From bf457f892c5ee417c97cd435d6f02db12c0cb713 Mon Sep 17 00:00:00 2001 From: Light Leung Date: Mon, 22 Apr 2019 11:17:26 +0800 Subject: [PATCH 1/3] Remove checking "resolving" in needToResolveOnBrowser The resolving condition will cause a bug when the component is resolving, then the current component is unmounted and then the component is recreated again right before the module is resolved. In this case, the component should get the existing resolver and update the rendering after the module is resolved. However, the resolving checking blocks this update. --- src/asyncComponent.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/asyncComponent.js b/src/asyncComponent.js index 4859240..f992164 100644 --- a/src/asyncComponent.js +++ b/src/asyncComponent.js @@ -44,7 +44,6 @@ export default function asyncComponent(config) { const needToResolveOnBrowser = () => state.module == null && state.error == null && - !state.resolving && typeof window !== 'undefined' // Takes the given module and if it has a ".default" the ".default" will From 03c394eff90ce544f794c4cdd53d008aa3a064ba Mon Sep 17 00:00:00 2001 From: Light Leung Date: Mon, 22 Apr 2019 14:15:06 +0800 Subject: [PATCH 2/3] add test for bug fix --- src/__tests__/integration.test.js | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/__tests__/integration.test.js b/src/__tests__/integration.test.js index 97de90b..f4f7b8e 100644 --- a/src/__tests__/integration.test.js +++ b/src/__tests__/integration.test.js @@ -193,6 +193,28 @@ describe('integration tests', () => { const wrapper = mount(app) expect(wrapper.html()).toContain('Loading...') }) + + it('renders the LoadingComponent without bootstrapper', async () => { + const AsyncComponent = asyncComponent({ + resolve: () => + new Promise(resolve => + setTimeout(() => resolve(() =>
foo
), 100), + ), + LoadingComponent, + }) + const Comp = ({ compKey }) => ( +
{compKey ? : null}
+ ) + const wrapper = mount() + expect(wrapper.html()).toContain('Loading...') + // Unmount the component immediately + wrapper.setProps({ + compKey: '2', + }) + expect(wrapper.html()).toContain('Loading...') + await new Promise(resolve => setTimeout(resolve, 100)) + expect(wrapper.html()).not.toContain('Loading...') + }) }) describe('server rendering', () => { From e3b4d69ffd7f518c634daea401644ccedc7deff6 Mon Sep 17 00:00:00 2001 From: Light Leung Date: Mon, 22 Apr 2019 14:42:15 +0800 Subject: [PATCH 3/3] CI fix --- src/__tests__/integration.test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/__tests__/integration.test.js b/src/__tests__/integration.test.js index f4f7b8e..4c6e7eb 100644 --- a/src/__tests__/integration.test.js +++ b/src/__tests__/integration.test.js @@ -212,7 +212,7 @@ describe('integration tests', () => { compKey: '2', }) expect(wrapper.html()).toContain('Loading...') - await new Promise(resolve => setTimeout(resolve, 100)) + await new Promise(resolve => setTimeout(resolve, 150)) expect(wrapper.html()).not.toContain('Loading...') }) })