Skip to content

fix(resolver): keep RegExp restrictions in ResolverFactory cache key - #16054

Merged
stormslowly merged 2 commits into
mainfrom
fix/resolver-factory-regexp-cache-key
Oct 12, 2026
Merged

stormslowly merged 2 commits into
mainfrom
fix/resolver-factory-regexp-cache-key

Conversation

@stormslowly

Copy link
Copy Markdown
Contributor

Summary

ResolverFactory.get() keys its string cache with JSON.stringify(resolveOptions), which serializes every RegExp as {}. Resolve options that differ only in RegExp restrictions (e.g. [/\.css$/] vs [/\.js$/], or /x/ vs /x/i) therefore got the same cached resolver, so whichever was created first won. withOptions() goes through the same cache and had the same problem.

The cache key now serializes a RegExp as { regexp: String(value) }, which keeps both source and flags and cannot collide with a plain string restriction.

Before: get('normal', { restrictions: [/\.js$/] }) after a [/\.css$/] lookup returned the CSS resolver and resolved style to index.css.
After: each pattern gets its own resolver, and the JS one resolves to index.js.

Related links

Closes #15826

Checklist

  • Tests updated (new configCases/resolver-factory/restriction-cache-key, which fails without the fix and covers different patterns, different flags, withOptions(), and that the same pattern still hits the cache)
  • Documentation updated (not needed)

JSON.stringify serializes every RegExp as {}, so resolve options that
differ only in RegExp restrictions shared one cached resolver.

Closes #15826
@stormslowly
stormslowly requested a review from hardfist as a code owner October 11, 2026 18:39
@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

📦 Binary Size-limit

Comparing d45e02a to fix: preserve pure exports during module concatenation (#16053) by harpsealjs

🙈 Size remains the same at 67.25MB

@github-actions

github-actions Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Gzip Size Change Gzip Change
popular-libs 1.7 MB 529.6 KB 0 0
react-10k 5.4 MB 1.3 MB 0 0
react-5k 2.6 MB 670.9 KB 0 0
react-1k 827.7 KB 226.6 KB 0 0
ui-components 4.7 MB 1.4 MB 0 0

Generated by Rsdoctor GitHub Action

@codspeed

codspeed Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 54 untouched benchmarks
⏩ 47 skipped benchmarks1


Comparing fix/resolver-factory-regexp-cache-key (d45e02a) with main (191c0ef)

Open in CodSpeed

Footnotes

  1. 47 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@stormslowly
stormslowly enabled auto-merge (squash) October 12, 2026 06:37

@chenjiahan chenjiahan left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

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.

[Bug]: ResolverFactory cache conflates different RegExp restrictions

2 participants