mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
display deprecation warning only when method was called (#462)
This commit is contained in:
parent
fe962b12de
commit
2a29bf6242
|
@ -31,5 +31,5 @@ const headManager = new HeadManager()
|
|||
const container = document.getElementById('__next')
|
||||
const appProps = { Component, props, router, headManager }
|
||||
|
||||
if (ids) rehydrate(ids)
|
||||
if (ids && ids.length) rehydrate(ids)
|
||||
render(createElement(App, appProps), container)
|
||||
|
|
|
@ -1,7 +1,11 @@
|
|||
import { warn } from './utils'
|
||||
import { deprecated } from './utils'
|
||||
const css = require('glamor')
|
||||
|
||||
warn('Warning: \'next/css\' is deprecated. Please use styled-jsx syntax instead.')
|
||||
for (const [k, v] of Object.entries(css)) {
|
||||
if (typeof v === 'function') {
|
||||
css[k] = deprecated(v, 'Warning: \'next/css\' is deprecated. Please use styled-jsx syntax instead.')
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose style as default and the whole object as properties
|
||||
|
|
18
lib/utils.js
18
lib/utils.js
|
@ -3,3 +3,21 @@ export function warn (message) {
|
|||
console.error(message)
|
||||
}
|
||||
}
|
||||
|
||||
export function deprecated (fn, message) {
|
||||
if (process.env.NODE_ENV === 'production') return fn
|
||||
|
||||
let warned = false
|
||||
const newFn = function (...args) {
|
||||
if (!warned) {
|
||||
warned = true
|
||||
console.error(message)
|
||||
}
|
||||
return fn.apply(this, args)
|
||||
}
|
||||
|
||||
// copy all properties
|
||||
Object.assign(newFn, fn)
|
||||
|
||||
return newFn
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue