You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In the nested callback, use againinject. It works again as expected
Back to the first callback. use a third time inject. It doesn't work anymore
A situation where one can encounter such issue is in a combination between vue-router guards and pinia stores:
// simplified code from where I've encountered the issuerouter.beforeEach(()=>{// this is the top runWithContext()conststore=useSomePiniaStore();// this is the nested runWithContextconstinjected=inject('some-global');// this doesn't work});
To simply reproduce it on any app (with vue > 3.3), run the following:
In my case, I can just move the call to inject to be the first line of the router guard, and this fixes the issue, but just because I can do it this way.
I think using a sort of stack like for the EffectScope would work, so replacing the current:
should work, at least it did fix my test case. Not sure how that would work with async, but runWithContext looks to only support synchronous calling, so that may be fine.
The text was updated successfully, but these errors were encountered:
Vue version
3.4.15
Link to minimal reproduction
https://stackblitz.com/edit/vue3-nested-runwithcontext?file=src%2Fmain.js
Steps to reproduce
app.runWithContext
inject
. It works as expectedapp.runWithContext
inject
. It works again as expectedinject
. It doesn't work anymoreA situation where one can encounter such issue is in a combination between
vue-router
guards andpinia
stores:To simply reproduce it on any app (with
vue > 3.3
), run the following:You'll see the following logs:

What is expected?
Calling
inject
or other API expecting a scope should be working for the whole duration of theapp.runWithContext()
.What is actually happening?
When the nested
app.runWithContext()
call finishes, thecurrentApp
variable is reset tonull
, rendering it empty for the rest of theapp.runWithContext
.System Info
Any additional comments?
In my case, I can just move the call to
inject
to be the first line of the router guard, and this fixes the issue, but just because I can do it this way.I think using a sort of stack like for the
EffectScope
would work, so replacing the current:With:
should work, at least it did fix my test case. Not sure how that would work with async, but
runWithContext
looks to only support synchronous calling, so that may be fine.The text was updated successfully, but these errors were encountered: