]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
fix(runtime-core): support for nested calls to runWithContext (#10261)
authoryangxiuxiu <79584569+yangxiuxiu1115@users.noreply.github.com>
Wed, 7 Feb 2024 05:33:44 +0000 (13:33 +0800)
committerGitHub <noreply@github.com>
Wed, 7 Feb 2024 05:33:44 +0000 (13:33 +0800)
close #10260

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

index f8dcd6aee2cecf720f82c568637ef6a97c0eccb4..05e51e43bb6b735f514b4276d15d8e6c98f9277f 100644 (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()
index b99d06e01ff5465b311869ae53e6db74345df6e1..c476cdbe701df08c3a4060564305ea74846440e1 100644 (file)
@@ -387,11 +387,12 @@ export function createAppAPI<HostElement>(
       },
 
       runWithContext(fn) {
+        const lastApp = currentApp
         currentApp = app
         try {
           return fn()
         } finally {
-          currentApp = null
+          currentApp = lastApp
         }
       },
     })