Skip to content

fix(useStorage): when used inside effectScope, should not remove listener on component unmount (#4695) #4717

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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

FishHawk
Copy link

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.
⚠️ Slowing down new functions

Warning: Slowing down new functions

As the VueUse audience continues to grow, we have been inundated with an overwhelming number of feature requests and pull requests. As a result, maintaining the project has become increasingly challenging and has stretched our capacity to its limits. As such, in the near future, we may need to slow down our acceptance of new features and prioritize the stability and quality of existing functions. Please note that new features for VueUse may not be accepted at this time. If you have any new ideas, we suggest that you first incorporate them into your own codebase, iterate on them to suit your needs, and assess their generalizability. If you strongly believe that your ideas are beneficial to the community, you may submit a pull request along with your use cases, and we would be happy to review and discuss them. Thank you for your understanding.


Description

When used in effectScope, useStorage should continue to listen on storage even after the module is unmounted. tryOnMounted should only be called when initOnMounted is set.

Fix #4695

@dosubot dosubot bot added the size:S This PR changes 10-29 lines, ignoring generated files. label Apr 20, 2025
43081j
43081j previously approved these changes Apr 21, 2025
Copy link
Collaborator

@43081j 43081j left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me. we have a few solutions floating around for this particular problem, so ill wait until @OrbisK or someone can review too

@dosubot dosubot bot added the lgtm This PR has been approved by a maintainer label Apr 21, 2025
@OrbisK
Copy link
Collaborator

OrbisK commented Apr 22, 2025

we have a few solutions floating around for this particular problem

This is a bit tricky. I think our (Anthony's) initial expectation is that lifecycle hooks should work with effect scope by default (and dont change the context). There are some issues with that. I think we should open a discussion in vue now to get this straightened out.

@FishHawk
Copy link
Author

Hope this fix can be merged soon. I’m concerned about spending too much time discussing it, as my site has been struggling with the issue for six months.😂

@OrbisK
Copy link
Collaborator

OrbisK commented Apr 22, 2025

Yeah, I think we can merge this an revistit it after we know a better solution 👍🏽

OrbisK
OrbisK previously approved these changes Apr 22, 2025
@autofix-ci autofix-ci bot dismissed stale reviews from OrbisK and 43081j via f20a236 April 22, 2025 09:26
@FishHawk
Copy link
Author

@OrbisK Is this ready to merge now?

@43081j
Copy link
Collaborator

43081j commented Apr 29, 2025

@FishHawk there is still a bug here (from before your PR) since we mistakenly setup the listeners in the component scope (onMounted)

i opened #4730 to try fix both problems in one

if we can get that PR approved, it'll likely replace this one. sorry for not letting you know sooner!

it'd be super helpful if you could review the other PR and make sure it still fixes the problem you had here

@FishHawk
Copy link
Author

@FishHawk there is still a bug here (from before your PR) since we mistakenly setup the listeners in the component scope (onMounted)

i opened #4730 to try fix both problems in one

if we can get that PR approved, it'll likely replace this one. sorry for not letting you know sooner!

it'd be super helpful if you could review the other PR and make sure it still fixes the problem you had here

It's okay, as long as it can be fixed in the next version. This issue can cause storage to be cleared in the production environment

@OrbisK OrbisK added duplicate This issue or pull request already exists and removed lgtm This PR has been approved by a maintainer labels Apr 30, 2025
@OrbisK
Copy link
Collaborator

OrbisK commented Apr 30, 2025

lets put this on hold until @FishHawk confirms that #4730 (merged, not yet released) fixes this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists size:S This PR changes 10-29 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

BUG | useStorage | Listener becomes invalid when component unmounts
3 participants