Skip to content

fix: use correct Cell for EsmLibraryPlugin#12067

Merged
JSerFeng merged 3 commits intomainfrom
esm-lib-plugin
Nov 3, 2025
Merged

fix: use correct Cell for EsmLibraryPlugin#12067
JSerFeng merged 3 commits intomainfrom
esm-lib-plugin

Conversation

@JSerFeng
Copy link
Contributor

@JSerFeng JSerFeng commented Nov 3, 2025

Summary

Plugin needs to run without any mutable reference, however we do need to store some data in plugin.

EsmLibraryPlugin has some internal state that needs to be initialized in make phase, and consumed by seal phase, we use OnceCell before, which will panic if user rebuild again.

The case is a common write then read case. And because we need to support async, so use AtomicRefCell for such cases.

Related links

Checklist

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

@JSerFeng JSerFeng requested a review from quininer as a code owner November 3, 2025 07:58
Copilot AI review requested due to automatic review settings November 3, 2025 07:58
@netlify
Copy link

netlify bot commented Nov 3, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 34dcef6
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/6908772a5edcf10008bee1d6

@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 Nov 3, 2025
@JSerFeng JSerFeng requested review from quininer and removed request for quininer November 3, 2025 07:58
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR refactors the EsmLibraryPlugin to replace OnceCell with AtomicRefCell for two fields: concatenated_modules_map_for_codegen and links. This change allows for more flexible interior mutability patterns and simplifies the code by replacing .get().expect() and .set().expect() calls with standard borrow operations.

Key Changes:

  • Replace OnceCell with AtomicRefCell for internal state management
  • Simplify access patterns using borrow() and borrow_mut() instead of get() and set()
  • Add atomic_refcell as a new dependency

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
crates/rspack_plugin_esm_library/Cargo.toml Adds atomic_refcell dependency
Cargo.lock Updates lock file with new dependency
crates/rspack_plugin_esm_library/src/plugin.rs Replaces OnceCell with AtomicRefCell for two fields and updates access patterns
crates/rspack_plugin_esm_library/src/link.rs Updates mutation logic to use borrow_mut()
crates/rspack_plugin_esm_library/src/render.rs Updates read access to use borrow() and direct indexing

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 3, 2025

📦 Binary Size-limit

Comparing 34dcef6 to fix: should parse webpackExports with empty array (#12066) by harpsealjs

❌ Size increased by 10.25KB from 47.85MB to 47.86MB (⬆️0.02%)

@codspeed-hq
Copy link

codspeed-hq bot commented Nov 3, 2025

CodSpeed Performance Report

Merging #12067 will not alter performance

Comparing esm-lib-plugin (34dcef6) with main (3be48da)

Summary

✅ 17 untouched

@JSerFeng JSerFeng enabled auto-merge (squash) November 3, 2025 10:35
@JSerFeng JSerFeng merged commit 55c107d into main Nov 3, 2025
68 of 70 checks passed
@JSerFeng JSerFeng deleted the esm-lib-plugin branch November 3, 2025 10:38
@h-a-n-a h-a-n-a mentioned this pull request Nov 5, 2025
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.

2 participants