diff --git a/packages/next/build/webpack/plugins/pages-plugin.js b/packages/next/build/webpack/plugins/pages-plugin.js index 6e7f55c1..19d73e3d 100644 --- a/packages/next/build/webpack/plugins/pages-plugin.js +++ b/packages/next/build/webpack/plugins/pages-plugin.js @@ -41,10 +41,10 @@ export default class PagesPlugin { routeName = `/${routeName.replace(/(^|\/)index$/, '')}` const source = new ConcatSource( - `__NEXT_REGISTER_PAGE('${routeName}', function() {\n`, + `(window.__NEXT_P=window.__NEXT_P||[]).push(['${routeName}', function() {\n`, moduleSourcePostModule, '\nreturn { page: module.exports.default }', - '});' + '}]);' ) return source diff --git a/packages/next/client/index.js b/packages/next/client/index.js index 1fcc0799..84d6b368 100644 --- a/packages/next/client/index.js +++ b/packages/next/client/index.js @@ -48,11 +48,12 @@ envConfig.setConfig({ const asPath = getURL() const pageLoader = new PageLoader(buildId, prefix) -window.__NEXT_LOADED_PAGES__.forEach(([r, f]) => { - pageLoader.registerPage(r, f) -}) -delete window.__NEXT_LOADED_PAGES__ -window.__NEXT_REGISTER_PAGE = pageLoader.registerPage.bind(pageLoader) +const register = ([r, f]) => pageLoader.registerPage(r, f) +if (window.__NEXT_P) { + window.__NEXT_P.map(register) +} +window.__NEXT_P = [] +window.__NEXT_P.push = register const headManager = new HeadManager() const appContainer = document.getElementById('__next') diff --git a/packages/next/pages/_document.js b/packages/next/pages/_document.js index ed9ba8b1..ab295317 100644 --- a/packages/next/pages/_document.js +++ b/packages/next/pages/_document.js @@ -187,7 +187,7 @@ export class NextScript extends Component { static getInlineScriptSource (documentProps) { const { __NEXT_DATA__ } = documentProps 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 () {