Skip to content

Commit 2a29bf6

Browse files
nkzawarauchg
authored andcommitted
display deprecation warning only when method was called (#462)
1 parent fe962b1 commit 2a29bf6

File tree

3 files changed

+25
-3
lines changed

3 files changed

+25
-3
lines changed

client/next.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,5 +31,5 @@ const headManager = new HeadManager()
3131
const container = document.getElementById('__next')
3232
const appProps = { Component, props, router, headManager }
3333

34-
if (ids) rehydrate(ids)
34+
if (ids && ids.length) rehydrate(ids)
3535
render(createElement(App, appProps), container)

lib/css.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,11 @@
1-
import { warn } from './utils'
1+
import { deprecated } from './utils'
22
const css = require('glamor')
33

4-
warn('Warning: \'next/css\' is deprecated. Please use styled-jsx syntax instead.')
4+
for (const [k, v] of Object.entries(css)) {
5+
if (typeof v === 'function') {
6+
css[k] = deprecated(v, 'Warning: \'next/css\' is deprecated. Please use styled-jsx syntax instead.')
7+
}
8+
}
59

610
/**
711
* Expose style as default and the whole object as properties

lib/utils.js

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,21 @@ export function warn (message) {
33
console.error(message)
44
}
55
}
6+
7+
export function deprecated (fn, message) {
8+
if (process.env.NODE_ENV === 'production') return fn
9+
10+
let warned = false
11+
const newFn = function (...args) {
12+
if (!warned) {
13+
warned = true
14+
console.error(message)
15+
}
16+
return fn.apply(this, args)
17+
}
18+
19+
// copy all properties
20+
Object.assign(newFn, fn)
21+
22+
return newFn
23+
}

0 commit comments

Comments
 (0)