Skip to content

feat(react-webpack): route lepus chunks through standard pipeline for slardar sourcemaps#2310

Closed
Yradex wants to merge 4 commits intolynx-family:mainfrom
Yradex:mtf-runtime-slardar
Closed

feat(react-webpack): route lepus chunks through standard pipeline for slardar sourcemaps#2310
Yradex wants to merge 4 commits intolynx-family:mainfrom
Yradex:mtf-runtime-slardar

Conversation

@Yradex
Copy link
Copy Markdown
Collaborator

@Yradex Yradex commented Mar 5, 2026

Summary by CodeRabbit

  • New Features

    • Implemented dynamic worklet runtime chunk compilation and injection with sourcemap support.
    • Added automatic worklet usage detection during the build process.
  • Bug Fixes

    • Fixed runtime exclusion patterns to correctly handle dynamically compiled chunks instead of hardcoded configurations.
    • Ensured generated worklet runtime assets are properly cleaned up after processing.
  • Tests

    • Added test coverage for worklet runtime injection and asset compilation behavior.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).
  • Changeset added, and when a BREAKING CHANGE occurs, it needs to be clearly marked (or not required).

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 5, 2026

🦋 Changeset detected

Latest commit: c466718

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 3 packages
Name Type
@lynx-js/react-rsbuild-plugin Patch
@lynx-js/react-webpack-plugin Patch
@lynx-js/react-alias-rsbuild-plugin Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Mar 5, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 31f7d056-4e36-4007-ab14-cb2a611c20c1

📥 Commits

Reviewing files that changed from the base of the PR and between a40215b and c466718.

📒 Files selected for processing (2)
  • .changeset/green-tips-bake.md
  • .changeset/silent-cars-trade.md

📝 Walkthrough

Walkthrough

This PR refactors worklet runtime injection in the React webpack plugin by introducing a Lepus chunk pipeline infrastructure. It replaces single hardcoded worklet-runtime handling with dynamic per-chunk compilation and injection, adds worklet usage detection in loaders, and updates runtime wrapper patterns to accommodate multiple Lepus chunks.

Changes

