Skip to content

Commit

Permalink
fix: allow webpack cache is ready only for initial chunks, fixes greg…
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed May 14, 2020
1 parent 7368f14 commit 919e9b4
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 2 deletions.
9 changes: 8 additions & 1 deletion src/createLoadable.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import React from 'react'
import { invariant } from './util'
import Context from './Context'
import {loadable_shared} from "./shared";

function resolveConstructor(ctor) {
if (typeof ctor === 'function') {
Expand Down Expand Up @@ -82,7 +83,13 @@ function createLoadable({ resolve = identity, render, onLoad }) {
// If module is already loaded, we use a synchronous loading
// Only perform this synchronous loading if the component has not
// been marked with no SSR, else we risk hydration mismatches
if (options.ssr !== false && ctor.isReady && ctor.isReady(props)) {
if (options.ssr !== false && (
// is ready - was loaded in this session
(ctor.isReady && ctor.isReady(props)) ||
// is ready - was loaded during SSR process
(ctor.chunkName && loadable_shared.initialChunks[ctor.chunkName(props)])
)
) {
this.loadSync()
}
}
Expand Down
4 changes: 3 additions & 1 deletion src/loadableReady.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
/* eslint-env browser */
import { warn } from './util'
import { getRequiredChunkKey } from './sharedInternals'
import {loadable_shared} from "./shared";

const BROWSER = typeof window !== 'undefined'

Expand All @@ -19,7 +20,8 @@ export default function loadableReady(
if (BROWSER) {
const dataElement = document.getElementById(getRequiredChunkKey(namespace))
if (dataElement) {
requiredChunks = JSON.parse(dataElement.textContent)
requiredChunks = JSON.parse(dataElement.textContent);
requiredChunks.forEach(chunk => loadable_shared.initialChunks[chunk] = true);
}
}

Expand Down
3 changes: 3 additions & 0 deletions src/shared.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const loadable_shared = {
initialChunks: {}
}

0 comments on commit 919e9b4

Please sign in to comment.