Skip to content

Commit ebdad9f

Browse files
yangxiuxiu1115lynxlangya
authored andcommitted
fix(runtime-core): support for nested calls to runWithContext (vuejs#10261)
close vuejs#10260
1 parent 5f4d413 commit ebdad9f

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)