1
0
Fork 0
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:
Tim Neutkens 2018-11-03 01:59:54 +01:00 committed by GitHub
parent a1bdbad2cf
commit a2553bb46e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 9 additions and 8 deletions

View file

@ -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

View file

@ -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')

View file

@ -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 () {