Skip to content

feat: support URL module entries with parser-created async blocks - #15663

Draft
intellild wants to merge 1 commit into
mainfrom
codex/url-async-block-assets
Draft

intellild wants to merge 1 commit into
mainfrom
codex/url-async-block-assets

Conversation

@intellild

Copy link
Copy Markdown
Contributor

Motivation

Support referencing bundled JavaScript and CSS modules through new URL() without patching cached modules or their dependency blocks after building the module graph.

The dependency structure must remain valid when an unchanged issuer resolves to a different target during a rebuild. For example, new URL('./target', import.meta.url) can initially resolve to target.js, then resolve to target.txt after the JavaScript file is removed. Reusing the issuer must not leave the URL pointing to a stale JavaScript entry.

Changes

  • Create URL async blocks and entry options during parsing, independently of the resolved target type.
  • Before normal splitChunks optimization, move modules from URL-only asset/value entries back into their referencing chunks. Reuse existing asset emission and deduplication, and preserve inline/source assets, custom public paths, ignored URLs, and fragment URLs.
  • Keep JavaScript and CSS targets as independently bundled URL entries, selecting the output using the module's source types.
  • Preserve inner-graph usage tracking for URL dependencies inside blocks and correctly disconnect entry-module associations.
  • Add English and Chinese usage documentation. No module default rules are added; bundling JS/CSS targets requires explicit dependency: 'url' rules.

Usage

Use the resulting URLs to load a script or stylesheet separately:

// rspack.config.mjs
export default {
  module: {
    rules: [
      { test: /\.js$/, dependency: 'url', type: 'javascript/auto' },
      { test: /\.css$/, dependency: 'url', type: 'css' },
    ],
  },
};
const scriptUrl = new URL('./script.js', import.meta.url);
const stylesheetUrl = new URL('./style.css', import.meta.url);

Creating these URLs does not execute the script or apply the stylesheet. Without the explicit rules, URL targets retain their asset behavior.

Regression coverage

  • async-block-assets: multiple entries sharing an asset, splitChunks enabled/disabled, async chunks enabled/disabled, resource/inline/source assets, custom public paths, and ordinary dynamic imports.
  • async-entry-module-types: JS/CSS output selection, CSS imports, CSS export types, and asset fallback when rules contain only test.
  • async-entry-rebuild: cached rebuilds across cache and incremental configurations.
  • async-entry-target-type-change: the previously identified regression, extended to JS → asset → JS → asset. It verifies that the incremental issuer builds only once, the block remains stable, asset ownership is restored, and updated asset contents are emitted.

Draft scope

Empty async entries/chunks are intentionally retained in this iteration. Their removal is a follow-up; this draft implements the asset migration without adding module graph mutation hooks.

Validation

  • URL regression selection: 60 passed.
  • Asset-module regression selection: 90 passed.
  • Worker regression selection: 106 passed.
  • Extended target-type-change watch regression: 8 passed.
  • cargo clippy -p rspack_core -p rspack_plugin_javascript -p rspack_plugin_css --all-targets -- --deny warnings
  • Rust formatting, diff checks, and commit-hook documentation spell checking passed.

by OpenAI Codex

@cloudflare-workers-and-pages

Copy link
Copy Markdown

Deploying rspack with  Cloudflare Pages  Cloudflare Pages

Latest commit: 4601c82
Status: ✅  Deploy successful!
Preview URL: https://7d2f679f.rspack-v2.pages.dev
Branch Preview URL: https://codex-url-async-block-assets.rspack-v2.pages.dev

View logs

@github-actions

Copy link
Copy Markdown
Contributor

📦 Binary Size-limit

Comparing 4601c82 to fix: revert "feat(core): expose NormalModule beforeLoaders hook to JS" (#15660) by AsyncIter

❌ Size increased by 16.00KB from 68.85MB to 68.86MB (⬆️0.02%)

@github-actions

Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 0 projects with changes.

📊 Quick Summary
Project Total Size Gzip Size Change Gzip Change
popular-libs 1.7 MB 523.6 KB 0 0
react-10k 5.3 MB 1.3 MB 0 0
react-1k 799.2 KB 217.5 KB 0 0
react-5k 2.6 MB 662.0 KB 0 0
ui-components 4.9 MB 1.4 MB 0 0

Generated by Rsdoctor GitHub Action

@codspeed

codspeed Bot commented Sep 14, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will degrade performance by 0.4%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 1 improved benchmark
❌ 1 regressed benchmark
✅ 48 untouched benchmarks
⏩ 47 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Benchmark BASE HEAD Efficiency
rust@create_chunk_assets 1.1 ms 1.2 ms -3.2%
rust@create_module_hashes 7.6 ms 7.4 ms +2.48%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing codex/url-async-block-assets (4601c82) with main (22f1dd8)

Open in CodSpeed

Footnotes

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

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant