Skip to content

Conversation

@agneym
Copy link
Contributor

@agneym agneym commented Jan 7, 2026

Summary

  • Fixed bug where ContextReplacementPlugin applied transformations to all require.context() calls regardless of regex match
  • The regex check was incorrectly placed inside the new_content_resource conditional, causing recursive, regExp, and critical modifications to apply to non-matching contexts
  • Now all transformations only apply when the configured regex successfully matches the request

Test plan

  • Added test case context-replacement/non-matching-regex that verifies non-matching contexts are not affected
  • Existing context-replacement tests should continue to pass

Closes #12656

@netlify
Copy link

netlify bot commented Jan 7, 2026

Deploy Preview for rspack canceled.

Built without sensitive environment variables

Name Link
🔨 Latest commit 2c9cfd8
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/6965c97e424d6400087752ae

@github-actions github-actions bot added the release: bug fix release: bug related release(mr only) label Jan 7, 2026
@agneym agneym changed the title fix(ContextReplacementPlugin): only apply changes when regex matches fix(context-replacement): only apply changes when regex matches Jan 7, 2026
@LingyuCoder LingyuCoder requested a review from SyMind January 13, 2026 02:26
@codspeed-hq
Copy link

codspeed-hq bot commented Jan 13, 2026

Merging this PR will not alter performance

✅ 16 untouched benchmarks
⏩ 1 skipped benchmark1


Comparing agneym:fix/context-replacement-regex-matching (2c9cfd8) with main (d02192f)

Open in CodSpeed

Footnotes

  1. 1 benchmark was skipped, so the baseline result was used instead. If it was deleted from the codebase, click here and archive it to remove it from the performance reports.

@chenjiahan chenjiahan enabled auto-merge (squash) January 13, 2026 03:23
@chenjiahan
Copy link
Member

Thank you! ❤️

The plugin was applying transformations (recursive, regExp, critical) to
all require.context() calls regardless of whether the configured regex
pattern matched the request. This fix ensures all transformations only
apply when the regex successfully matches.

Closes web-infra-dev#12656
auto-merge was automatically disabled January 13, 2026 04:26

Head branch was pushed to by a user without write access

@agneym agneym force-pushed the fix/context-replacement-regex-matching branch from 0300b88 to 2c9cfd8 Compare January 13, 2026 04:26
@agneym
Copy link
Contributor Author

agneym commented Jan 13, 2026

@chenjiahan @SyMind rebased with main branch since some unexpected test failures

@chenjiahan chenjiahan enabled auto-merge (squash) January 13, 2026 05:23
@chenjiahan chenjiahan merged commit a6892fe into web-infra-dev:main Jan 13, 2026
52 checks passed
LingyuCoder pushed a commit that referenced this pull request Jan 14, 2026
fix(ContextReplacementPlugin): only apply changes when regex matches

The plugin was applying transformations (recursive, regExp, critical) to
all require.context() calls regardless of whether the configured regex
pattern matched the request. This fix ensures all transformations only
apply when the regex successfully matches.

Closes #12656
LingyuCoder pushed a commit that referenced this pull request Jan 14, 2026
fix(ContextReplacementPlugin): only apply changes when regex matches

The plugin was applying transformations (recursive, regExp, critical) to
all require.context() calls regardless of whether the configured regex
pattern matched the request. This fix ensures all transformations only
apply when the regex successfully matches.

Closes #12656
hardfist pushed a commit that referenced this pull request Jan 14, 2026
fix(ContextReplacementPlugin): only apply changes when regex matches

The plugin was applying transformations (recursive, regExp, critical) to
all require.context() calls regardless of whether the configured regex
pattern matched the request. This fix ensures all transformations only
apply when the regex successfully matches.

Closes #12656
LingyuCoder pushed a commit that referenced this pull request Jan 15, 2026
fix(ContextReplacementPlugin): only apply changes when regex matches

The plugin was applying transformations (recursive, regExp, critical) to
all require.context() calls regardless of whether the configured regex
pattern matched the request. This fix ensures all transformations only
apply when the regex successfully matches.

Closes #12656
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: bug fix release: bug related release(mr only)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Context Replacement Plugin applies changes even when the regex fails to match

3 participants