Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(runtime-core): return hook() in wrappedHook to handle the async call in KeepAliveHook. #4978

Merged
merged 3 commits into from Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 30 additions & 1 deletion packages/runtime-core/__tests__/components/KeepAlive.spec.ts
Expand Up @@ -16,7 +16,9 @@ import {
cloneVNode,
provide,
defineAsyncComponent,
Component
Component,
createApp,
onActivated
} from '@vue/runtime-test'
import { KeepAliveProps } from '../../src/components/KeepAlive'

Expand Down Expand Up @@ -874,4 +876,31 @@ describe('KeepAlive', () => {
await nextTick()
expect(serializeInner(root)).toBe('<p>1</p>')
})

// #4976
test('handle error in async onActivated', async () => {
const err = new Error('foo')
const handler = jest.fn()

const app = createApp({
setup() {
return () => h(KeepAlive, null, () => h(Child))
}
})

const Child = {
setup() {
onActivated(async () => {
throw err
})
},
render() {}
}

app.config.errorHandler = handler
app.mount(nodeOps.createElement('div'))

await nextTick()
expect(handler).toHaveBeenCalledWith(err, {}, 'activated hook')
})
})
2 changes: 1 addition & 1 deletion packages/runtime-core/src/components/KeepAlive.ts
Expand Up @@ -381,7 +381,7 @@ function registerKeepAliveHook(
}
current = current.parent
}
hook()
return hook()
})
injectHook(type, wrappedHook, target)
// In addition to registering it on the target instance, we walk up the parent
Expand Down