mirror of
https://github.com/terribleplan/next.js.git
synced 2024-01-19 02:48:18 +00:00
Remove registration code from initial markup (#5583)
Clears the way a bit for #4943, also makes _document.js less complex, and will allow us to move `__NEXT_DATA__` to a `application/json` script tag. Also this causes a slightly smaller bundle size 😌
This commit is contained in:
parent
a1bdbad2cf
commit
a2553bb46e
|
@ -41,10 +41,10 @@ export default class PagesPlugin {
|
||||||
routeName = `/${routeName.replace(/(^|\/)index$/, '')}`
|
routeName = `/${routeName.replace(/(^|\/)index$/, '')}`
|
||||||
|
|
||||||
const source = new ConcatSource(
|
const source = new ConcatSource(
|
||||||
`__NEXT_REGISTER_PAGE('${routeName}', function() {\n`,
|
`(window.__NEXT_P=window.__NEXT_P||[]).push(['${routeName}', function() {\n`,
|
||||||
moduleSourcePostModule,
|
moduleSourcePostModule,
|
||||||
'\nreturn { page: module.exports.default }',
|
'\nreturn { page: module.exports.default }',
|
||||||
'});'
|
'}]);'
|
||||||
)
|
)
|
||||||
|
|
||||||
return source
|
return source
|
||||||
|
|
|
@ -48,11 +48,12 @@ envConfig.setConfig({
|
||||||
const asPath = getURL()
|
const asPath = getURL()
|
||||||
|
|
||||||
const pageLoader = new PageLoader(buildId, prefix)
|
const pageLoader = new PageLoader(buildId, prefix)
|
||||||
window.__NEXT_LOADED_PAGES__.forEach(([r, f]) => {
|
const register = ([r, f]) => pageLoader.registerPage(r, f)
|
||||||
pageLoader.registerPage(r, f)
|
if (window.__NEXT_P) {
|
||||||
})
|
window.__NEXT_P.map(register)
|
||||||
delete window.__NEXT_LOADED_PAGES__
|
}
|
||||||
window.__NEXT_REGISTER_PAGE = pageLoader.registerPage.bind(pageLoader)
|
window.__NEXT_P = []
|
||||||
|
window.__NEXT_P.push = register
|
||||||
|
|
||||||
const headManager = new HeadManager()
|
const headManager = new HeadManager()
|
||||||
const appContainer = document.getElementById('__next')
|
const appContainer = document.getElementById('__next')
|
||||||
|
|
|
@ -187,7 +187,7 @@ export class NextScript extends Component {
|
||||||
static getInlineScriptSource (documentProps) {
|
static getInlineScriptSource (documentProps) {
|
||||||
const { __NEXT_DATA__ } = documentProps
|
const { __NEXT_DATA__ } = documentProps
|
||||||
const { page } = __NEXT_DATA__
|
const { page } = __NEXT_DATA__
|
||||||
return `__NEXT_DATA__ = ${htmlescape(__NEXT_DATA__)};__NEXT_LOADED_PAGES__=[];__NEXT_REGISTER_PAGE=function(r,f){__NEXT_LOADED_PAGES__.push([r, f])};`
|
return `__NEXT_DATA__ = ${htmlescape(__NEXT_DATA__)};`
|
||||||
}
|
}
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
|
|
Loading…
Reference in a new issue