diff --git a/packages/runtime-core/src/component.ts b/packages/runtime-core/src/component.ts index 768a47d9b6c..8b45636b3db 100644 --- a/packages/runtime-core/src/component.ts +++ b/packages/runtime-core/src/component.ts @@ -840,9 +840,12 @@ export function finishComponentSetup( if (__FEATURE_OPTIONS_API__ && !(__COMPAT__ && skipOptions)) { setCurrentInstance(instance) pauseTracking() - applyOptions(instance) - resetTracking() - unsetCurrentInstance() + try { + applyOptions(instance) + resetTracking() + } finally { + unsetCurrentInstance() + } } // warn missing template/render diff --git a/packages/server-renderer/__tests__/render.spec.ts b/packages/server-renderer/__tests__/render.spec.ts index f18001a0ae4..65b16e0de96 100644 --- a/packages/server-renderer/__tests__/render.spec.ts +++ b/packages/server-renderer/__tests__/render.spec.ts @@ -794,6 +794,47 @@ function testRender(type: string, render: typeof renderToString) { } catch {} expect(getCurrentInstance()).toBe(prev) }) + + // #7733 + test('reset current instance after error in data', async () => { + const prev = getCurrentInstance() + expect(prev).toBe(null) + try { + await render( + createApp({ + data() { + throw new Error() + }, + template: `