Commit 2a29bf62 authored by Naoyuki Kanezawa's avatar Naoyuki Kanezawa Committed by Guillermo Rauch

display deprecation warning only when method was called (#462)

parent fe962b12
......@@ -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)
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
......
......@@ -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
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment