Skip to content

Commit

Permalink
async components: timeout should not trigger if already resolved (fix #…
Browse files Browse the repository at this point in the history
  • Loading branch information
yyx990803 committed May 9, 2017
1 parent 3139605 commit 8d54aec
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
12 changes: 7 additions & 5 deletions src/core/vdom/helpers/resolve-async-component.js
Expand Up @@ -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)
}
}
Expand Down
23 changes: 23 additions & 0 deletions test/unit/features/component/component-async.spec.js
Expand Up @@ -292,5 +292,28 @@ describe('Component async', () => {
done()
}
})

it('should not trigger timeout if resolved', done => {
const vm = new Vue({
template: `<div><test/></div>`,
components: {
test: () => ({
component: new Promise((resolve, reject) => {
setTimeout(() => {
resolve({ template: '<div>hi</div>' })
}, 10)
}),
error: { template: `<div>error</div>` },
timeout: 20
})
}
}).$mount()

setTimeout(() => {
expect(vm.$el.textContent).toBe('hi')
expect(`Failed to resolve async component`).not.toHaveBeenWarned()
done()
}, 30)
})
})
})

0 comments on commit 8d54aec

Please sign in to comment.