Skip to content

Conversation

@upupming
Copy link
Collaborator

@upupming upupming commented Aug 27, 2025

Fix lazy bundle regression introduced by #1370

Summary by CodeRabbit

  • Bug Fixes
    • Prevented incorrect cache-events flag injection into lazy-loaded bundles.
    • Minitialized runtime wiring to run via app startup and skipped attaching cache-events logic for main-thread-only chunks to avoid unintended side effects.
  • Tests
    • Added tests for lazy-bundle scenarios to verify the cache-events flag is absent when not enabled.
  • Chores
    • Prepared a patch release for the cache-events Webpack plugin.

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

@upupming upupming requested a review from colinaaa as a code owner August 27, 2025 11:45
@changeset-bot
Copy link

changeset-bot bot commented Aug 27, 2025

🦋 Changeset detected

Latest commit: fc77a8f

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

This PR includes changesets to release 4 packages
Name Type
@lynx-js/cache-events-webpack-plugin Patch
@lynx-js/rspeedy Patch
create-rspeedy Patch
upgrade-rspeedy 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
Contributor

coderabbitai bot commented Aug 27, 2025

📝 Walkthrough

Walkthrough

Prepares a patch changeset and updates the cache-events webpack plugin and runtime to wire startup via RuntimeGlobals.startup, skip injecting __webpack_require__.lynx_ce into lazy / __main-thread chunks, and adds a test case and configs for a non-cache-events lazy-bundle scenario.

Changes

Cohort / File(s) Summary of changes
Changeset
.changeset/loose-pens-flow.md
Adds a patch changeset for @lynx-js/cache-events-webpack-plugin describing a bugfix preventing __webpack_require__.lynx_ce from being injected for lazy bundles.
Plugin wiring & chunk guards
packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsPlugin.ts
Stop registering runtime requirement handlers for RuntimeGlobals.ensureChunk / ensureChunkIncludeEntries; add guards to skip attaching LynxCacheEventsSetupListRuntimeModule and LynxCacheEventsRuntimeModule for chunks whose names include __main-thread.
Runtime startup wiring
packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsRuntimeModule.ts
Rewire initialization to use RuntimeGlobals.startup as the startup chain (assign next from RuntimeGlobals.startup and wrap it so onLoaded runs via .finally), preserving cleanup, cachedActions, and loaded state logic.
Tests: not-cache-events lazy bundle
packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/*
Add test case and supporting files verifying __webpack_require__['lynx_ce'] is falsy for a lazy bundle: index.js, lazy-component.js, rspack.config.js, and test.config.cjs (includes mocked async module loader).

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • upupming
  • gaoachao
  • colinaaa

Poem

I hop through chunks at startup’s tune,
No sly flags on lazy loads this noon.
Main-thread fenced, tidy and bright,
Tests nibble bugs till morning light.
Carrot commit — a hopping delight! 🥕


📜 Recent review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 0bb216c and fc77a8f.

📒 Files selected for processing (7)
  • .changeset/loose-pens-flow.md (1 hunks)
  • packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsPlugin.ts (2 hunks)
  • packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsRuntimeModule.ts (1 hunks)
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/index.js (1 hunks)
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/lazy-component.js (1 hunks)
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/rspack.config.js (1 hunks)
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/test.config.cjs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • .changeset/loose-pens-flow.md
  • packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsPlugin.ts
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/index.js
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/test.config.cjs
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/lazy-component.js
  • packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsRuntimeModule.ts
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/rspack.config.js
✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbit in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbit in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbit gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbit read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbit help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbit ignore or @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbit summary or @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbit or @coderabbitai anywhere in the PR title to generate the title automatically.

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@codecov
Copy link

codecov bot commented Aug 27, 2025

Codecov Report

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

Files with missing lines Patch % Lines
...events-webpack-plugin/src/LynxCacheEventsPlugin.ts 33.33% 4 Missing ⚠️

📢 Thoughts on this report? Let us know!

Copy link
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: 3

🧹 Nitpick comments (6)
packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsRuntimeModule.ts (1)

36-39: Wrap startup to preserve args/this and handle sync returns

Avoid assuming startup returns a Promise and preserve call context/args to prevent subtle breakages across runtimes.

Please confirm RuntimeGlobals.startup is available in all webpack versions we target.

-var next = ${RuntimeGlobals.startup};
-${RuntimeGlobals.startup} = () => {
-  return next().finally(onLoaded);
-}
+var prevStartup = ${RuntimeGlobals.startup};
+${RuntimeGlobals.startup} = function (...args) {
+  const res = prevStartup && prevStartup.apply(this, args);
+  return Promise.resolve(res).finally(onLoaded);
+};
.changeset/loose-pens-flow.md (1)

5-5: Polish wording for the changeset entry

Rephrase for clarity.

-Fix that `__webpack_require__.lynx_ce` is incorrectly injected when lazy bundle is enabled.
+Fix incorrect injection of `__webpack_require__.lynx_ce` when lazy bundle is enabled.
packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsPlugin.ts (3)

163-166: DRY the main-thread guard and centralize the predicate.

The same string check appears twice. Factor it to a helper to improve readability and avoid typos if the token changes.

Apply within these ranges:

-        if (chunk.name?.includes('__main-thread')) {
+        if (isMainThreadChunk(chunk)) {
           return;
         }
-        if (chunk.name?.includes('__main-thread')) {
+        if (isMainThreadChunk(chunk)) {
           return;
         }

Add this near the top of the thisCompilation tap (outside the selected ranges):

// helper: colocate with other local utilities inside thisCompilation
const isMainThreadChunk = (chunk: Chunk): boolean =>
  chunk.name?.includes('__main-thread') === true;

Also applies to: 183-186


137-141: Remove unused WeakSet for lynxAsyncChunkIds.

The entry for lynxAsyncChunkIds is declared but never referenced. Trim to reduce mental overhead.

-      const onceForChunkSet = {
-        [LynxRuntimeGlobals.lynxAsyncChunkIds]: new WeakSet<Chunk>(),
-        [LynxRuntimeGlobals.lynxCacheEvents]: new WeakSet<Chunk>(),
-        [LynxRuntimeGlobals.lynxCacheEventsSetupList]: new WeakSet<Chunk>(),
-      };
+      const onceForChunkSet = {
+        [LynxRuntimeGlobals.lynxCacheEvents]: new WeakSet<Chunk>(),
+        [LynxRuntimeGlobals.lynxCacheEventsSetupList]: new WeakSet<Chunk>(),
+      };

119-136: Avoid adding runtime requirements for main-thread chunks at source.

You already guard when adding runtime modules; extend the predicate to handler so we don’t populate runtimeRequirements for chunks we’ll ignore anyway. Keeps the requirement graph cleaner.

       const handler = (chunk: Chunk, runtimeRequirements: Set<string>) => {
         const globalChunkLoading = compilation.outputOptions.chunkLoading;
         const isEnabledForChunk = (chunk: Chunk): boolean => {
           const options = chunk.getEntryOptions();
           const chunkLoading = options && options.chunkLoading !== undefined
             ? options.chunkLoading
             : globalChunkLoading;
-          return chunkLoading === LynxCacheEventsPluginImpl.chunkLoadingValue;
+          return (
+            chunkLoading === LynxCacheEventsPluginImpl.chunkLoadingValue &&
+            !isMainThreadChunk(chunk)
+          );
         };
         if (!isEnabledForChunk(chunk)) return;
         runtimeRequirements.add(LynxRuntimeGlobals.lynxCacheEventsSetupList);
         runtimeRequirements.add(LynxRuntimeGlobals.lynxCacheEvents);
       };
packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/test.config.cjs (1)

11-31: Make lazy load truly async and align chunk/module identifiers.

Fire the callback on a microtask to better emulate async chunk loading, and align ids with the provided module key for consistency.

-      requireModuleAsync: (_request, callback) => {
-        callback(null, {
-          ids: ['0'],
-          modules: {
+      requireModuleAsync: (_request, callback) => {
+        queueMicrotask(() => {
+          callback(null, {
+            ids: [1],
+            modules: {
                 __unused_webpack___webpack_module__,
                 __webpack_exports__,
                 __webpack_require__,
               ) {
                 __webpack_require__.d(__webpack_exports__, {
                   default: () => __WEBPACK_DEFAULT_EXPORT__,
                 });
-              /* ESM default export */ const __WEBPACK_DEFAULT_EXPORT__ =
-                (LazyComponent = () => {
-                  return null;
-                });
+                /* ESM default export */ const __WEBPACK_DEFAULT_EXPORT__ = () => null;
               },
-          },
-        });
+            },
+          });
+        });
       },
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 3c4172e and 7436ea4.

📒 Files selected for processing (7)
  • .changeset/loose-pens-flow.md (1 hunks)
  • packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsPlugin.ts (2 hunks)
  • packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsRuntimeModule.ts (1 hunks)
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/index.js (1 hunks)
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/lazy-component.js (1 hunks)
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/rspack.config.js (1 hunks)
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/test.config.cjs (1 hunks)
🧰 Additional context used
🧠 Learnings (12)
📓 Common learnings
Learnt from: colinaaa
PR: lynx-family/lynx-stack#1454
File: pnpm-workspace.yaml:46-46
Timestamp: 2025-08-07T04:00:59.645Z
Learning: In the lynx-family/lynx-stack repository, the webpack patch (patches/webpack5.101.0.patch) was created to fix issues with webpack5.99.9 but only takes effect on webpack5.100.0 and later versions. The patchedDependencies entry should use "webpack@^5.100.0" to ensure the patch applies to the correct version range.
Learnt from: upupming
PR: lynx-family/lynx-stack#1370
File: packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsRuntimeModule.ts:23-27
Timestamp: 2025-08-21T08:46:54.456Z
Learning: In Lynx webpack runtime modules, the team prioritizes performance and simplicity over defensive runtime error handling. They prefer relying on compile-time type safety (TypeScript) rather than adding runtime checks like try-catch blocks or type validation, especially for performance-critical code like cache event setup/cleanup functions.
Learnt from: upupming
PR: lynx-family/lynx-stack#1370
File: packages/rspeedy/plugin-react/src/entry.ts:237-240
Timestamp: 2025-08-12T09:32:01.512Z
Learning: The events-cache.js functionality for caching events until background threads are ready is manually tested due to the complexity of constructing automated runtime test cases that involve timing, chunk loading, and browser runtime behavior.
Learnt from: upupming
PR: lynx-family/lynx-stack#1370
File: packages/webpack/template-webpack-plugin/src/LynxCacheEventsSetupListRuntimeModule.ts:21-25
Timestamp: 2025-08-19T12:49:05.875Z
Learning: In the Lynx cache events system, there are two separate runtime modules with distinct responsibilities: `LynxCacheEventsSetupListRuntimeModule` is only responsible for initializing the setup list with the setup functions, while `LynxCacheEventsRuntimeModule` guarantees the initialization of `loaded` and `cachedActions` properties. The modules have a dependency relationship where `lynxCacheEventsSetupList` is required by `lynxCacheEvents`.
📚 Learning: 2025-08-06T13:28:57.182Z
Learnt from: colinaaa
PR: lynx-family/lynx-stack#1453
File: vitest.config.ts:49-61
Timestamp: 2025-08-06T13:28:57.182Z
Learning: In the lynx-family/lynx-stack repository, the file `packages/rspeedy/create-rspeedy/template-react-vitest-rltl-js/vitest.config.js` is a template file for scaffolding new Rspeedy projects, not a test configuration that should be included in the main vitest projects array.

Applied to files:

  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/rspack.config.js
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/test.config.cjs
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/index.js
📚 Learning: 2025-08-06T13:28:57.182Z
Learnt from: colinaaa
PR: lynx-family/lynx-stack#1453
File: vitest.config.ts:49-61
Timestamp: 2025-08-06T13:28:57.182Z
Learning: In the lynx-family/lynx-stack repository, the file `packages/react/testing-library/src/vitest.config.js` is source code for the testing library that gets exported for users, not a test configuration that should be included in the main vitest projects array.

Applied to files:

  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/rspack.config.js
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/test.config.cjs
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/index.js
📚 Learning: 2025-08-21T08:46:54.456Z
Learnt from: upupming
PR: lynx-family/lynx-stack#1370
File: packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsRuntimeModule.ts:23-27
Timestamp: 2025-08-21T08:46:54.456Z
Learning: In Lynx webpack runtime modules, the team prioritizes performance and simplicity over defensive runtime error handling. They prefer relying on compile-time type safety (TypeScript) rather than adding runtime checks like try-catch blocks or type validation, especially for performance-critical code like cache event setup/cleanup functions.

Applied to files:

  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/rspack.config.js
  • packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsPlugin.ts
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/test.config.cjs
  • .changeset/loose-pens-flow.md
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/index.js
  • packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsRuntimeModule.ts
📚 Learning: 2025-08-19T12:49:05.875Z
Learnt from: upupming
PR: lynx-family/lynx-stack#1370
File: packages/webpack/template-webpack-plugin/src/LynxCacheEventsSetupListRuntimeModule.ts:21-25
Timestamp: 2025-08-19T12:49:05.875Z
Learning: In the Lynx cache events system, there are two separate runtime modules with distinct responsibilities: `LynxCacheEventsSetupListRuntimeModule` is only responsible for initializing the setup list with the setup functions, while `LynxCacheEventsRuntimeModule` guarantees the initialization of `loaded` and `cachedActions` properties. The modules have a dependency relationship where `lynxCacheEventsSetupList` is required by `lynxCacheEvents`.

Applied to files:

  • packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsPlugin.ts
  • packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsRuntimeModule.ts
📚 Learning: 2025-08-12T09:32:01.512Z
Learnt from: upupming
PR: lynx-family/lynx-stack#1370
File: packages/rspeedy/plugin-react/src/entry.ts:237-240
Timestamp: 2025-08-12T09:32:01.512Z
Learning: The events-cache.js functionality for caching events until background threads are ready is manually tested due to the complexity of constructing automated runtime test cases that involve timing, chunk loading, and browser runtime behavior.

Applied to files:

  • packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsPlugin.ts
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/test.config.cjs
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/index.js
📚 Learning: 2025-07-22T09:26:16.722Z
Learnt from: colinaaa
PR: lynx-family/lynx-stack#1330
File: .changeset/olive-animals-attend.md:1-3
Timestamp: 2025-07-22T09:26:16.722Z
Learning: In the lynx-family/lynx-stack repository, CI checks require changesets when files matching the pattern "src/**" are modified (as configured in .changeset/config.json). For internal changes that don't need meaningful changesets, an empty changeset file is used to satisfy the CI requirement while not generating any release notes.

Applied to files:

  • .changeset/loose-pens-flow.md
📚 Learning: 2025-07-22T09:23:07.797Z
Learnt from: colinaaa
PR: lynx-family/lynx-stack#1330
File: .changeset/olive-animals-attend.md:1-3
Timestamp: 2025-07-22T09:23:07.797Z
Learning: In the lynx-family/lynx-stack repository, changesets are only required for meaningful changes to end-users such as bugfixes and features. Internal/development changes like chores, refactoring, or removing debug info do not need changeset entries.

Applied to files:

  • .changeset/loose-pens-flow.md
📚 Learning: 2025-08-07T04:00:59.645Z
Learnt from: colinaaa
PR: lynx-family/lynx-stack#1454
File: pnpm-workspace.yaml:46-46
Timestamp: 2025-08-07T04:00:59.645Z
Learning: In the lynx-family/lynx-stack repository, the webpack patch (patches/webpack5.101.0.patch) was created to fix issues with webpack5.99.9 but only takes effect on webpack5.100.0 and later versions. The patchedDependencies entry should use "webpack@^5.100.0" to ensure the patch applies to the correct version range.

Applied to files:

  • .changeset/loose-pens-flow.md
📚 Learning: 2025-08-19T11:25:36.127Z
Learnt from: colinaaa
PR: lynx-family/lynx-stack#1558
File: .changeset/solid-squids-fall.md:2-2
Timestamp: 2025-08-19T11:25:36.127Z
Learning: In the lynx-family/lynx-stack repository, changesets should use the exact package name from package.json#name, not generic or unscoped names. Each package has its own specific scoped name (e.g., "lynx-js/react-transform" for packages/react/transform).

Applied to files:

  • .changeset/loose-pens-flow.md
📚 Learning: 2025-08-11T05:59:28.530Z
Learnt from: upupming
PR: lynx-family/lynx-stack#1305
File: packages/react/testing-library/src/plugins/vitest.ts:4-6
Timestamp: 2025-08-11T05:59:28.530Z
Learning: In the lynx-family/lynx-stack repository, the `packages/react/testing-library` package does not have `vite` as a direct dependency. It relies on `vitest` being available from the monorepo root and accesses Vite types through re-exports from `vitest/node`. Direct imports from `vite` should not be suggested for this package.

Applied to files:

  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/index.js
📚 Learning: 2025-08-12T16:09:32.413Z
Learnt from: colinaaa
PR: lynx-family/lynx-stack#1497
File: packages/react/transform/tests/__swc_snapshots__/src/swc_plugin_snapshot/mod.rs/basic_full_static.js:9-10
Timestamp: 2025-08-12T16:09:32.413Z
Learning: In the Lynx stack, functions prefixed with `__` that are called in transformed code may be injected globally by the Lynx Engine at runtime rather than exported from the React runtime package. For example, `__CreateFrame` is injected globally by the Lynx Engine, not exported from lynx-js/react.

Applied to files:

  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/index.js
🧬 Code graph analysis (4)
packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/rspack.config.js (1)
packages/webpack/chunk-loading-webpack-plugin/src/index.ts (1)
  • ChunkLoadingWebpackPlugin (58-87)
packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/test.config.cjs (1)
packages/react/testing-library/src/__tests__/lazy-bundle/LazyComponent.jsx (1)
  • LazyComponent (1-4)
packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/lazy-component.js (1)
packages/react/testing-library/src/__tests__/lazy-bundle/LazyComponent.jsx (1)
  • LazyComponent (1-4)
packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsRuntimeModule.ts (1)
packages/webpack/webpack-runtime-globals/src/RuntimeGlobals.ts (1)
  • RuntimeGlobals (10-34)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: build / Build (Windows)
  • GitHub Check: build / Build (Ubuntu)
  • GitHub Check: test-rust / Test (Ubuntu)
  • GitHub Check: CodeQL Analyze (javascript-typescript)
  • GitHub Check: CodeQL Analyze (actions)
  • GitHub Check: zizmor
🔇 Additional comments (1)
packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/rspack.config.js (1)

1-16: LGTM: correct plugin order and chunkLoading

Order (ChunkLoadingWebpackPlugin before LynxCacheEventsPlugin) and chunkLoading: 'lynx' look right for this case.

@relativeci
Copy link

relativeci bot commented Aug 27, 2025

Web Explorer

#4708 Bundle Size — 367.43KiB (0%).

fc77a8f(current) vs 00f6496 main#4707(baseline)

Bundle metrics  no changes
                 Current
#4708
     Baseline
#4707
No change  Initial JS 144.23KiB 144.23KiB
No change  Initial CSS 31.84KiB 31.84KiB
No change  Cache Invalidation 0% 0%
No change  Chunks 8 8
No change  Assets 8 8
No change  Modules 220 220
No change  Duplicate Modules 16 16
No change  Duplicate Code 3.32% 3.32%
No change  Packages 4 4
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#4708
     Baseline
#4707
No change  JS 235.43KiB 235.43KiB
No change  Other 100.16KiB 100.16KiB
No change  CSS 31.84KiB 31.84KiB

Bundle analysis reportBranch upupming:fix/not-cache-events-on...Project dashboard


Generated by RelativeCIDocumentationReport issue

@relativeci
Copy link

relativeci bot commented Aug 27, 2025

React Example

#4715 Bundle Size — 237.06KiB (0%).

fc77a8f(current) vs 00f6496 main#4714(baseline)

Bundle metrics  no changes
                 Current
#4715
     Baseline
#4714
No change  Initial JS 0B 0B
No change  Initial CSS 0B 0B
No change  Cache Invalidation 0% 0%
No change  Chunks 0 0
No change  Assets 4 4
No change  Modules 158 158
No change  Duplicate Modules 64 64
No change  Duplicate Code 45.83% 45.83%
No change  Packages 2 2
No change  Duplicate Packages 0 0
Bundle size by type  no changes
                 Current
#4715
     Baseline
#4714
No change  IMG 145.76KiB 145.76KiB
No change  Other 91.3KiB 91.3KiB

Bundle analysis reportBranch upupming:fix/not-cache-events-on...Project dashboard


Generated by RelativeCIDocumentationReport issue

@codspeed-hq
Copy link

codspeed-hq bot commented Aug 27, 2025

CodSpeed Performance Report

Merging #1616 will not alter performance

Comparing upupming:fix/not-cache-events-on-lazy-bundle (fc77a8f) with main (00f6496)

🎉 Hooray! codspeed-cpp just leveled up to 1.2.0!

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.

Summary

✅ 19 untouched benchmarks

@hzy hzy force-pushed the fix/not-cache-events-on-lazy-bundle branch from 32bedc0 to 0bb216c Compare August 29, 2025 03:32
Copy link
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: 0

♻️ Duplicate comments (1)
packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/test.config.cjs (1)

23-24: Strict-mode hazard resolved in module factory.

Good fix replacing the undeclared assignment with an inline default export.

🧹 Nitpick comments (2)
packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/test.config.cjs (2)

12-27: Confirm ids element types; prefer numeric chunk ids.

If the consumer expects numeric chunk ids, ['0'] may be coerced incorrectly. Recommend using numbers to match typical Webpack chunk id shape.

-          ids: ['0'],
+          ids: [0],

6-30: Optional: simulate async boundary for requireModuleAsync.

If any callers assume true asynchrony, immediate callback invocation can mask ordering bugs. Consider deferring via microtask.

-      requireModuleAsync: (_request, callback) => {
-        callback(null, {
+      requireModuleAsync: (_request, callback) => {
+        queueMicrotask(() => callback(null, {
           ids: [0],
           modules: {
               __unused_webpack___webpack_module__,
               __webpack_exports__,
               __webpack_require__,
             ) {
               __webpack_require__.d(__webpack_exports__, {
                 default: () => __WEBPACK_DEFAULT_EXPORT__,
               });
               /* ESM default export */ const __WEBPACK_DEFAULT_EXPORT__ = () =>
                 null;
             },
           },
-        });
+        }));
       },
📜 Review details

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • MCP integration is disabled by default for public repositories
  • Jira integration is disabled by default for public repositories
  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 546e97e and 0bb216c.

📒 Files selected for processing (7)
  • .changeset/loose-pens-flow.md (1 hunks)
  • packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsPlugin.ts (2 hunks)
  • packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsRuntimeModule.ts (1 hunks)
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/index.js (1 hunks)
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/lazy-component.js (1 hunks)
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/rspack.config.js (1 hunks)
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/test.config.cjs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/lazy-component.js
  • .changeset/loose-pens-flow.md
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/index.js
  • packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsPlugin.ts
  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/rspack.config.js
🧰 Additional context used
🧠 Learnings (6)
📓 Common learnings
Learnt from: colinaaa
PR: lynx-family/lynx-stack#1454
File: pnpm-workspace.yaml:46-46
Timestamp: 2025-08-07T04:00:59.645Z
Learning: In the lynx-family/lynx-stack repository, the webpack patch (patches/webpack5.101.0.patch) was created to fix issues with webpack5.99.9 but only takes effect on webpack5.100.0 and later versions. The patchedDependencies entry should use "webpack@^5.100.0" to ensure the patch applies to the correct version range.
Learnt from: upupming
PR: lynx-family/lynx-stack#1616
File: packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/index.js:3-3
Timestamp: 2025-08-27T12:42:01.095Z
Learning: In webpack, properties like __webpack_require__.lynx_ce are injected during compilation/build time when webpack processes modules and generates bundles, not at runtime when dynamic imports execute. Tests for such properties don't need to wait for dynamic imports to complete.
Learnt from: upupming
PR: lynx-family/lynx-stack#1370
File: packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsRuntimeModule.ts:23-27
Timestamp: 2025-08-21T08:46:54.494Z
Learning: In Lynx webpack runtime modules, the team prioritizes performance and simplicity over defensive runtime error handling. They prefer relying on compile-time type safety (TypeScript) rather than adding runtime checks like try-catch blocks or type validation, especially for performance-critical code like cache event setup/cleanup functions.
Learnt from: upupming
PR: lynx-family/lynx-stack#1370
File: packages/rspeedy/plugin-react/src/entry.ts:237-240
Timestamp: 2025-08-12T09:32:01.512Z
Learning: The events-cache.js functionality for caching events until background threads are ready is manually tested due to the complexity of constructing automated runtime test cases that involve timing, chunk loading, and browser runtime behavior.
📚 Learning: 2025-08-06T13:28:57.182Z
Learnt from: colinaaa
PR: lynx-family/lynx-stack#1453
File: vitest.config.ts:49-61
Timestamp: 2025-08-06T13:28:57.182Z
Learning: In the lynx-family/lynx-stack repository, the file `packages/react/testing-library/src/vitest.config.js` is source code for the testing library that gets exported for users, not a test configuration that should be included in the main vitest projects array.

Applied to files:

  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/test.config.cjs
📚 Learning: 2025-08-06T13:28:57.182Z
Learnt from: colinaaa
PR: lynx-family/lynx-stack#1453
File: vitest.config.ts:49-61
Timestamp: 2025-08-06T13:28:57.182Z
Learning: In the lynx-family/lynx-stack repository, the file `packages/rspeedy/create-rspeedy/template-react-vitest-rltl-js/vitest.config.js` is a template file for scaffolding new Rspeedy projects, not a test configuration that should be included in the main vitest projects array.

Applied to files:

  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/test.config.cjs
📚 Learning: 2025-08-27T12:42:01.095Z
Learnt from: upupming
PR: lynx-family/lynx-stack#1616
File: packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/index.js:3-3
Timestamp: 2025-08-27T12:42:01.095Z
Learning: In webpack, properties like __webpack_require__.lynx_ce are injected during compilation/build time when webpack processes modules and generates bundles, not at runtime when dynamic imports execute. Tests for such properties don't need to wait for dynamic imports to complete.

Applied to files:

  • packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/test.config.cjs
  • packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsRuntimeModule.ts
📚 Learning: 2025-08-19T12:49:05.875Z
Learnt from: upupming
PR: lynx-family/lynx-stack#1370
File: packages/webpack/template-webpack-plugin/src/LynxCacheEventsSetupListRuntimeModule.ts:21-25
Timestamp: 2025-08-19T12:49:05.875Z
Learning: In the Lynx cache events system, there are two separate runtime modules with distinct responsibilities: `LynxCacheEventsSetupListRuntimeModule` is only responsible for initializing the setup list with the setup functions, while `LynxCacheEventsRuntimeModule` guarantees the initialization of `loaded` and `cachedActions` properties. The modules have a dependency relationship where `lynxCacheEventsSetupList` is required by `lynxCacheEvents`.

Applied to files:

  • packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsRuntimeModule.ts
📚 Learning: 2025-08-21T08:46:54.494Z
Learnt from: upupming
PR: lynx-family/lynx-stack#1370
File: packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsRuntimeModule.ts:23-27
Timestamp: 2025-08-21T08:46:54.494Z
Learning: In Lynx webpack runtime modules, the team prioritizes performance and simplicity over defensive runtime error handling. They prefer relying on compile-time type safety (TypeScript) rather than adding runtime checks like try-catch blocks or type validation, especially for performance-critical code like cache event setup/cleanup functions.

Applied to files:

  • packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsRuntimeModule.ts
🧬 Code graph analysis (1)
packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsRuntimeModule.ts (1)
packages/webpack/webpack-runtime-globals/src/RuntimeGlobals.ts (1)
  • RuntimeGlobals (10-34)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (6)
  • GitHub Check: build / Build (Ubuntu)
  • GitHub Check: build / Build (Windows)
  • GitHub Check: test-rust / Test (Ubuntu)
  • GitHub Check: zizmor
  • GitHub Check: CodeQL Analyze (javascript-typescript)
  • GitHub Check: CodeQL Analyze (actions)
🔇 Additional comments (1)
packages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsRuntimeModule.ts (1)

36-39: Harden startup wrapper – avoid next collision and non-Promise issues

Replace the existing wrapping

var next = ${RuntimeGlobals.startup};
${RuntimeGlobals.startup} = () => {
  return next().finally(onLoaded);
}

with a closure that captures the prior startup, guards against name collisions, and handles non-Promise returns:

-(function(prev){
-  ${RuntimeGlobals.startup} = function() {
-    var res = prev ? prev() : undefined;
-    if (res && typeof res.finally === 'function') {
-      return res.finally(onLoaded);
-    }
-    onLoaded();
-    return res;
-  };
-})(${RuntimeGlobals.startup});

Run the lazy-bundle and non-lazy-entry tests to confirm no regressions when startup() returns synchronously.

upupming and others added 5 commits August 29, 2025 14:42
…che-events/lazy-bundle/test.config.cjs

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Yiming Li <[email protected]>
…che-events/lazy-bundle/lazy-component.js

Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com>
Signed-off-by: Yiming Li <[email protected]>
@hzy hzy force-pushed the fix/not-cache-events-on-lazy-bundle branch from 0bb216c to fc77a8f Compare August 29, 2025 06:42
@upupming upupming requested review from Yradex, gaoachao and hzy August 29, 2025 10:49
@colinaaa colinaaa merged commit d7d0b9b into lynx-family:main Aug 30, 2025
42 of 45 checks passed
colinaaa pushed a commit that referenced this pull request Sep 1, 2025
This PR was opened by the [Changesets
release](https://github.com/changesets/action) GitHub action. When
you're ready to do a release, you can merge this and the packages will
be published to npm automatically. If you're not ready to do a release
yet, that's fine, whenever you add more changesets to main, this PR will
be updated.


# Releases
## @lynx-js/[email protected]

### Minor Changes

- Deprecate `source.alias`, use `resolve.alias` instead.
([#1610](#1610))

Note that `resolve.alias` has **lower** priority than the deprecated
`source.alias`.

- Bump Rsbuild v1.5.0 with Rspack v1.5.0.
([#1591](#1591))

- **BREAKING CHANGE**: Remove the `./register` exports from
`@lynx-js/rspeedy`.
([#1547](#1547))

    This should not affect most users.

### Patch Changes

- Support `resolve.alias`.
([#1610](#1610))

- Support `rspeedy build --watch`
([#1579](#1579))

- Updated dependencies
\[[`d7d0b9b`](d7d0b9b),
[`1952fc1`](1952fc1)]:
    -   @lynx-js/[email protected]
    -   @lynx-js/[email protected]

## @lynx-js/[email protected]

### Minor Changes

- refactor: provide the mts a real globalThis
([#1589](#1589))

Before this change, We create a function wrapper and a fake globalThis
for Javascript code.

    This caused some issues.

After this change, we will create an iframe for createing an isolated
Javascript context.

    This means the globalThis will be the real one.

### Patch Changes

- refactor: add `:not([l-e-name])` at the end of selector for lazy
component ([#1622](#1622))

- fix: the SystemInfo in bts should be assigned to the globalThis
([#1599](#1599))

- Updated dependencies
\[[`c1f8715`](c1f8715)]:
    -   @lynx-js/[email protected]

## @lynx-js/[email protected]

### Minor Changes

- refactor: provide the mts a real globalThis
([#1589](#1589))

Before this change, We create a function wrapper and a fake globalThis
for Javascript code.

    This caused some issues.

After this change, we will create an iframe for createing an isolated
Javascript context.

    This means the globalThis will be the real one.

### Patch Changes

- refactor: add `:not([l-e-name])` at the end of selector for lazy
component ([#1622](#1622))

- feat: remove multi-thread mts heating
([#1597](#1597))

The default rendering mode is "all-on-ui". Therefore the preheating for
"multi-thread" will be removed.

- fix: the SystemInfo in bts should be assigned to the globalThis
([#1599](#1599))

- Updated dependencies
\[[`1a32dd8`](1a32dd8),
[`bb53d9a`](bb53d9a),
[`1a32dd8`](1a32dd8),
[`c1f8715`](c1f8715)]:
    -   @lynx-js/[email protected]
    -   @lynx-js/[email protected]
    -   @lynx-js/[email protected]
    -   @lynx-js/[email protected]
    -   @lynx-js/[email protected]

## @lynx-js/[email protected]

### Minor Changes

- refactor: provide the mts a real globalThis
([#1589](#1589))

Before this change, We create a function wrapper and a fake globalThis
for Javascript code.

    This caused some issues.

After this change, we will create an iframe for createing an isolated
Javascript context.

    This means the globalThis will be the real one.

## @lynx-js/[email protected]

### Minor Changes

- refactor: provide the mts a real globalThis
([#1589](#1589))

Before this change, We create a function wrapper and a fake globalThis
for Javascript code.

    This caused some issues.

After this change, we will create an iframe for createing an isolated
Javascript context.

    This means the globalThis will be the real one.

### Patch Changes

- refactor: add `:not([l-e-name])` at the end of selector for lazy
component ([#1622](#1622))

- fix: the SystemInfo in bts should be assigned to the globalThis
([#1599](#1599))

- Updated dependencies
\[[`1a32dd8`](1a32dd8),
[`bb53d9a`](bb53d9a),
[`c1f8715`](c1f8715)]:
    -   @lynx-js/[email protected]
    -   @lynx-js/[email protected]

## @lynx-js/[email protected]

### Minor Changes

- refactor: provide the mts a real globalThis
([#1589](#1589))

Before this change, We create a function wrapper and a fake globalThis
for Javascript code.

    This caused some issues.

After this change, we will create an iframe for createing an isolated
Javascript context.

    This means the globalThis will be the real one.

## @lynx-js/[email protected]

### Minor Changes

- refactor: provide the mts a real globalThis
([#1589](#1589))

Before this change, We create a function wrapper and a fake globalThis
for Javascript code.

    This caused some issues.

After this change, we will create an iframe for createing an isolated
Javascript context.

    This means the globalThis will be the real one.

### Patch Changes

- fix: the SystemInfo in bts should be assigned to the globalThis
([#1599](#1599))

- Updated dependencies
\[[`1a32dd8`](1a32dd8),
[`bb53d9a`](bb53d9a),
[`1a32dd8`](1a32dd8),
[`c1f8715`](c1f8715)]:
    -   @lynx-js/[email protected]
    -   @lynx-js/[email protected]
    -   @lynx-js/[email protected]
    -   @lynx-js/[email protected]

## @lynx-js/[email protected]

### Patch Changes

- Remove the "key is not on root element of snapshot" warning.
([#1558](#1558))

## [email protected]

### Patch Changes

- Use TypeScript [Project
References](https://www.typescriptlang.org/docs/handbook/project-references.html)
in templates.
([#1612](#1612))

## @lynx-js/[email protected]

### Patch Changes

- remove innerHTML, replace it by textContent
([#1622](#1622))

## @lynx-js/[email protected]

### Patch Changes

- Fix that `__webpack_require__.lynx_ce` is incorrectly injected when
lazy bundle is enabled.
([#1616](#1616))

## @lynx-js/[email protected]

### Patch Changes

- Should not load initial CSS chunks.
([#1601](#1601))

## [email protected]



## @lynx-js/[email protected]

Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com>
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.

3 participants