Cohort / File(s) Summary
Runtime Path Resolution & Pattern Generation
packages/rspeedy/plugin-react/src/entry.ts, packages/rspeedy/plugin-react/test/config.test.ts
Dynamic resolution of worklet runtime path and generation of runtime wrapper test pattern from lepusChunkNames; replaces hardcoded main-thread.js exclusion with configurable pattern.
Lepus Chunk Pipeline Infrastructure
packages/webpack/react-webpack-plugin/src/lepusChunkPipeline.ts
New module providing Lepus chunk pipeline management: conditional chunk registration, entry injection via compilation hooks, template exclusion, asset validation, isolation wrapper generation, and public API exports.
Worklet Usage Tracking
packages/webpack/react-webpack-plugin/src/workletMetadata.ts, packages/webpack/react-webpack-plugin/src/loaders/background.ts, packages/webpack/react-webpack-plugin/src/loaders/main-thread.ts
New worklet metadata module for detecting and persisting worklet usage; loaders now call detectWorkletUsage and setModuleWorkletUsage after transformation.
Plugin Integration
packages/webpack/react-webpack-plugin/src/ReactWebpackPlugin.ts
Integrates lepusChunkPipeline into plugin initialization; replaces single worklet-runtime injection with per-chunk injection during beforeEncode hook; adds post-processAssets cleanup hook for generated Lepus chunk assets.
Test Cases & Configuration
packages/webpack/react-webpack-plugin/test/cases/worklet-runtime/not-using/index.js, packages/webpack/react-webpack-plugin/test/cases/worklet-runtime/standard-path/*
New test suite validating worklet-runtime injection behavior, including source maps, asset cleanup when unused, and injection content verification.
Documentation
.changeset/green-tips-bake.md, .changeset/silent-cars-trade.md
Changeset entries documenting runtime-wrapper exclusion logic updates and Lepus chunk pipeline routing through standard compilation pipeline.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • colinaaa
  • upupming
  • luhc228

Poem

🐰 Lepus chunks dance in the webpack stream,
Per-chunk injection is our dream—
No more hardcoded paths so tight,
Dynamic pipelines shine so bright!
Worklet metadata takes its place,
Runtime wrappers find their grace!

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of the PR: routing lepus chunks through the standard webpack pipeline to enable slardar sourcemaps support.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 5, 2026

Codecov Report

❌ Patch coverage is 86.90476% with 33 lines in your changes missing coverage. Please review.
✅ All tests successful. No failed tests found.

Files with missing lines Patch % Lines
...ack/react-webpack-plugin/src/lepusChunkPipeline.ts 90.85% 15 Missing ⚠️
...ebpack/react-webpack-plugin/src/workletMetadata.ts 29.41% 12 Missing ⚠️
...ack/react-webpack-plugin/src/loaders/background.ts 0.00% 3 Missing ⚠️
...ck/react-webpack-plugin/src/loaders/main-thread.ts 0.00% 3 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codspeed-hq
Copy link
Copy Markdown

codspeed-hq bot commented Mar 5, 2026

Merging this PR will degrade performance by 7.61%

❌ 1 regressed benchmark
✅ 71 untouched benchmarks
🆕 1 new benchmark
⏩ 3 skipped benchmarks1

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

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 static/js/worklet-runtime.js_LoadScript N/A 129.5 µs N/A
transform 1000 view elements 43.6 ms 47.2 ms -7.61%

Comparing Yradex:mtf-runtime-slardar (c466718) with main (4daa4d9)

Open in CodSpeed

Footnotes

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

@relativeci
Copy link
Copy Markdown

relativeci bot commented Mar 5, 2026

Web Explorer

#8046 Bundle Size — 384.5KiB (0%).

c466718(current) vs 4daa4d9 main#8021(baseline)

Bundle metrics  Change 1 change
                 Current
#8046
     Baseline
#8021
No change  Initial JS 155.59KiB 155.59KiB
No change  Initial CSS 35.1KiB 35.1KiB
No change  Cache Invalidation 0% 0%
No change  Chunks 8 8
No change  Assets 8 8
Change  Modules 238(-0.42%) 239
No change  Duplicate Modules 16 16
No change  Duplicate Code 2.98% 2.98%
No change  Packages 4 4
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#8046
     Baseline
#8021
No change  JS 253.55KiB 253.55KiB
No change  Other 95.85KiB 95.85KiB
No change  CSS 35.1KiB 35.1KiB

Bundle analysis reportBranch Yradex:mtf-runtime-slardarProject dashboard


Generated by RelativeCIDocumentationReport issue

@Yradex Yradex force-pushed the mtf-runtime-slardar branch from 0b7f81d to b5249a5 Compare March 5, 2026 13:29
@Yradex Yradex marked this pull request as ready for review March 6, 2026 02:43
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: b5249a58fa

ℹ️ 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".

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

🧹 Nitpick comments (1)
packages/rspeedy/plugin-react/test/config.test.ts (1)

2448-2450: Make this test follow the dynamic lepus chunk list.

The implementation now excludes by lepus chunk names, but this test still only exercises the current worklet-runtime singleton. If another lepus chunk is added, the wrapper regex can regress without the test noticing.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/rspeedy/plugin-react/test/config.test.ts` around lines 2448 - 2450,
The test currently hardcodes the 'worklet-runtime' chunk; modify it to iterate
over the dynamic lepus chunk list used by the implementation (import the lepus
chunk names constant or function used by the module under test) and for each
chunk name assert that testRule.test(`static/js/${chunk}.js`) and
testRule.test(`static/js/${chunk}.<hash>.js`) both return false; update the
assertions referencing testRule.test and the existing string patterns so the
test covers every lepus chunk rather than just 'worklet-runtime'.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Inline comments:
In `@packages/webpack/react-webpack-plugin/src/lepusChunkPipeline.ts`:
- Around line 57-82: The current code builds queuedChunks from the ephemeral
requestedChunkNames populated in succeedModule, which misses unchanged modules
on incremental rebuilds; instead, inside compilation.hooks.finishModules (the
finishModules callback) iterate over the full module set provided there and for
each item in lepusChunkPipeline call shouldCompile(module) against those modules
to decide inclusion—populate queuedChunks/queuedChunkByName from that pass (or
compute a Set of present module identifiers and test each LepusChunkPipelineItem
against that Set) so worklet-runtime and other persistent dependencies are
preserved across incremental compilations.

In
`@packages/webpack/react-webpack-plugin/test/cases/worklet-runtime/standard-path/index.js`:
- Around line 44-47: The test's assertion is too permissive because the fallback
injected.includes('function __webpack_require__(') allows unwrapped bundles to
pass; update the assertion in the test so it requires the isolated IIFE wrapper
produced by createIsolatedLepusChunkSource() (check the injected string only for
an IIFE start, e.g. use a strict startsWith('(function(') or a regex like
/^\(function\s*\(/) and remove the fallback includes(...) branch so the test
fails if the IIFE wrapper is not present.

---

Nitpick comments:
In `@packages/rspeedy/plugin-react/test/config.test.ts`:
- Around line 2448-2450: The test currently hardcodes the 'worklet-runtime'
chunk; modify it to iterate over the dynamic lepus chunk list used by the
implementation (import the lepus chunk names constant or function used by the
module under test) and for each chunk name assert that
testRule.test(`static/js/${chunk}.js`) and
testRule.test(`static/js/${chunk}.<hash>.js`) both return false; update the
assertions referencing testRule.test and the existing string patterns so the
test covers every lepus chunk rather than just 'worklet-runtime'.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 09af0b72-7f23-479d-b73e-637bf344c743

📥 Commits

Reviewing files that changed from the base of the PR and between 7518b72 and b5249a5.

📒 Files selected for processing (13)
  • .changeset/sweet-rings-kneel.md
  • packages/rspeedy/plugin-react/src/entry.ts
  • packages/rspeedy/plugin-react/test/config.test.ts
  • packages/webpack/react-webpack-plugin/src/ReactWebpackPlugin.ts
  • packages/webpack/react-webpack-plugin/src/lepusChunkPipeline.ts
  • packages/webpack/react-webpack-plugin/src/loaders/background.ts
  • packages/webpack/react-webpack-plugin/src/loaders/main-thread.ts
  • packages/webpack/react-webpack-plugin/src/workletMetadata.ts
  • packages/webpack/react-webpack-plugin/test/cases/worklet-runtime/not-using/index.js
  • packages/webpack/react-webpack-plugin/test/cases/worklet-runtime/standard-path/a.jsx
  • packages/webpack/react-webpack-plugin/test/cases/worklet-runtime/standard-path/index.js
  • packages/webpack/react-webpack-plugin/test/cases/worklet-runtime/standard-path/rspack.config.js
  • packages/webpack/react-webpack-plugin/test/cases/worklet-runtime/standard-path/test.config.cjs

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
packages/webpack/react-webpack-plugin/src/lepusChunkPipeline.ts (1)

216-222: Function-based entry configurations are not currently used in the codebase.

The hasEntry function only checks the object form of webpack's entry configuration. While webpack does support function entries that return configurations dynamically (e.g., entry: () => ({ 'worklet-runtime': './src/worklet.js' })), a search of the repository found no use of function-based entry configurations—all entries are object-based (e.g., entry: { main: '...' } or entry: Object.fromEntries(...)).

The theoretical risk of returning false for function-based entries remains valid if someone adds such a configuration in the future, but this is not an issue affecting the current codebase.

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@packages/webpack/react-webpack-plugin/src/lepusChunkPipeline.ts` around lines
216 - 222, The hasEntry helper currently only handles object entries and will
miss function-based entries; update hasEntry(compiler: Compiler, name: string)
to support function entries by detecting if compiler.options.entry is a
function, invoking it (awaiting if it returns a Promise) to obtain the resolved
entry object, then perform the same object-type check and "name in entry"
lookup; this will require changing hasEntry to an async function and callers to
await its result (or adapt call sites accordingly) so function-returning webpack
entries are correctly recognized.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@packages/webpack/react-webpack-plugin/src/lepusChunkPipeline.ts`:
- Around line 216-222: The hasEntry helper currently only handles object entries
and will miss function-based entries; update hasEntry(compiler: Compiler, name:
string) to support function entries by detecting if compiler.options.entry is a
function, invoking it (awaiting if it returns a Promise) to obtain the resolved
entry object, then perform the same object-type check and "name in entry"
lookup; this will require changing hasEntry to an async function and callers to
await its result (or adapt call sites accordingly) so function-returning webpack
entries are correctly recognized.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 429996eb-ed93-43f9-8074-4ba628560b3a

📥 Commits

Reviewing files that changed from the base of the PR and between b5249a5 and a40215b.

📒 Files selected for processing (2)
  • packages/webpack/react-webpack-plugin/src/lepusChunkPipeline.ts
  • packages/webpack/react-webpack-plugin/test/cases/worklet-runtime/standard-path/index.js
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/webpack/react-webpack-plugin/test/cases/worklet-runtime/standard-path/index.js

@Yradex
Copy link
Copy Markdown
Collaborator Author

Yradex commented Mar 6, 2026

@colinaaa Take a look?

@Yradex Yradex closed this Mar 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants