Skip to content

Commit

Permalink
fix: allow webpack cache is ready only for initial chunks, fixes #558
Browse files Browse the repository at this point in the history
  • Loading branch information
theKashey committed May 14, 2020
1 parent 5a9c33b commit 61f8b75
Show file tree
Hide file tree
Showing 6 changed files with 40 additions and 21 deletions.
36 changes: 18 additions & 18 deletions packages/babel-plugin/src/__snapshots__/index.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ exports[`plugin Magic comment should remove only needed comments 1`] = `
isReady(props) {
const key = this.resolve(props);
if (this.resolved[key] === false) {
if (this.resolved[key] !== true) {
return false;
}
Expand Down Expand Up @@ -69,7 +69,7 @@ exports[`plugin Magic comment should transpile arrow functions 1`] = `
isReady(props) {
const key = this.resolve(props);
if (this.resolved[key] === false) {
if (this.resolved[key] !== true) {
return false;
}
Expand Down Expand Up @@ -125,7 +125,7 @@ exports[`plugin Magic comment should transpile function expression 1`] = `
isReady(props) {
const key = this.resolve(props);
if (this.resolved[key] === false) {
if (this.resolved[key] !== true) {
return false;
}
Expand Down Expand Up @@ -184,7 +184,7 @@ exports[`plugin Magic comment should transpile shortand properties 1`] = `
isReady(props) {
const key = this.resolve(props);
if (this.resolved[key] === false) {
if (this.resolved[key] !== true) {
return false;
}
Expand Down Expand Up @@ -245,7 +245,7 @@ exports[`plugin aggressive import should work with destructuration 1`] = `
isReady(props) {
const key = this.resolve(props);
if (this.resolved[key] === false) {
if (this.resolved[key] !== true) {
return false;
}
Expand Down Expand Up @@ -305,7 +305,7 @@ exports[`plugin aggressive import with "webpackChunkName" should replace it 1`]
isReady(props) {
const key = this.resolve(props);
if (this.resolved[key] === false) {
if (this.resolved[key] !== true) {
return false;
}
Expand Down Expand Up @@ -361,7 +361,7 @@ exports[`plugin aggressive import without "webpackChunkName" should support comp
isReady(props) {
const key = this.resolve(props);
if (this.resolved[key] === false) {
if (this.resolved[key] !== true) {
return false;
}
Expand Down Expand Up @@ -419,7 +419,7 @@ exports[`plugin aggressive import without "webpackChunkName" should support dest
isReady(props) {
const key = this.resolve(props);
if (this.resolved[key] === false) {
if (this.resolved[key] !== true) {
return false;
}
Expand Down Expand Up @@ -479,7 +479,7 @@ exports[`plugin aggressive import without "webpackChunkName" should support simp
isReady(props) {
const key = this.resolve(props);
if (this.resolved[key] === false) {
if (this.resolved[key] !== true) {
return false;
}
Expand Down Expand Up @@ -535,7 +535,7 @@ exports[`plugin loadable.lib should be transpiled too 1`] = `
isReady(props) {
const key = this.resolve(props);
if (this.resolved[key] === false) {
if (this.resolved[key] !== true) {
return false;
}
Expand Down Expand Up @@ -591,7 +591,7 @@ exports[`plugin simple import in a complex promise should work 1`] = `
isReady(props) {
const key = this.resolve(props);
if (this.resolved[key] === false) {
if (this.resolved[key] !== true) {
return false;
}
Expand Down Expand Up @@ -647,7 +647,7 @@ exports[`plugin simple import should transform path into "chunk-friendly" name 1
isReady(props) {
const key = this.resolve(props);
if (this.resolved[key] === false) {
if (this.resolved[key] !== true) {
return false;
}
Expand Down Expand Up @@ -703,7 +703,7 @@ exports[`plugin simple import should work with * in name 1`] = `
isReady(props) {
const key = this.resolve(props);
if (this.resolved[key] === false) {
if (this.resolved[key] !== true) {
return false;
}
Expand Down Expand Up @@ -759,7 +759,7 @@ exports[`plugin simple import should work with + concatenation 1`] = `
isReady(props) {
const key = this.resolve(props);
if (this.resolved[key] === false) {
if (this.resolved[key] !== true) {
return false;
}
Expand Down Expand Up @@ -815,7 +815,7 @@ exports[`plugin simple import should work with template literal 1`] = `
isReady(props) {
const key = this.resolve(props);
if (this.resolved[key] === false) {
if (this.resolved[key] !== true) {
return false;
}
Expand Down Expand Up @@ -871,7 +871,7 @@ exports[`plugin simple import with "webpackChunkName" comment should use it 1`]
isReady(props) {
const key = this.resolve(props);
if (this.resolved[key] === false) {
if (this.resolved[key] !== true) {
return false;
}
Expand Down Expand Up @@ -927,7 +927,7 @@ exports[`plugin simple import with "webpackChunkName" comment should use it even
isReady(props) {
const key = this.resolve(props);
if (this.resolved[key] === false) {
if (this.resolved[key] !== true) {
return false;
}
Expand Down Expand Up @@ -983,7 +983,7 @@ exports[`plugin simple import without "webpackChunkName" comment should add it 1
isReady(props) {
const key = this.resolve(props);
if (this.resolved[key] === false) {
if (this.resolved[key] !== true) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion packages/babel-plugin/src/properties/isReady.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default function isReadyProperty({ types: t, template }) {
const statements = template.ast(`
const key=this.resolve(props)
if (this.resolved[key] === false) {
if (this.resolved[key] !== true) {
return false
}
Expand Down
9 changes: 8 additions & 1 deletion packages/component/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 packages/component/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 packages/component/src/shared.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export const loadable_shared = {
initialChunks: {}
}
7 changes: 7 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6531,6 +6531,13 @@ make-dir@^2.0.0, make-dir@^2.1.0:
pify "^4.0.1"
semver "^5.6.0"

make-dir@^3.0.2:
version "3.1.0"
resolved "https://registry.yarnpkg.com/make-dir/-/make-dir-3.1.0.tgz#415e967046b3a7f1d185277d84aa58203726a13f"
integrity sha512-g3FeP20LNwhALb/6Cz6Dd4F2ngze0jz7tbzrD2wAV+o9FeNHe4rL+yK2md0J/fiSf1sa1ADhXqi5+oVwOM/eGw==
dependencies:
semver "^6.0.0"

make-fetch-happen@^5.0.0:
version "5.0.2"
resolved "https://registry.yarnpkg.com/make-fetch-happen/-/make-fetch-happen-5.0.2.tgz#aa8387104f2687edca01c8687ee45013d02d19bd"
Expand Down

0 comments on commit 61f8b75

Please sign in to comment.