Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: vue 2 support for provideLocal and injectLocal #3464

Merged
merged 1 commit into from Oct 7, 2023

Conversation

xiaoxiangmoe
Copy link
Contributor

@xiaoxiangmoe xiaoxiangmoe commented Oct 7, 2023

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

Description

fix vue 2.7 support for provideLocal and injectLocal

See
https://github.com/vuejs/vue/blob/49b6bd4264c25ea41408f066a1835f38bf6fe9f1/src/v3/currentInstance.ts#L5-L14

Every time call getCurrentInstance in vue 2.7 will create a new Object锛宻o we should use getCurrentInstance()?.proxy other than getCurrentInstance() as WeakMap key.

Additional context


馃 Generated by Copilot at 9bfc23c

This pull request fixes bugs and adds tests for the provideLocal and injectLocal functions, which enable local state management across components. It uses the proxy property of the component instance to access and set the local state in the localProvidedStateMap weak map.

馃 Generated by Copilot at 9bfc23c

  • Fix bugs in provideLocal and injectLocal functions that use the wrong instance object to access and set the local state (link, link)
  • Update the type of the localProvidedStateMap variable to use the proxy property of the instance as the key (link)
  • Add test cases for provideLocal and injectLocal functions using vitest and vue-demi (link)

@xiaoxiangmoe xiaoxiangmoe marked this pull request as draft October 7, 2023 10:34
@antfu antfu merged commit cf75702 into vueuse:main Oct 7, 2023
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants