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

Already on GitHub? Sign in to your account

fix(nuxt): ignore prefix if clearNuxtState called w/o keys #23483

Merged
merged 1 commit into from Oct 1, 2023

Conversation

AlbertBrand
Copy link
Contributor

@AlbertBrand AlbertBrand commented Sep 30, 2023

πŸ”— Linked issue

resolves #23482.

❓ Type of change

  • πŸ“– Documentation (updates to the documentation, readme or JSdoc annotations)
  • 🐞 Bug fix (a non-breaking change that fixes an issue)
  • πŸ‘Œ Enhancement (improving an existing functionality like performance)
  • ✨ New feature (a non-breaking change that adds functionality)
  • 🧹 Chore (updates to the build process or auxiliary tools and libraries)
  • ⚠️ Breaking change (fix or feature that would cause existing functionality to change)

πŸ“š Description

This fixes clearNuxtState behavior when called with a function or with no arguments. Internally, useState prefixes all keys. When clearNuxtState is called with a callback, it should not be needed to provide the prefix on keys from the calling side (this is an implementation detail). Also, when called without argument, all keys should be reset. The current behavior resets none, because all prefixed keys are prefixed again and then removed (which matches none).

I added mulitple tests as a separate describe to make sure all functionality is tested.

πŸ“ Checklist

  • I have linked an issue or discussion.
  • I have updated the documentation accordingly.

@stackblitz
Copy link

stackblitz bot commented Sep 30, 2023

Review PR in StackBlitz Codeflow Run & review this pull request in StackBlitz Codeflow.

Copy link
Member

@danielroe danielroe left a comment

Choose a reason for hiding this comment

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

Thank you ❀️

Comment on lines 44 to +45
const _allKeys = Object.keys(nuxtApp.payload.state)
.map(key => key.substring(useStateKeyPrefix.length))
Copy link
Member

Choose a reason for hiding this comment

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

I would also welcome a future PR that improves perf by not enumerating state keys when an array of strings is provided as the keys arg.

@danielroe danielroe changed the title fix(nuxt): make clearNuxtState work when called with function or no arguments fix(nuxt): ignore prefix if clearNuxtState called w/o keys Oct 1, 2023
@danielroe danielroe merged commit df90d42 into nuxt:main Oct 1, 2023
34 checks passed
@github-actions github-actions bot mentioned this pull request Oct 1, 2023
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.

clearNuxtState composable does not work with function callback or clear all (no arguments)
2 participants