Skip to content

fix: refresh useCookie value when cookie name changes - #2723

Open
Sudashiii wants to merge 1 commit into
streamich:masterfrom
Sudashiii:fix/use-cookie-name-change
Open

Sudashiii wants to merge 1 commit into
streamich:masterfrom
Sudashiii:fix/use-cookie-name-change

Conversation

@Sudashiii

Copy link
Copy Markdown

Description

Changing the cookieName passed to useCookie leaves the returned value pointing to the previous cookie. For example, switching from useCookie('cookieA') to useCookie('cookieB') continues to return cookie A's value even though the update and delete callbacks already target cookie B.

Refresh the stored value in an effect whenever cookieName changes, returning null when the new cookie does not exist. Add regression tests for switching names, missing cookies, switching back, and update/delete callbacks after switching. Document the behavior.

Fixes #2590.

Type of change

  • Bug fix (non-breaking change which fixes an issue)

Validation

  • Before the fix, three new regression tests failed with the previous cookie's value.
  • After the fix, all 496 tests across 76 suites pass.
  • All 8 useCookie tests pass, with 100% statement, branch, function, and line coverage for src/useCookie.ts.
  • Type checking and CommonJS/ES module builds pass.
  • Lint passes with no errors; 97 existing warnings are in untouched files. The changed source and test files lint cleanly.

Checklist

  • Read the Contributing Guide
  • Perform a code self-review
  • Comment the code, particularly in hard-to-understand areas — not applicable to this small effect
  • Add documentation
  • Add hook's story at Storybook — not applicable; existing hook API is unchanged
  • Cover changes with tests
  • Ensure the test suite passes
  • Provide 100% test coverage for the changed hook
  • Make sure code lints
  • Make sure types are fine

This branch has not been deployed

No deployments
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.

useCookie does not react to changes in the passed in "cookieName"

1 participant