Skip to content

fix(useCookie): preserve empty cookie values - #2727

Open
feritcemkahraman wants to merge 1 commit into
streamich:masterfrom
feritcemkahraman:fix/cookie-empty-value
Open

feritcemkahraman wants to merge 1 commit into
streamich:masterfrom
feritcemkahraman:fix/cookie-empty-value

Conversation

@feritcemkahraman

@feritcemkahraman feritcemkahraman commented Oct 7, 2026 •

Copy link
Copy Markdown

Description

An empty cookie becomes null when the component remounts, even though useCookie accepts '' when setting it. Use a nullish fallback so an empty cookie stays empty and only a missing cookie becomes null.

The tests cover reading an existing empty cookie and setting one before remounting. The docs now explain that distinction. Cookie-name changes are handled separately in #2723.

Checked with the original Jest setup: 494 tests in 76 suites pass, including all six cookie tests. Full lint passes with 97 existing warnings. The changed hook passes a strict TypeScript check; full type/build checks still fail in the existing nano-css/csstype dependency declarations.

Validation details

Both new tests fail before the fix. Hook coverage is 100% statements/functions/lines and 90.9% branches, including transpiler branches. Jest 26, React 17.0.2 and js-cookie 3.0.5 were used. The full lint run used an LF-normalized local Windows checkout.

The original yarn.lock Babel types were used to get past newer syntax unsupported by TypeScript 4.1.5; three nano-css/csstype declaration errors remain. No package or lockfile changes are included. git diff --check passes. Storybook was not built.

Type of change

  • Bug fix

Checklist

  • Read the Contributing Guide
  • Perform a code self-review
  • Comment the code, particularly in hard-to-understand areas
  • Add documentation
  • Add hook's story at Storybook
  • Cover changes with tests
  • Ensure the test suite passes (yarn test)
  • Provide 100% tests coverage
  • Make sure code lints (yarn lint).
  • Make sure types are fine (yarn lint:types).

@feritcemkahraman
feritcemkahraman marked this pull request as ready for review October 8, 2026 01:46

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.

1 participant