-
Notifications
You must be signed in to change notification settings - Fork 111
fix: __webpack_require__.lynx_ce is incorrectly injected when lazy bundle is enabled
#1616
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: __webpack_require__.lynx_ce is incorrectly injected when lazy bundle is enabled
#1616
Conversation
🦋 Changeset detectedLatest commit: fc77a8f The changes in this PR will be included in the next version bump. This PR includes changesets to release 4 packages
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 |
📝 WalkthroughWalkthroughPrepares a patch changeset and updates the cache-events webpack plugin and runtime to wire startup via Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Suggested reviewers
Poem
📜 Recent review detailsConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro 💡 Knowledge Base configuration:
You can enable these sources in your CodeRabbit configuration. 📒 Files selected for processing (7)
🚧 Files skipped from review as they are similar to previous changes (7)
✨ Finishing Touches
🧪 Generate unit tests
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. 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
Status, Documentation and Community
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
There was a problem hiding this 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 returnsAvoid assuming
startupreturns a Promise and preserve call context/args to prevent subtle breakages across runtimes.Please confirm
RuntimeGlobals.startupis 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 entryRephrase 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
thisCompilationtap (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
lynxAsyncChunkIdsis 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
handlerso we don’t populateruntimeRequirementsfor 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
idswith 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.
📒 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.jspackages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/test.config.cjspackages/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.jspackages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/test.config.cjspackages/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.jspackages/webpack/cache-events-webpack-plugin/src/LynxCacheEventsPlugin.tspackages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/test.config.cjs.changeset/loose-pens-flow.mdpackages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/index.jspackages/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.tspackages/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.tspackages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/test.config.cjspackages/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 chunkLoadingOrder (
ChunkLoadingWebpackPluginbeforeLynxCacheEventsPlugin) andchunkLoading: 'lynx'look right for this case.
packages/webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/index.js
Show resolved
Hide resolved
...ebpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/lazy-component.js
Outdated
Show resolved
Hide resolved
.../webpack/cache-events-webpack-plugin/test/cases/not-cache-events/lazy-bundle/test.config.cjs
Outdated
Show resolved
Hide resolved
Web Explorer#4708 Bundle Size — 367.43KiB (0%).fc77a8f(current) vs 00f6496 main#4707(baseline) Bundle metrics
|
| Current #4708 |
Baseline #4707 |
|
|---|---|---|
144.23KiB |
144.23KiB |
|
31.84KiB |
31.84KiB |
|
0% |
0% |
|
8 |
8 |
|
8 |
8 |
|
220 |
220 |
|
16 |
16 |
|
3.32% |
3.32% |
|
4 |
4 |
|
0 |
0 |
Bundle size by type no changes
| Current #4708 |
Baseline #4707 |
|
|---|---|---|
235.43KiB |
235.43KiB |
|
100.16KiB |
100.16KiB |
|
31.84KiB |
31.84KiB |
Bundle analysis report Branch upupming:fix/not-cache-events-on... Project dashboard
Generated by RelativeCI Documentation Report issue
React Example#4715 Bundle Size — 237.06KiB (0%).fc77a8f(current) vs 00f6496 main#4714(baseline) Bundle metrics
|
| Current #4715 |
Baseline #4714 |
|
|---|---|---|
0B |
0B |
|
0B |
0B |
|
0% |
0% |
|
0 |
0 |
|
4 |
4 |
|
158 |
158 |
|
64 |
64 |
|
45.83% |
45.83% |
|
2 |
2 |
|
0 |
0 |
Bundle size by type no changes
| Current #4715 |
Baseline #4714 |
|
|---|---|---|
145.76KiB |
145.76KiB |
|
91.3KiB |
91.3KiB |
Bundle analysis report Branch upupming:fix/not-cache-events-on... Project dashboard
Generated by RelativeCI Documentation Report issue
CodSpeed Performance ReportMerging #1616 will not alter performanceComparing 🎉 Hooray!
|
32bedc0 to
0bb216c
Compare
There was a problem hiding this 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: Confirmidselement 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.
📒 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.cjspackages/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 – avoidnextcollision and non-Promise issuesReplace 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.
…bundle is enabled
…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]>
0bb216c to
fc77a8f
Compare
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>
Fix lazy bundle regression introduced by #1370
Summary by CodeRabbit
Checklist