From 8d54aecdd04202d39659a7625eef846673064ab3 Mon Sep 17 00:00:00 2001 From: Evan You Date: Tue, 9 May 2017 23:35:09 +0800 Subject: [PATCH] async components: timeout should not trigger if already resolved (fix #5635) --- .../vdom/helpers/resolve-async-component.js | 12 ++++++---- .../component/component-async.spec.js | 23 +++++++++++++++++++ 2 files changed, 30 insertions(+), 5 deletions(-) diff --git a/src/core/vdom/helpers/resolve-async-component.js b/src/core/vdom/helpers/resolve-async-component.js index a06f4522923..e1b90fb0fe2 100644 --- a/src/core/vdom/helpers/resolve-async-component.js +++ b/src/core/vdom/helpers/resolve-async-component.js @@ -97,11 +97,13 @@ export function resolveAsyncComponent ( if (isDef(res.timeout)) { setTimeout(() => { - reject( - process.env.NODE_ENV !== 'production' - ? `timeout (${res.timeout}ms)` - : null - ) + if (isUndef(factory.resolved)) { + reject( + process.env.NODE_ENV !== 'production' + ? `timeout (${res.timeout}ms)` + : null + ) + } }, res.timeout) } } diff --git a/test/unit/features/component/component-async.spec.js b/test/unit/features/component/component-async.spec.js index 76ab05f5e6c..75b2a88938a 100644 --- a/test/unit/features/component/component-async.spec.js +++ b/test/unit/features/component/component-async.spec.js @@ -292,5 +292,28 @@ describe('Component async', () => { done() } }) + + it('should not trigger timeout if resolved', done => { + const vm = new Vue({ + template: `
`, + components: { + test: () => ({ + component: new Promise((resolve, reject) => { + setTimeout(() => { + resolve({ template: '
hi
' }) + }, 10) + }), + error: { template: `
error
` }, + timeout: 20 + }) + } + }).$mount() + + setTimeout(() => { + expect(vm.$el.textContent).toBe('hi') + expect(`Failed to resolve async component`).not.toHaveBeenWarned() + done() + }, 30) + }) }) })