Skip to content

Commit 75e02b5

Browse files
authoredFeb 7, 2024··
fix(runtime-core): support for nested calls to runWithContext (#10261)
close #10260
1 parent eb1b911 commit 75e02b5

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed
 

‎packages/runtime-core/__tests__/apiCreateApp.spec.ts

+7
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,13 @@ describe('api: createApp', () => {
123123

124124
expect(app.runWithContext(() => inject('foo'))).toBe(1)
125125

126+
expect(
127+
app.runWithContext(() => {
128+
app.runWithContext(() => {})
129+
return inject('foo')
130+
}),
131+
).toBe(1)
132+
126133
// ensure the context is restored
127134
inject('foo')
128135
expect('inject() can only be used inside setup').toHaveBeenWarned()

‎packages/runtime-core/src/apiCreateApp.ts

+2-1
Original file line numberDiff line numberDiff line change
@@ -387,11 +387,12 @@ export function createAppAPI<HostElement>(
387387
},
388388

389389
runWithContext(fn) {
390+
const lastApp = currentApp
390391
currentApp = app
391392
try {
392393
return fn()
393394
} finally {
394-
currentApp = null
395+
currentApp = lastApp
395396
}
396397
},
397398
})

0 commit comments

Comments
 (0)
Please sign in to comment.