fix(runtime-core): support for nested calls to runWithContext (#10261)

close #10260
This commit is contained in:
yangxiuxiu 2024-02-07 13:33:44 +08:00 committed by GitHub
parent eb1b9116d7
commit 75e02b5099
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 9 additions and 1 deletions

View File

@ -123,6 +123,13 @@ describe('api: createApp', () => {
expect(app.runWithContext(() => inject('foo'))).toBe(1)
expect(
app.runWithContext(() => {
app.runWithContext(() => {})
return inject('foo')
}),
).toBe(1)
// ensure the context is restored
inject('foo')
expect('inject() can only be used inside setup').toHaveBeenWarned()

View File

@ -387,11 +387,12 @@ export function createAppAPI<HostElement>(
},
runWithContext(fn) {
const lastApp = currentApp
currentApp = app
try {
return fn()
} finally {
currentApp = null
currentApp = lastApp
}
},
})