Skip to content

feat(binding): add active-related APIs to ModuleGraphConnection#13548

Merged
JSerFeng merged 14 commits intomainfrom
fy/stupefied-noyce
Apr 3, 2026
Merged

feat(binding): add active-related APIs to ModuleGraphConnection#13548
JSerFeng merged 14 commits intomainfrom
fy/stupefied-noyce

Conversation

@JSerFeng
Copy link
Copy Markdown
Contributor

@JSerFeng JSerFeng commented Mar 31, 2026

Summary

  • Add active getter, conditional getter, and getActiveState(runtime) method to ModuleGraphConnection binding, allowing JS plugins to inspect connection active state
  • Add is_conditional() public accessor on core ModuleGraphConnection
  • Add test case (get-incoming-connections-active) verifying active incoming connection properties

This is useful to debug side effects bailouts. For example we can visit all active incoming connections to know what module is included only by side effect connections.

Copilot AI review requested due to automatic review settings March 31, 2026 07:24
Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: c5fb1f1212

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread crates/rspack_binding_api/src/module_graph_connection.rs Outdated
@github-actions github-actions Bot added the team The issue/pr is created by the member of Rspack. label Mar 31, 2026
@JSerFeng JSerFeng requested a review from hardfist as a code owner March 31, 2026 07:38
@github-actions github-actions Bot added the release: feature release: feature related release(mr only) label Mar 31, 2026
Copy link
Copy Markdown
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

Adds active-state inspection APIs for ModuleGraphConnection (core + binding) so JS plugins can query whether a connection is active/conditional, plus a config test validating the behavior.

Changes:

  • Expose getActiveState(runtime) (binding) and surface non-boolean states as Symbols in @rspack/core.
  • Export ConnectionState + related Symbol constants from @rspack/core.
  • Add a new config test case module-graph/get-incoming-connections-active to validate active incoming connections.

Reviewed changes

Copilot reviewed 9 out of 10 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
tests/rspack-test/configCases/module-graph/get-incoming-connections-active/used.js Adds a used module for module-graph connection assertions
tests/rspack-test/configCases/module-graph/get-incoming-connections-active/unused.js Adds an imported-but-unused module fixture
tests/rspack-test/configCases/module-graph/get-incoming-connections-active/index.js Entry that imports used/unused modules
tests/rspack-test/configCases/module-graph/get-incoming-connections-active/rspack.config.js Plugin-based test asserting getActiveState() results on connections
packages/rspack/src/exports.ts Re-exports ConnectionState and Symbol constants
packages/rspack/src/ModuleGraphConnection.ts Monkey-patches binding getActiveState() to map string states to Symbols
packages/rspack/src/ModuleGraph.ts Ensures the ModuleGraphConnection patch is applied via side-effect import
crates/rspack_binding_api/src/module_graph_connection.rs Adds get_active_state(runtime) N-API method and computes active-state in Rust
crates/node_binding/napi-binding.d.ts Updates TS declarations for ModuleGraphConnection.getActiveState()

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

Comment thread crates/rspack_binding_api/src/module_graph_connection.rs
Comment thread crates/rspack_binding_api/src/module_graph_connection.rs
Comment thread packages/rspack/src/ModuleGraph.ts Outdated
@codspeed-hq
Copy link
Copy Markdown

codspeed-hq Bot commented Mar 31, 2026

Merging this PR will degrade performance by 1.32%

🎉 Hooray! codspeed-rust just leveled up to 4.4.1!

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.

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 16 untouched benchmarks
⏩ 19 skipped benchmarks1

⚠️ Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation rust@persistent_cache_restore@basic-react-development 26 ms 26.3 ms -1.32%
Simulation bundle@basic-react-development 348.1 ms 344.6 ms +1.02%

Comparing fy/stupefied-noyce (c280360) with main (c88a8d5)

Open in CodSpeed

Footnotes

  1. 19 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.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 31, 2026

Rsdoctor Bundle Diff Analysis

Found 6 projects in monorepo, 6 projects with changes.

📊 Quick Summary
Project Total Size Change
popular-libs 1.7 MB -
react-10k 5.7 MB -
react-1k 826.3 KB -
react-5k 2.7 MB -
rome 984.2 KB -
ui-components 5.0 MB -
📋 Detailed Reports (Click to expand)

📁 popular-libs

Path: ../build-tools-performance/cases/popular-libs/dist/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 1.7 MB - -
📄 JavaScript 1.7 MB - -
🎨 CSS 0 B - -
🌐 HTML 0 B - -
📁 Other Assets 0 B - -

📁 react-10k

Path: ../build-tools-performance/cases/react-10k/dist/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 5.7 MB - -
📄 JavaScript 5.7 MB - -
🎨 CSS 21.0 B - -
🌐 HTML 0 B - -
📁 Other Assets 0 B - -

📁 react-1k

