Skip to content

fix(useSet): remove and toggle NaN using native Set equality - #2729

Closed
Aminark wants to merge 2 commits into
streamich:masterfrom
Aminark:codex/use-set-nan-removal
Closed

Aminark wants to merge 2 commits into
streamich:masterfrom
Aminark:codex/use-set-nan-removal

Conversation

@Aminark

@Aminark Aminark commented Oct 23, 2026

Copy link
Copy Markdown

Description

useSet(new Set([NaN, 1])) reports that NaN is present, but both remove(NaN) and toggle(NaN) leave it in the set. Removal currently filters with strict inequality, for which NaN !== NaN.

Clone the previous set and use native Set.delete so removal follows the same equality semantics as membership. Toggling uses the same approach. Previous state snapshots, the caller's initial set, reset behavior, and stable action references are preserved.

Three regression cases cover NaN removal, toggling on/off, and immutable state/reset. All three fail against the original implementation.

Related: #2669 and #2687 propose broader ref-based rewrites. This PR keeps the existing immutable state implementation and addresses the NaN correctness issue only.

Type of change

  • Bug fix (non-breaking)

Validation

  • yarn test: 76 suites, 495 tests passed.
  • yarn lint: passed with 0 errors and 97 warnings.
  • yarn lint:types: passed.
  • yarn build: CommonJS and ES module builds passed.
  • Focused useSet/useMap/useList run: 56 tests passed; useSet statement, branch, function and line coverage are all 100%.
  • git diff --check: passed.

Checklist

  • Read the contributing guide.
  • Reviewed the code and regression tests.
  • Covered the behavior change with failing-before/passing-after tests.
  • Test suite, lint, types and builds pass.
  • Documentation and Storybook impact considered: no API changes or new usage to document.

AI assistance: OpenAI Codex prepared the implementation and tests, ran the checks, and drafted this PR.

Clone the previous Set before deleting or toggling values so NaN follows Set membership semantics while previous state and reset remain unchanged.

Generated-by: OpenAI Codex
The three added cases fail before the fix. The useSet, useMap and useList suites pass after it (56 tests); useSet has 100% statement, branch, function and line coverage.

Generated-by: OpenAI Codex
@Aminark Aminark closed this Oct 23, 2026
@Aminark
Aminark deleted the codex/use-set-nan-removal branch October 23, 2026 18:21
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