File tree Expand file tree Collapse file tree 9 files changed +107
-5
lines changed
rspack-test-tools/tests/hotCases/css/recovery/__snapshots__/web
tests/e2e/cases/css/update-initial-chunks-after-hmr Expand file tree Collapse file tree 9 files changed +107
-5
lines changed Original file line number Diff line number Diff line change @@ -37,6 +37,9 @@ var findStylesheet = function (href, fullhref) {
37
37
for ( var i = 0 ; i < existingLinkTags . length ; i ++ ) {
38
38
var tag = existingLinkTags [ i ] ;
39
39
var dataHref = tag . getAttribute ( "data-href" ) || tag . getAttribute ( "href" ) ;
40
+ if ( dataHref ) {
41
+ dataHref = dataHref . split ( '?' ) [ 0 ]
42
+ }
40
43
if ( tag . rel === "stylesheet" && ( dataHref === href || dataHref === fullhref ) ) return tag ;
41
44
}
42
45
Original file line number Diff line number Diff line change 6
6
## Asset Files
7
7
- Bundle: bundle.js
8
8
- Manifest: main.LAST_HASH.hot-update.json, size: 28
9
- - Update: main.hot-update.js, size: 7115
9
+ - Update: main.hot-update.js, size: 7153
10
10
11
11
## Manifest
12
12
@@ -80,8 +80,9 @@ function updateCss(el, url) {
80
80
let normalizedUrl;
81
81
if (url) normalizedUrl = url;
82
82
else {
83
- if (!el.href) return;
84
- normalizedUrl = el.href.split("?")[0];
83
+ let href = el.getAttribute("href");
84
+ if (!href) return;
85
+ normalizedUrl = href.split("?")[0];
85
86
}
86
87
if (!isUrlRequest(normalizedUrl) || !1 === el.isLoaded || !normalizedUrl || !(normalizedUrl.indexOf(".css") > -1)) return;
87
88
el.visited = !0;
Original file line number Diff line number Diff line change @@ -109,11 +109,12 @@ function getCurrentScriptUrl(moduleId: string) {
109
109
function updateCss ( el : HTMLLinkElement & Record < string , any > , url ?: string ) {
110
110
let normalizedUrl : string ;
111
111
if ( ! url ) {
112
- if ( ! el . href ) {
112
+ const href = el . getAttribute ( "href" ) ;
113
+ if ( ! href ) {
113
114
return ;
114
115
}
115
116
116
- normalizedUrl = el . href . split ( "?" ) [ 0 ] ;
117
+ normalizedUrl = href . split ( "?" ) [ 0 ] ;
117
118
} else {
118
119
normalizedUrl = url ;
119
120
}
Original file line number Diff line number Diff line change
1
+ import { test , expect } from "@/fixtures" ;
2
+
3
+ const COLOR_BLUE = "rgb(163, 255, 255)"
4
+ const COLOR_WHITE = "rgb(255, 255, 255)"
5
+
6
+ test ( "should update body css" , async ( { page, fileAction } ) => {
7
+ await expect ( page . locator ( "body" ) ) . toHaveCSS ( "background-color" , COLOR_BLUE ) ;
8
+
9
+ // trigger css hmr
10
+ fileAction . updateFile ( "src/index.js" , content =>
11
+ content . replace ( 'import "./blue.css";' , '// import "./blue.css";' )
12
+ ) ;
13
+
14
+ await expect ( page . locator ( "body" ) ) . toHaveCSS ( "background-color" , COLOR_WHITE ) ;
15
+
16
+ // initial css chunk update, without css hmr
17
+ fileAction . updateFile ( "src/index.js" , content =>
18
+ content . replace ( "//" , "" )
19
+ ) ;
20
+
21
+ await expect ( page . locator ( "body" ) ) . toHaveCSS ( "background-color" , COLOR_BLUE ) ;
22
+ } ) ;
Original file line number Diff line number Diff line change
1
+ const { rspack } = require ( "@rspack/core" ) ;
2
+
3
+ /** @type { import('@rspack/core').RspackOptions } */
4
+ module . exports = {
5
+ context : __dirname ,
6
+ mode : "development" ,
7
+ entry : {
8
+ main : [ "./src/index.css" , "./src/index.js" ]
9
+ } ,
10
+ devServer : {
11
+ hot : true
12
+ } ,
13
+ plugins : [
14
+ new rspack . HtmlRspackPlugin ( {
15
+ template : "./src/index.html" ,
16
+ inject : "body"
17
+ } ) ,
18
+ new rspack . CssExtractRspackPlugin ( {
19
+ filename : "static/style.css" ,
20
+ } )
21
+ ] ,
22
+ module : {
23
+ rules : [
24
+ {
25
+ test : / \. c s s $ / ,
26
+ use : [
27
+ rspack . CssExtractRspackPlugin . loader ,
28
+ "css-loader" ,
29
+ ]
30
+ }
31
+ ]
32
+ } ,
33
+ optimization : {
34
+ splitChunks : {
35
+ cacheGroups : {
36
+ style : {
37
+ name : "style" ,
38
+ test : / \. c s s $ / ,
39
+ chunks : "all" ,
40
+ enforce : true
41
+ }
42
+ }
43
+ }
44
+ } ,
45
+ watchOptions : {
46
+ poll : 1000
47
+ } ,
48
+ experiments : {
49
+ css : false
50
+ }
51
+ } ;
Original file line number Diff line number Diff line change
1
+ body {
2
+ background-color : rgb (163 , 255 , 255 );
3
+ }
Original file line number Diff line number Diff line change
1
+ body {
2
+ background-color : # ffffff ;
3
+ }
Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ < html lang ="en ">
3
+
4
+ < head >
5
+ < meta charset ="UTF-8 " />
6
+ < meta http-equiv ="X-UA-Compatible " content ="IE=edge " />
7
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 " />
8
+ < title > Document</ title >
9
+ </ head >
10
+
11
+ < body >
12
+ < div id ="root "> </ div >
13
+ </ body >
14
+
15
+ </ html >
Original file line number Diff line number Diff line change
1
+ import "./blue.css" ;
2
+
3
+ module . hot . accept ( )
You can’t perform that action at this time.
0 commit comments