-
-
Notifications
You must be signed in to change notification settings - Fork 600
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: css runtime should have hmr handler when lazy-compilation (#8400)
- Loading branch information
Showing
10 changed files
with
134 additions
and
32 deletions.
There are no files selected for viewing
This file contains 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 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 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
21 changes: 21 additions & 0 deletions
21
packages/playground/cases/lazy-compilation/css-update/index.test.ts
This file contains 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,21 @@ | ||
import { expect, test } from "@/fixtures"; | ||
|
||
test("should update style", async ({ page }) => { | ||
const body = await page.$("body"); | ||
const backgroundColor = await body!.evaluate( | ||
el => window.getComputedStyle(el).backgroundColor | ||
); | ||
// first time enter the page, style is red | ||
expect(backgroundColor, "red"); | ||
|
||
// second time enter the page, this time brings query, | ||
// trigger lazy-compile | ||
const url = await body!.evaluate(() => window.location.href); | ||
await page.goto(`${url}?1`); | ||
const updatedBody = await page.$("body"); | ||
const updatedBackgroundColor = await updatedBody!.evaluate( | ||
el => window.getComputedStyle(el).backgroundColor | ||
); | ||
// first time enter the page, style is red | ||
expect(updatedBackgroundColor, "blue"); | ||
}); |
37 changes: 37 additions & 0 deletions
37
packages/playground/cases/lazy-compilation/css-update/rspack.config.js
This file contains 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,37 @@ | ||
const rspack = require("@rspack/core"); | ||
|
||
/** @type { import('@rspack/core').RspackOptions } */ | ||
module.exports = { | ||
context: __dirname, | ||
entry: "./src/index.js", | ||
mode: "development", | ||
module: { | ||
rules: [ | ||
{ | ||
test: /\.css$/, | ||
use: [rspack.CssExtractRspackPlugin.loader, "css-loader"] | ||
} | ||
] | ||
}, | ||
plugins: [new rspack.HtmlRspackPlugin(), new rspack.CssExtractRspackPlugin()], | ||
experiments: { | ||
css: false, | ||
lazyCompilation: true | ||
}, | ||
optimization: { | ||
splitChunks: { | ||
minSize: 0, | ||
chunks: "all", | ||
cacheGroups: { | ||
styles: { | ||
test: /\.css$/, | ||
name: "style.css" | ||
} | ||
} | ||
} | ||
}, | ||
devServer: { | ||
hot: true, | ||
port: 5678 | ||
} | ||
}; |
3 changes: 3 additions & 0 deletions
3
packages/playground/cases/lazy-compilation/css-update/src/blue.css
This file contains 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,3 @@ | ||
body { | ||
background-color: blue; | ||
} |
1 change: 1 addition & 0 deletions
1
packages/playground/cases/lazy-compilation/css-update/src/change.js
This file contains 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 @@ | ||
import "./blue.css"; |
6 changes: 6 additions & 0 deletions
6
packages/playground/cases/lazy-compilation/css-update/src/index.js
This file contains 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,6 @@ | ||
import "./red.css"; | ||
|
||
if (new URL(window.location.href).search) { | ||
// @ts-expect-error change.js no dts | ||
import("./change.js"); | ||
} |
3 changes: 3 additions & 0 deletions
3
packages/playground/cases/lazy-compilation/css-update/src/red.css
This file contains 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,3 @@ | ||
body { | ||
background-color: red; | ||
} |
This file contains 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
f23d638
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.
📝 Ran ecosystem CI: Open
f23d638
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.
📝 Benchmark detail: Open