fix(runtime-core): handle error in async KeepAlive hooks (#4978)
This commit is contained in:
parent
61720231b4
commit
820a143457
@ -16,7 +16,9 @@ import {
|
|||||||
cloneVNode,
|
cloneVNode,
|
||||||
provide,
|
provide,
|
||||||
defineAsyncComponent,
|
defineAsyncComponent,
|
||||||
Component
|
Component,
|
||||||
|
createApp,
|
||||||
|
onActivated
|
||||||
} from '@vue/runtime-test'
|
} from '@vue/runtime-test'
|
||||||
import { KeepAliveProps } from '../../src/components/KeepAlive'
|
import { KeepAliveProps } from '../../src/components/KeepAlive'
|
||||||
|
|
||||||
@ -874,4 +876,31 @@ describe('KeepAlive', () => {
|
|||||||
await nextTick()
|
await nextTick()
|
||||||
expect(serializeInner(root)).toBe('<p>1</p>')
|
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')
|
||||||
|
})
|
||||||
})
|
})
|
||||||
|
@ -381,7 +381,7 @@ function registerKeepAliveHook(
|
|||||||
}
|
}
|
||||||
current = current.parent
|
current = current.parent
|
||||||
}
|
}
|
||||||
hook()
|
return hook()
|
||||||
})
|
})
|
||||||
injectHook(type, wrappedHook, target)
|
injectHook(type, wrappedHook, target)
|
||||||
// In addition to registering it on the target instance, we walk up the parent
|
// In addition to registering it on the target instance, we walk up the parent
|
||||||
|
Loading…
x
Reference in New Issue
Block a user