Path: ../build-tools-performance/cases/react-1k/dist/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 826.3 KB - -
📄 JavaScript 826.3 KB - -
🎨 CSS 0 B - -
🌐 HTML 0 B - -
📁 Other Assets 0 B - -

📁 react-5k

Path: ../build-tools-performance/cases/react-5k/dist/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 2.7 MB - -
📄 JavaScript 2.7 MB - -
🎨 CSS 21.0 B - -
🌐 HTML 0 B - -
📁 Other Assets 0 B - -

📁 rome

Path: ../build-tools-performance/cases/rome/dist/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 984.2 KB - -
📄 JavaScript 984.2 KB - -
🎨 CSS 0 B - -
🌐 HTML 0 B - -
📁 Other Assets 0 B - -

📁 ui-components

Path: ../build-tools-performance/cases/ui-components/dist/rsdoctor-data.json

⚠️ No baseline data found - Unable to perform comparison analysis

Metric Current Baseline Change
📊 Total Size 5.0 MB - -
📄 JavaScript 4.7 MB - -
🎨 CSS 291.6 KB - -
🌐 HTML 0 B - -
📁 Other Assets 0 B - -

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Mar 31, 2026

📦 Binary Size-limit

Comparing c280360 to feat!: disable bundlerInfo force by default (#13599) by harpsealjs

🎉 Size decreased by 4.72KB from 49.26MB to 49.26MB (⬇️0.01%)

@JSerFeng
Copy link
Copy Markdown
Contributor Author

JSerFeng commented Apr 1, 2026

@codex review

Copy link
Copy Markdown

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2aa432bb1e

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

JSerFeng added 9 commits April 2, 2026 16:22
Expose connection active state in the binding layer so JS plugins can
inspect whether a module graph connection is active, conditional, or
evaluate its full active state with a given runtime.

- Add `active` getter (evaluates `is_active` with compilation context)
- Add `conditional` getter
- Add `getActiveState(runtime)` method returning state as string
- Add `is_conditional()` public accessor on core `ModuleGraphConnection`
- Add test case for active incoming connections
…'transitive-only' | 'circular'

Remove `active` and `conditional` getters, keep only `getActiveState(runtime)`
which returns `boolean | string` matching webpack's ConnectionState semantics.
- Rust binding returns `boolean | string` from `getActiveState`
- JS layer patches prototype to convert strings to Symbols:
  - `Symbol("transitive only")` for TRANSITIVE_ONLY
  - `Symbol("circular connection")` for CIRCULAR_CONNECTION
- Export TRANSITIVE_ONLY, CIRCULAR_CONNECTION, and ConnectionState type
  from @rspack/core
- Remove getActiveState from napi ModuleGraphConnection class
- Add getActiveState(connection, runtime) to JsModuleGraph napi class
- Add ModuleGraphConnectionRef for passing connection as method argument
- ModuleGraph.ts wraps binding method, converting strings to Symbols
- ModuleGraphConnection.ts exports TRANSITIVE_ONLY, CIRCULAR_CONNECTION
  symbols and ConnectionState type
…ctly

Use define_symbols\! macro to create CIRCULAR_CONNECTION and
TRANSITIVE_ONLY symbols, and return them directly from Rust via
custom ToNapiValue impl on JsConnectionState. No JS prototype
patching needed — the napi method returns boolean | symbol natively.
After rebase, define_symbols! uses stringify!($cell) as export name,
so CIRCULAR_CONNECTION_SYMBOL and TRANSITIVE_ONLY_SYMBOL are the
actual binding export names. Update napi-binding.d.ts and re-exports.
@JSerFeng JSerFeng force-pushed the fy/stupefied-noyce branch from df6c54e to b9ea6bf Compare April 2, 2026 08:30
JSerFeng added 5 commits April 2, 2026 19:38
- Add CIRCULAR_CONNECTION_SYMBOL and TRANSITIVE_ONLY_SYMBOL to
  banner.d.ts so they persist across napi codegen
- Add ConnectionState type alias in banner.d.ts
- Fix prettier formatting in test rspack.config.js
exports_info_artifact and module_graph_cache_artifact are StealCell
and may be stolen during certain compilation phases. Use try_read()
with Default fallback instead of direct deref to prevent panic.
When exports_info_artifact is not available (stolen during
finishModules hook), conditional connections cannot be properly
evaluated. Return Active(true) as fallback since optimization
has not run yet and all connections should be considered active.
Add CSS file and CssExtractRspackPlugin to test case. Verify that
CssDependency outgoing connections return TRANSITIVE_ONLY symbol
in processAssets phase where exports info artifact is available.
@JSerFeng JSerFeng force-pushed the fy/stupefied-noyce branch from e4fa4d5 to c280360 Compare April 3, 2026 10:22
@JSerFeng JSerFeng enabled auto-merge (squash) April 3, 2026 10:43
@JSerFeng JSerFeng merged commit 571543e into main Apr 3, 2026
37 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

release: feature release: feature 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.

3 participants