diff --git a/packages/component/.size-snapshot.json b/packages/component/.size-snapshot.json index 2f50e41a..920f303e 100644 --- a/packages/component/.size-snapshot.json +++ b/packages/component/.size-snapshot.json @@ -1,20 +1,20 @@ { "dist/cjs/loadable.cjs.js": { - "bundled": 16900, - "minified": 7226, - "gzipped": 2553 + "bundled": 17192, + "minified": 7413, + "gzipped": 2600 }, "dist/esm/loadable.esm.mjs": { - "bundled": 16517, - "minified": 6917, - "gzipped": 2490, + "bundled": 16809, + "minified": 7104, + "gzipped": 2537, "treeshaked": { "rollup": { "code": 259, "import_statements": 259 }, "webpack": { - "code": 5764 + "code": 5902 } } } diff --git a/packages/component/src/createLoadable.js b/packages/component/src/createLoadable.js index 5a3da831..f51d2ae0 100644 --- a/packages/component/src/createLoadable.js +++ b/packages/component/src/createLoadable.js @@ -3,7 +3,7 @@ import React from 'react' import hoistNonReactStatics from 'hoist-non-react-statics' import { invariant } from './util' import Context from './Context' -import { LOADABLE_SHARED } from './shared' +import { getInitialChunks } from './shared' const STATUS_PENDING = 'PENDING' const STATUS_RESOLVED = 'RESOLVED' @@ -173,7 +173,7 @@ function createLoadable({ ((ctor.isReady && ctor.isReady(props)) || // is ready - was loaded during SSR process (ctor.chunkName && - LOADABLE_SHARED.initialChunks[ctor.chunkName(props)])) + getInitialChunks()[ctor.chunkName(props)])) ) { this.loadSync() } diff --git a/packages/component/src/loadableReady.js b/packages/component/src/loadableReady.js index 11e8dedf..d4cd0d9e 100644 --- a/packages/component/src/loadableReady.js +++ b/packages/component/src/loadableReady.js @@ -2,9 +2,7 @@ /* eslint-env browser */ import { warn } from './util' import { getRequiredChunkKey } from './sharedInternals' -import { LOADABLE_SHARED } from './shared' - -const BROWSER = typeof window !== 'undefined' +import { BROWSER, getInitialChunks } from './shared' export default function loadableReady( done = () => {}, @@ -26,8 +24,9 @@ export default function loadableReady( const extElement = document.getElementById(`${id}_ext`) if (extElement) { const { namedChunks } = JSON.parse(extElement.textContent) + const initialChunks = getInitialChunks() namedChunks.forEach(chunkName => { - LOADABLE_SHARED.initialChunks[chunkName] = true + initialChunks[chunkName] = true }) } else { // version mismatch diff --git a/packages/component/src/shared.js b/packages/component/src/shared.js index 0aeda340..3d5dbb63 100644 --- a/packages/component/src/shared.js +++ b/packages/component/src/shared.js @@ -1,3 +1,16 @@ -export const LOADABLE_SHARED = { - initialChunks: {}, +/* eslint-env browser */ +const INITIAL_CHUNKS_KEY = '__LOADABLE_INITIAL_CHUNKS__' + +const SERVER_INITIAL_CHUNKS = {} + +export const BROWSER = typeof window !== 'undefined' + +export function getInitialChunks() { + if (!BROWSER) { + return SERVER_INITIAL_CHUNKS + } + if (!window[INITIAL_CHUNKS_KEY]) { + window[INITIAL_CHUNKS_KEY] = {} + } + return window[INITIAL_CHUNKS_KEY] }