-
Notifications
You must be signed in to change notification settings - Fork 122
fix: avoid injecting hot update runtime #1980
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| "@lynx-js/react-rsbuild-plugin": patch | ||
| --- | ||
|
|
||
| Avoid injecting hot update runtime when dev.hmr or dev.liveReload is set to false. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,6 +1,7 @@ | ||
| packages/web-platform/** @pupiltong | ||
| packages/webpack/** @colinaaa @upupming | ||
| packages/rspeedy/** @colinaaa @upupming | ||
| packages/rspeedy/plugin-react/** @upupming | ||
| packages/react/** @hzy @HuJean | ||
| packages/react/transform/** @gaoachao | ||
| benchmark/react/** @hzy @HuJean |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,153 @@ | ||
| // Copyright 2025 The Lynx Authors. All rights reserved. | ||
| // Licensed under the Apache License Version 2.0 that can be found in the | ||
| // LICENSE file in the root directory of this source tree. | ||
| import { describe, expect, test, vi } from 'vitest' | ||
|
|
||
| import { createStubRspeedy as createRspeedy } from './createRspeedy.js' | ||
|
|
||
| vi.stubEnv('USE_RSPACK', 'true').stubEnv('NODE_ENV', 'development') | ||
|
|
||
| describe('hot update', () => { | ||
| test('should prepend hot update runtime in development mode', async () => { | ||
| const { pluginReactLynx } = await import('../src/pluginReactLynx.js') | ||
| const rsbuild = await createRspeedy({ | ||
| rspeedyConfig: { | ||
| plugins: [ | ||
| pluginReactLynx(), | ||
| ], | ||
| }, | ||
| }) | ||
|
|
||
| const [config] = await rsbuild.initConfigs() | ||
| expect(config.entry).toMatchInlineSnapshot(` | ||
| { | ||
| "main": { | ||
| "filename": ".rspeedy/main/background.js", | ||
| "import": [ | ||
| "@lynx-js/webpack-dev-transport/client", | ||
| "@lynx-js/react/refresh", | ||
| "@rspack/core/hot/dev-server", | ||
| "./src/index.js", | ||
| ], | ||
|
coderabbitai[bot] marked this conversation as resolved.
|
||
| "layer": "react:background", | ||
| }, | ||
| "main__main-thread": { | ||
| "filename": ".rspeedy/main/main-thread.js", | ||
| "import": [ | ||
| "<WORKSPACE>/packages/webpack/css-extract-webpack-plugin/runtime/hotModuleReplacement.lepus.cjs", | ||
| "./src/index.js", | ||
| ], | ||
| "layer": "react:main-thread", | ||
| }, | ||
| } | ||
| `) | ||
| }) | ||
|
|
||
| test('should prepend hot update runtime when liveReload is set to false', async () => { | ||
| const { pluginReactLynx } = await import('../src/pluginReactLynx.js') | ||
| const rsbuild = await createRspeedy({ | ||
| rspeedyConfig: { | ||
| dev: { | ||
| liveReload: false, | ||
| }, | ||
| plugins: [ | ||
| pluginReactLynx(), | ||
| ], | ||
| }, | ||
| }) | ||
|
|
||
| const [config] = await rsbuild.initConfigs() | ||
| expect(config.entry).toMatchInlineSnapshot(` | ||
| { | ||
| "main": { | ||
| "filename": ".rspeedy/main/background.js", | ||
| "import": [ | ||
| "@lynx-js/webpack-dev-transport/client", | ||
| "@lynx-js/react/refresh", | ||
| "@rspack/core/hot/dev-server", | ||
| "./src/index.js", | ||
| ], | ||
| "layer": "react:background", | ||
| }, | ||
| "main__main-thread": { | ||
| "filename": ".rspeedy/main/main-thread.js", | ||
| "import": [ | ||
| "<WORKSPACE>/packages/webpack/css-extract-webpack-plugin/runtime/hotModuleReplacement.lepus.cjs", | ||
| "./src/index.js", | ||
| ], | ||
| "layer": "react:main-thread", | ||
| }, | ||
| } | ||
| `) | ||
| }) | ||
|
|
||
| test('should not prepend refresh runtime when hmr is set to false', async () => { | ||
| const { pluginReactLynx } = await import('../src/pluginReactLynx.js') | ||
| const rsbuild = await createRspeedy({ | ||
| rspeedyConfig: { | ||
| dev: { | ||
| hmr: false, | ||
| }, | ||
| plugins: [ | ||
| pluginReactLynx(), | ||
| ], | ||
| }, | ||
| }) | ||
|
|
||
| const [config] = await rsbuild.initConfigs() | ||
| expect(config.entry).toMatchInlineSnapshot(` | ||
| { | ||
| "main": { | ||
| "filename": ".rspeedy/main/background.js", | ||
| "import": [ | ||
| "@lynx-js/webpack-dev-transport/client", | ||
| "./src/index.js", | ||
| ], | ||
| "layer": "react:background", | ||
| }, | ||
| "main__main-thread": { | ||
| "filename": ".rspeedy/main/main-thread.js", | ||
| "import": [ | ||
| "./src/index.js", | ||
| ], | ||
| "layer": "react:main-thread", | ||
| }, | ||
| } | ||
| `) | ||
| }) | ||
|
|
||
| test('should not prepend dev runtime when hmr and liveReload is set to false both', async () => { | ||
| const { pluginReactLynx } = await import('../src/pluginReactLynx.js') | ||
| const rsbuild = await createRspeedy({ | ||
| rspeedyConfig: { | ||
| dev: { | ||
| hmr: false, | ||
| liveReload: false, | ||
| }, | ||
| plugins: [ | ||
| pluginReactLynx(), | ||
| ], | ||
| }, | ||
| }) | ||
|
|
||
| const [config] = await rsbuild.initConfigs() | ||
| expect(config.entry).toMatchInlineSnapshot(` | ||
| { | ||
| "main": { | ||
| "filename": ".rspeedy/main/background.js", | ||
| "import": [ | ||
| "./src/index.js", | ||
| ], | ||
| "layer": "react:background", | ||
| }, | ||
| "main__main-thread": { | ||
| "filename": ".rspeedy/main/main-thread.js", | ||
| "import": [ | ||
| "./src/index.js", | ||
| ], | ||
| "layer": "react:main-thread", | ||
| }, | ||
| } | ||
| `) | ||
| }) | ||
| }) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.