Skip to content

fix: support deferred imports introduced by hot updates - #16015

Merged
LingyuCoder merged 2 commits into
mainfrom
seal/fix-defer-import-hmr
Oct 9, 2026
Merged

LingyuCoder merged 2 commits into
mainfrom
seal/fix-defer-import-hmr

Conversation

@LingyuCoder

Copy link
Copy Markdown
Contributor

Motivation

Fixes #15960.

With experiments.deferImport, lazy compilation can introduce deferred imports through a hot update after the initial bootstrap has run. The deferred namespace and async-dependency helpers access the module cache through a bootstrap-local variable, causing ReferenceError: __webpack_module_cache__ is not defined in the hot-update chunk. The deferred exports table has the same scope problem, and the initial require may not include support for sharing those exports.

Changes

Reference the module cache through MODULE_CACHE and expose the deferred exports table as DEFERRED_MODULE_EXPORTS. When HMR and experiments.deferImport are enabled, initialize the shared table and the corresponding require support in the initial bootstrap, while generating the deferred namespace helper only when needed.

Carry the shared state through both runtime modes and modern-module output so pending namespaces retain their export targets when helpers are updated. Also remove table entries after successful module execution with strictModuleErrorHandling, preventing stale export objects from being reused by subsequent hot updates.

@LingyuCoder
LingyuCoder requested a review from hardfist as a code owner October 8, 2026 10:56
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codex Review Summary

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-10-09T02:54:27.822784Z 16d1901 New commits
ℹ️ 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" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

📦 Binary Size-limit

Comparing 16d1901 to perf(sources): profile allocations and trim source map capacity (#16014) by Cong-Cong Pan

🙈 Size remains the same at 67.17MB

@github-actions

github-actions Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Rsdoctor Bundle Diff Analysis

Found 5 projects in monorepo, 1 project with changes.

📊 Quick Summary
Project Total Size Gzip Size Change Gzip Change
popular-libs 1.7 MB 529.6 KB 0 0
react-10k 5.4 MB 1.3 MB 0 0
react-1k 827.7 KB 226.6 KB 0 0
react-5k 2.6 MB 670.9 KB 0 0
ui-components 4.7 MB 1.4 MB -3.0 B (-0.0%) -6.0 B (-0.0%)
📋 Detailed Reports (Click to expand)

📁 ui-components

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

📌 Baseline Commit: 927dac9621e56841cd438e566915fae24a2824d7 | PR: #16014

Metric Current Baseline Change
📊 Total Size 4.7 MB 4.7 MB -3.0 B (-0.0%)
🗜️ Gzip Size 1.4 MB 1.4 MB -6.0 B (-0.0%)
📄 JavaScript 4.6 MB 4.6 MB -3.0 B (-0.0%)
🎨 CSS 114.8 KB 114.8 KB 0
🌐 HTML 328.0 B 328.0 B 0
📁 Other Assets 0 B 0 B 0

📦 Download Diff Report: ui-components Bundle Diff

🤖 AI Degradation Analysis (Click to expand)

📊 Size Changes

No significant regressions detected 🎉. Total bundle size decreased slightly (-3 bytes).

🔍 Root Cause Analysis

  • New Dependencies: Added multiple modules from @ant-design/[email protected] (e.g., AntdIcon.js, IconBase.js, various icon definitions).
  • Offsetting Removals: Despite new icon modules (e.g., AntdIcon.js source 5,748 bytes), total JS size remained stable (4,831,551 bytes), indicating effective tree-shaking or concurrent code removal.

⚠️ Risk Assessment

Overall severity: Low

  • Initial chunk size is effectively unchanged (4,831,551 bytes vs 4,831,554 bytes baseline), ensuring no impact on initial load performance.

💡 Optimization Suggestions

  1. Verify icon imports use named exports (e.g., import { CheckOutlined } from '@ant-design/icons-vue') to maintain tree-shaking efficiency.
  2. Monitor future PRs for cumulative icon additions that could bypass shaking logic.
  3. Consider SVG sprites if the icon count grows significantly beyond current usage.

Analysis by qwen3.5-plus

Generated by Rsdoctor GitHub Action

@codspeed

codspeed Bot commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 54 untouched benchmarks
⏩ 47 skipped benchmarks1


Comparing seal/fix-defer-import-hmr (16d1901) with main (927dac9)

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. ↩

@LingyuCoder
LingyuCoder enabled auto-merge (squash) October 9, 2026 03:34

@stormslowly stormslowly left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

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.

[Bug]: deferImport experiment breaks first page served by dev server when combined with hot reloading & lazy compilation

2 participants