Skip to content

Commit 8d54aec

Browse files
committed
async components: timeout should not trigger if already resolved (fix vuejs#5635)
1 parent 3139605 commit 8d54aec

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed

src/core/vdom/helpers/resolve-async-component.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -97,11 +97,13 @@ export function resolveAsyncComponent (
9797

9898
if (isDef(res.timeout)) {
9999
setTimeout(() => {
100-
reject(
101-
process.env.NODE_ENV !== 'production'
102-
? `timeout (${res.timeout}ms)`
103-
: null
104-
)
100+
if (isUndef(factory.resolved)) {
101+
reject(
102+
process.env.NODE_ENV !== 'production'
103+
? `timeout (${res.timeout}ms)`
104+
: null
105+
)
106+
}
105107
}, res.timeout)
106108
}
107109
}

test/unit/features/component/component-async.spec.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -292,5 +292,28 @@ describe('Component async', () => {
292292
done()
293293
}
294294
})
295+
296+
it('should not trigger timeout if resolved', done => {
297+
const vm = new Vue({
298+
template: `<div><test/></div>`,
299+
components: {
300+
test: () => ({
301+
component: new Promise((resolve, reject) => {
302+
setTimeout(() => {
303+
resolve({ template: '<div>hi</div>' })
304+
}, 10)
305+
}),
306+
error: { template: `<div>error</div>` },
307+
timeout: 20
308+
})
309+
}
310+
}).$mount()
311+
312+
setTimeout(() => {
313+
expect(vm.$el.textContent).toBe('hi')
314+
expect(`Failed to resolve async component`).not.toHaveBeenWarned()
315+
done()
316+
}, 30)
317+
})
295318
})
296319
})

0 commit comments

Comments
 (0)