fix(shared): support provideLocal/injectLocal in vapor mode#5050
Merged
antfu merged 1 commit intovueuse:mainfrom Sep 20, 2025
Merged
fix(shared): support provideLocal/injectLocal in vapor mode#5050antfu merged 1 commit intovueuse:mainfrom
antfu merged 1 commit intovueuse:mainfrom
Conversation
- fall back to current effect scope when component instance is missing - share the same owner lookup between provideLocal and injectLocal - allow localProvidedStateMap to key off either component proxies or scopes scopesCloses vueuse#4875 Signed-off-by: Zhaokun Zhang <[email protected]>
antfu
approved these changes
Sep 20, 2025
@vueuse/components
@vueuse/core
@vueuse/electron
@vueuse/firebase
@vueuse/integrations
@vueuse/math
@vueuse/metadata
@vueuse/nuxt
@vueuse/router
@vueuse/rxjs
@vueuse/shared
commit: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
provideLocalandinjectLocal| In Vue's vapor mode,getCurrentInstancereturnsnull#4875Before submitting the PR, please make sure you do the following
fixes #123).Description
Additional context
Description
This PR addresses the compatibility issue with Vue's Vapor mode where
getCurrentInstance()returnsnull, causingprovideLocalandinjectLocalto fail. The key changes are:getCurrentScope()when component instance is unavailable, ensuring proper context resolution in Vapor modeprovideLocalandinjectLocalfor consistencylocalProvidedStateMapto support both component proxies and effect scopes as keysThese changes maintain backward compatibility with traditional Vue components while adding support for Vapor mode, where component instances may not be available but effect scopes still provide valid context.
Additional context
The primary focus of this PR is to maintain the functionality of local injection APIs in environments where component instances aren't available, specifically Vue's new Vapor rendering mode. By using effect scopes as a fallback, we ensure the local provide/inject pattern works consistently across both rendering modes.
Testing should verify:
This fix closes #4875 by addressing the root cause of the instance check failure in Vapor mode.