Skip to content

fix: concate with external runtime specific modules#9490

Merged
JSerFeng merged 1 commit intomainfrom
fix/concate-runtime-condition
Feb 27, 2025
Merged

fix: concate with external runtime specific modules#9490
JSerFeng merged 1 commit intomainfrom
fix/concate-runtime-condition

Conversation

@JSerFeng
Copy link
Contributor

@JSerFeng JSerFeng commented Feb 27, 2025

Summary

close #8649

Runtime Condition

Runtime Condition is used when an export is utilized in one runtime but not in another. Rspack will generate code like this:

if (__webpack_require__.j === 'main') {
var lib = __webpack_require__('./foo');
}

This means that if users enter this code, the execution of 'foo' and its sub-modules will only occur if they go through the main runtime; otherwise, it can be skipped.

In our architecture, modules are connected through various connections. Some connections point to the same module, where one may be active in a particular runtime while others are not. This scenario can occur.

When this happens, we need to ensure that all connections are valid for the concatenated module to function properly.

if (__webpack_require__.j === 'bar') {
var lib = __webpack_require__('./foo');
}
if (__webpack_require__.j === 'foo') {
var lib = __webpack_require__('./foo');
}

We must guarantee that 'lib' can be active for all possible runtimes. In the previous implementation, we incorrectly used only one of valid runtime.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

@netlify
Copy link

netlify bot commented Feb 27, 2025

Deploy Preview for rspack ready!

Name Link
🔨 Latest commit da996b6
🔍 Latest deploy log https://app.netlify.com/sites/rspack/deploys/67c05472256454000973915f
😎 Deploy Preview https://deploy-preview-9490--rspack.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions github-actions bot added release: bug fix release: bug related release(mr only) team The issue/pr is created by the member of Rspack. labels Feb 27, 2025
@codspeed-hq
Copy link

codspeed-hq bot commented Feb 27, 2025

CodSpeed Performance Report

Merging #9490 will not alter performance

Comparing fix/concate-runtime-condition (da996b6) with main (10c824b)

🎉 Hooray! codspeed-node just leveled up to 4.0.0!

A heads-up, this is a breaking change and it might affect your current performance baseline a bit. But here's the exciting part - it's packed with new, cool features and promises improved result stability 🥳!
Curious about what's new? Visit our releases page to delve into all the awesome details about this new version.

Summary

✅ 7 untouched benchmarks

@JSerFeng JSerFeng force-pushed the fix/concate-runtime-condition branch from 1763e34 to 9be0aa9 Compare February 27, 2025 11:58
@JSerFeng JSerFeng force-pushed the fix/concate-runtime-condition branch from 9be0aa9 to da996b6 Compare February 27, 2025 12:02
@JSerFeng JSerFeng marked this pull request as ready for review February 27, 2025 12:11
@JSerFeng JSerFeng requested review from ahabhgk and fi3ework February 27, 2025 12:19
@JSerFeng JSerFeng merged commit 2b45815 into main Feb 27, 2025
31 checks passed
@JSerFeng JSerFeng deleted the fix/concate-runtime-condition branch February 27, 2025 12:36
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) team The issue/pr is created by the member of Rspack.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Incorrect conditional imports are generated when usedExports is enabled

2 participants