Skip to content

fix(store): compare regular expression patterns and flags - #427

Open
chengzuopeng wants to merge 1 commit into
TanStack:mainfrom
chengzuopeng:fix/compare-regexp-pattern-and-flags
Open

chengzuopeng wants to merge 1 commit into
TanStack:mainfrom
chengzuopeng:fix/compare-regexp-pattern-and-flags

Conversation

@chengzuopeng

@chengzuopeng chengzuopeng commented Nov 26, 2026 •

Copy link
Copy Markdown

Fixes #426.

🎯 Changes

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.

Prepared with AI assistance.

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • 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.

@changeset-bot

changeset-bot Bot commented Nov 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: c8a6cb3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 9 packages
Name Type
@tanstack/store Patch
@tanstack/angular-store Patch
@tanstack/lit-store Patch
@tanstack/octane-store Patch
@tanstack/preact-store Patch
@tanstack/react-store Patch
@tanstack/solid-store Patch
@tanstack/svelte-store Patch
@tanstack/vue-store Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai

coderabbitai Bot commented Nov 26, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

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.

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: harry-whorlow

Merge Risk: Minimal · up to c8a6c

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: Passed 4

Check name Status Explanation
Title check Passed 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 Passed 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 Passed 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 Passed 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.

Share

Recent review info

Run configuration

Commits

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.

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.

compareDeep and compareShallow suppress RegExp updates

1 participant