You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
fix(store): compare regular expression patterns and flags - #427
compareDeep and compareShallow previously treated regular expressions with different patterns or flags as equal. In an atom configured with either comparator, that could leave the old expression in place without notifying subscribers.
Check RegExp source and flags before comparing own properties. This retains existing handling of custom enumerable properties and equals() methods. Matching can mutate lastIndex without changing the expression's pattern or flags, so the comparison continues to ignore that cursor.
Tests cover pattern changes, flags, identical expressions, lastIndex, custom properties, and atom updates and notifications through both comparators. On the base revision, the public source entry reproduced the false equality and the atom retained its old expression. The same assertion fixture passed with the change.
Core Vitest: four new regression cases failed on the base; the patched core runtime suites passed 63 tests with one existing skip. The core TypeScript source check passed. The full workspace build and lint were not verified because the pinned workspace install could not acquire its store lock in the test environment.
I have tested code changes locally with pnpm test:pr, or these tests do not apply to this pull request.
I fully understand the code in this pull request, including any code generated with AI assistance.
🚀 Release Impact
This change affects published code, and I have generated a changeset.
This change is docs/CI/dev-only (no release).
Summary by CodeRabbit
Bug Fixes
Regular-expression comparisons now distinguish patterns and flags, while treating otherwise equivalent expressions as equal even if their current match position differs.
Store updates using these comparisons now avoid unnecessary subscriber notifications for equivalent regular expressions and notify when the pattern changes.
No actionable comments were generated in the recent review.
Walkthrough
Both comparators now check regular-expression patterns and flags before comparing own keys. Tests cover matching expressions, differing patterns or flags, and atom updates and notifications.
Changes: RegExp comparison
Layer / File(s)
Summary
Compare regular-expression patterns and flags packages/store/src/compare.ts, .changeset/fix-regexp-comparison.md
_evaluate returns false when regular expressions have different patterns or flags. The changeset records a patch release.
Verify comparator and atom behavior packages/store/tests/compare.spec.ts
Parameterized tests cover both comparators, including lastIndex, custom properties, and atom notifications when an expression changes.
This fix makes regular expressions with different patterns or flags compare as unequal, so atoms update and notify subscribers. The change is narrow and tested, and no merge-blocking risk was identified.
Pre-merge checks: 4
Check name
Status
Explanation
Title check
The title names the primary change: compareDeep and compareShallow now compare RegExp patterns and flags. It follows the conventional commit format and matches the changeset, compare.ts, and tests. It…
Description check
The description follows the template. It explains the change and its motivation, and it links issue #426. It describes the test coverage and the base-versus-patched results, and it notes that the full…
Linked Issues check
Issue #426 requires that compareDeep and compareShallow return unequal for RegExp values with different patterns or flags, and that an atom using either comparator store and notify on such a change. A…
Out of Scope Changes check
The whole-PR diff against the merge base 3ee69b9 changes three areas. packages/store/src/compare.ts adds the RegExp source and flags check that implements #426. packages/store/tests/compare.spec.ts ad…
Full details: Title check
Explanation
The title names the primary change: compareDeep and compareShallow now compare RegExp patterns and flags. It follows the conventional commit format and matches the changeset, compare.ts, and tests. It is specific enough for a reviewer scanning history.
Full details: Description check
Explanation
The description follows the template. It explains the change and its motivation, and it links issue #426. It describes the test coverage and the base-versus-patched results, and it notes that the full workspace build and lint were not verified. The checklist shows the changeset was generated. The first checklist item and the test-run item remain unchecked, but the author explains the test state in the Changes section. Those items are minor.
Full details: Linked Issues check
Explanation
Issue #426 requires that compareDeep and compareShallow return unequal for RegExp values with different patterns or flags, and that an atom using either comparator store and notify on such a change. At the reviewed head, packages/store/src/compare.ts adds a check in _evaluate, after the equals() branch and before the own-key comparison. When both values are RegExp and objA.source or objA.flags differs from objB, the function returns false. Both comparators call _evaluate, so both are covered. The check ignores lastIndex, so matching state does not affect equality. Matching RegExp values with custom enumerable properties still go through the existing own-key comparison. The tests in packages/store/tests/compare.spec.ts cover pattern changes, flag changes, identical expressions, lastIndex, custom properties, and atom notifications for both comparators. The PR author reports four regression cases failing on the base and passing with the change. I did not run the tests. The unverified full workspace build and lint do not affect a coding requirement of #426.
Full details: Out of Scope Changes check
Explanation
The whole-PR diff against the merge base 3ee69b9 changes three areas. packages/store/src/compare.ts adds the RegExp source and flags check that implements #426. packages/store/tests/compare.spec.ts adds regression tests for that behavior. .changeset/fix-regexp-comparison.md adds a patch changeset for the published @tanstack/store package. The changeset and tests support the fix and do not add unrelated behavior. No public API declarations change.
Finishing Touches
Generate unit tests (beta)
Create a new PR
Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
Reviewing files that changed from the base of the PR and between 3ee69b9 and c8a6cb3.
Files selected for processing: 3
.changeset/fix-regexp-comparison.md
packages/store/src/compare.ts
packages/store/tests/compare.spec.ts
Included review availability: This review used your included allowance. Your plan provides up to 4 included reviews per hour; 3 remain after this review.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #426.
🎯 Changes
compareDeepandcompareShallowpreviously treated regular expressions with different patterns or flags as equal. In an atom configured with either comparator, that could leave the old expression in place without notifying subscribers.Check RegExp source and flags before comparing own properties. This retains existing handling of custom enumerable properties and
equals()methods. Matching can mutatelastIndexwithout changing the expression's pattern or flags, so the comparison continues to ignore that cursor.Tests cover pattern changes, flags, identical expressions,
lastIndex, custom properties, and atom updates and notifications through both comparators. On the base revision, the public source entry reproduced the false equality and the atom retained its old expression. The same assertion fixture passed with the change.Core Vitest: four new regression cases failed on the base; the patched core runtime suites passed 63 tests with one existing skip. The core TypeScript source check passed. The full workspace build and lint were not verified because the pinned workspace install could not acquire its store lock in the test environment.
Prepared with AI assistance.
✅ Checklist
pnpm test:pr, or these tests do not apply to this pull request.🚀 Release Impact
Summary by CodeRabbit