Skip to content

Conversation

@LingyuCoder
Copy link
Contributor

@LingyuCoder LingyuCoder commented Dec 16, 2025

Summary

This PR implements the UniversalCompileAsyncWasmPlugin for universal chunk loading, which allows WebAssembly modules to be loaded in both browser and Node.js environments. The plugin automatically detects the runtime environment and uses the appropriate loading mechanism (fetch API for browsers, fs.readFile for Node.js).

The implementation follows the webpack's UniversalCompileAsyncWasmPlugin pattern and adds support for the universal wasm loading type. When wasmLoading: "universal" is configured, the plugin generates code that can work in both environments by detecting the presence of document or self globals.

By the way, modified some test cases from old webassembly/sync to webassembly/async, rspack has no plan to support webassembly/sync.

Checklist

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

Copilot AI review requested due to automatic review settings December 16, 2025 09:53
@netlify
Copy link

netlify bot commented Dec 16, 2025

Deploy Preview for rspack canceled.

Name Link
🔨 Latest commit 64ed07a
🔍 Latest deploy log https://app.netlify.com/projects/rspack/deploys/694144c0da061c00081d9332

@github-actions github-actions bot added release: feature release: feature related release(mr only) team The issue/pr is created by the member of Rspack. labels Dec 16, 2025
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 implements the UniversalCompileAsyncWasmPlugin to enable WebAssembly module loading that works in both browser and Node.js environments. The plugin automatically detects the runtime environment using feature detection (typeof document !== 'undefined' || typeof self !== 'undefined') and uses the appropriate loading mechanism: the fetch API for browsers and fs.readFile for Node.js. This follows webpack's universal loading pattern and integrates with rspack's existing wasm loading infrastructure.

Key changes include:

  • Addition of the WasmLoadingType::Universal variant and associated plugin implementation
  • Extension of entry options and output configuration to support per-entry wasmLoading settings
  • Updates to default configuration logic to automatically enable universal loading when appropriate (output.module && environment.dynamicImport && mixed runtime capabilities)
  • Test suite updates enabling universal wasm tests and converting sync wasm tests to async

Reviewed changes

