Skip to content

Commit a2553bb

Browse files
authored
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 😌
1 parent a1bdbad commit a2553bb

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

packages/next/build/webpack/plugins/pages-plugin.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ export default class PagesPlugin {
4141
routeName = `/${routeName.replace(/(^|\/)index$/, '')}`
4242

4343
const source = new ConcatSource(
44-
`__NEXT_REGISTER_PAGE('${routeName}', function() {\n`,
44+
`(window.__NEXT_P=window.__NEXT_P||[]).push(['${routeName}', function() {\n`,
4545
moduleSourcePostModule,
4646
'\nreturn { page: module.exports.default }',
47-
'});'
47+
'}]);'
4848
)
4949

5050
return source

packages/next/client/index.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,12 @@ envConfig.setConfig({
4848
const asPath = getURL()
4949

5050
const pageLoader = new PageLoader(buildId, prefix)
51-
window.__NEXT_LOADED_PAGES__.forEach(([r, f]) => {
52-
pageLoader.registerPage(r, f)
53-
})
54-
delete window.__NEXT_LOADED_PAGES__
55-
window.__NEXT_REGISTER_PAGE = pageLoader.registerPage.bind(pageLoader)
51+
const register = ([r, f]) => pageLoader.registerPage(r, f)
52+
if (window.__NEXT_P) {
53+
window.__NEXT_P.map(register)
54+
}
55+
window.__NEXT_P = []
56+
window.__NEXT_P.push = register
5657

5758
const headManager = new HeadManager()
5859
const appContainer = document.getElementById('__next')

packages/next/pages/_document.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ export class NextScript extends Component {
187187
static getInlineScriptSource (documentProps) {
188188
const { __NEXT_DATA__ } = documentProps
189189
const { page } = __NEXT_DATA__
190-
return `__NEXT_DATA__ = ${htmlescape(__NEXT_DATA__)};__NEXT_LOADED_PAGES__=[];__NEXT_REGISTER_PAGE=function(r,f){__NEXT_LOADED_PAGES__.push([r, f])};`
190+
return `__NEXT_DATA__ = ${htmlescape(__NEXT_DATA__)};`
191191
}
192192

193193
render () {

0 commit comments

Comments
 (0)