Repository navigation
fix(devtools-bundler-core): make stateful-regex ignore patterns deterministic - #5
Open
detail-app[bot] wants to merge 1 commit into
Conversation
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Detail bug report: View on Detail
🎯 Changes
The
matcherused by theinjectSource.ignore.files/ignore.componentsconfig calledpattern.test(s)directly on user-suppliedRegExpobjects. When a regex has theg(global) ory(sticky) flag,.test()is stateful and advanceslastIndexon a successful match. Because the same regex object from the user's config is reused across every module transform (Vitetransformhook and rspack loader) and every JSX-element check for the lifetime of a dev server/build, identical inputs produced alternating match/no-match results — so files/components the user asked to ignore were intermittently injected withdata-tsd-sourcedepending on module processing order.Fix:
matchernow clones anyg/y-flagged regex without those stateful flags (preserving all other flags likei/m/s/u) so each.test()is stateless and deterministic. Flagless regexes pass through by identity, so the common documented cases are unchanged. The user's original config regex is never mutated (lastIndexstays0).✅ Checklist
pnpm test:pr, or these tests do not apply to this pull request.🚀 Release Impact
Testing
tsc --noEmit), lint (eslint ./src), and build (vite build+publint --strict) for@tanstack/devtools-bundler-coreall pass. Downstream consumers@tanstack/devtools-viteand@tanstack/devtools-rspacktypecheck cleanly against the updated package. The fulldevtools-bundler-coresuite (13 files / 204 tests) is green, including the existinginject-sourceignore-pattern tests (53 tests, no regression).matcher.test.tsasserting thatg- andy-flagged regexes stay deterministic across repeated calls with a shared regex object, and that the user's regexlastIndexis not mutated.addSourceToJsx(code, 'src/Foo.test.tsx', { files: [/\.test\.tsx$/g] })calls sharing one config object — the exact code path the Vite plugin and rspack loader use per module. With the fix, the file is ignored on every call; with the fix reverted the suite reproduces the reported nondeterminism (call chore: remove unused a11y panel style keys #1 injects instead of ignoring,lastIndexadvances to16, and a file with multiple<Button/>elements intermittently getsdata-tsd-sourceon a later element). The fix was restored before commit.injectSource, and the headless public-API test exercises the identical shared-config-reuse code path, with the revert control confirming the exact reported symptom.Automatic Fixes PRs can be configured here.