Copilot reviewed 37 out of 39 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/rspack_plugin_wasm/src/loading_plugin.rs Implements UniversalCompileAsyncWasmPlugin with environment detection and dual-path loading logic
crates/rspack_plugin_wasm/src/runtime.rs Extends AsyncWasmLoadingRuntimeModule to support additional code injection points for universal loading
crates/rspack_plugin_wasm/src/lib.rs Exports the new UniversalCompileAsyncWasmPlugin
crates/rspack_core/src/options/output.rs Adds Universal variant to WasmLoadingType enum and updates error messages
crates/rspack_core/src/options/entry.rs Adds wasm_loading field to EntryDescription for per-entry configuration
crates/rspack_core/src/chunk_group.rs Adds wasm_loading to EntryOptions struct and merge logic
crates/rspack/src/builder/mod.rs Implements logic to enable universal wasm loading when chunk loading is universal
crates/rspack_binding_api/src/options/entry.rs Adds wasm_loading to JavaScript binding interface
crates/node_binding/napi-binding.d.ts Updates TypeScript definitions to include wasmLoading in entry options
packages/rspack/src/config/defaults.ts Updates default wasmLoading to return "universal" when appropriate based on target platform
packages/rspack/src/config/normalization.ts Adds wasmLoading to EntryDescriptionNormalized type
packages/rspack/src/builtin-plugin/EntryPlugin.ts Includes wasmLoading in getRawEntryOptions return value
packages/rspack/etc/core.api.md Updates API documentation with wasmLoading in EntryDescriptionNormalized
crates/rspack_plugin_javascript/src/parser_plugin/worker_plugin.rs Adds wasm_loading to worker entry options
tests/rspack-test/configCases/wasm/universal/* Enables universal wasm loading test
tests/rspack-test/configCases/wasm/*/test.filter.js Removes TODOs for now-supported features (sync wasm, AsyncWebAssemblyModulesPlugin hooks)
tests/rspack-test/configCases/wasm/*/rspack.config.js Converts sync wasm tests to async and removes commented-out sync configurations
tests/rspack-test/configCases/wasm/wasm-in-initial-chunk-error/* Removes entire sync wasm test case
tests/rspack-test/configCases/url/dynamic-template-literals-expr/test.filter.js Enables test for webpackComments in new URL with new Worker
Comments suppressed due to low confidence (1)

crates/rspack/src/builder/mod.rs:3086

  • The commented-out code for collecting wasm_loading from entry descriptors should likely be uncommented and implemented now that wasmLoading support is added to EntryOptions. This would allow entries to specify their own wasm loading type, similar to how chunk_loading works.
        // for (_, desc) in entry.iter() {
        //   if let Some(wasm_loading) = &desc.wasm_loading {
        //     enabled_wasm_loading_types.push(wasm_loading.clone());
        //   }
        // }

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

@github-actions
Copy link
Contributor

github-actions bot commented Dec 16, 2025

Rsdoctor Bundle Diff Analysis

Found 5 project(s) in monorepo.

📁 react-10k

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

📌 Baseline Commit: 5fade2fad0 | PR: #12445

Metric Current Baseline Change
📊 Total Size 5.7 MB 5.7 MB 0 B (0.0%)
📄 JavaScript 5.7 MB 5.7 MB 0 B (0.0%)
🎨 CSS 21.0 B 21.0 B 0 B (0.0%)
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: react-10k Bundle Diff

📁 react-1k

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

📌 Baseline Commit: 5fade2fad0 | PR: #12445

Metric Current Baseline Change
📊 Total Size 823.4 KB 823.4 KB 0 B (0.0%)
📄 JavaScript 823.4 KB 823.4 KB 0 B (0.0%)
🎨 CSS 0 B 0 B N/A
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: react-1k Bundle Diff

📁 react-5k

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

📌 Baseline Commit: 5fade2fad0 | PR: #12445

Metric Current Baseline Change
📊 Total Size 2.7 MB 2.7 MB 0 B (0.0%)
📄 JavaScript 2.7 MB 2.7 MB 0 B (0.0%)
🎨 CSS 21.0 B 21.0 B 0 B (0.0%)
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: react-5k Bundle Diff

📁 rome

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

📌 Baseline Commit: 5fade2fad0 | PR: #12445

Metric Current Baseline Change
📊 Total Size 984.3 KB 984.3 KB 0 B (0.0%)
📄 JavaScript 984.3 KB 984.3 KB 0 B (0.0%)
🎨 CSS 0 B 0 B N/A
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: rome Bundle Diff

📁 ui-components

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

📌 Baseline Commit: 5fade2fad0 | PR: #12445

Metric Current Baseline Change
📊 Total Size 2.1 MB 2.1 MB 0 B (0.0%)
📄 JavaScript 2.0 MB 2.0 MB 0 B (0.0%)
🎨 CSS 83.0 KB 83.0 KB 0 B (0.0%)
🌐 HTML 0 B 0 B N/A
📁 Other Assets 0 B 0 B N/A

📦 Download Diff Report: ui-components Bundle Diff

Generated by Rsdoctor GitHub Action

@github-actions
Copy link
Contributor

github-actions bot commented Dec 16, 2025

📦 Binary Size-limit

Comparing 64ed07a to feat(deps)!: bump swc_core from 46.0.3 to 50.2.3 and swc_experimental (#12445) by CPunisher

❌ Size increased by 11.00KB from 48.28MB to 48.29MB (⬆️0.02%)

@codspeed-hq
Copy link

codspeed-hq bot commented Dec 16, 2025

CodSpeed Performance Report

Merging #12471 will not alter performance

Comparing feat/universal-wasm-loading-plugin (64ed07a) with main (5fade2f)

Summary

✅ 17 untouched

@LingyuCoder LingyuCoder merged commit 03e45d3 into main Dec 17, 2025
78 of 80 checks passed
@LingyuCoder LingyuCoder deleted the feat/universal-wasm-loading-plugin branch December 17, 2025 02:38
Copy link
Member

@chenjiahan chenjiahan left a comment

Choose a reason for hiding this comment

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

Should we update the documentation to reflect this change?

@CPunisher CPunisher mentioned this pull request Dec 17, 2025
2 tasks
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.

4 participants