Skip to content
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

chore: polish CSS HMR logs and correct the case #8083

Merged
merged 2 commits into from
Oct 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ function isUrlRequest(url) {
*/
module.exports = function (moduleId, options) {
if (noDocument) {
console.log("no window.document found, will not HMR CSS");
console.log("[HMR] No `window.document` found, CSS HMR disabled");

return noop;
}
Expand All @@ -274,17 +274,17 @@ module.exports = function (moduleId, options) {
const reloaded = reloadStyle(src);

if (options.locals) {
console.log("[HMR] Detected local css modules. Reload all css");
console.log("[HMR] Detected local CSS Modules. Reload all CSS");

reloadAll();

return;
}

if (reloaded) {
console.log("[HMR] css reload %s", src.join(" "));
console.log("[HMR] CSS reload %s", src.join(" "));
} else {
console.log("[HMR] Reload all css");
console.log("[HMR] Reload all CSS");

reloadAll();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
## Asset Files
- Bundle: bundle.js
- Manifest: main.LAST_HASH.hot-update.json, size: 28
- Update: main.LAST_HASH.hot-update.js, size: 7627
- Update: main.LAST_HASH.hot-update.js, size: 7635

## Manifest

Expand Down Expand Up @@ -193,24 +193,24 @@ function isUrlRequest(url) {
}
function cssReload(moduleId, options) {
if (noDocument) {
console.log("no window.document found, will not HMR CSS");
console.log("[HMR] No `window.document` found, CSS HMR disabled");
return noop;
}
const getScriptSrc = getCurrentScriptUrl(moduleId);
function update() {
const src = getScriptSrc(options.filename);
const reloaded = reloadStyle(src);
if (options.locals) {
console.log("[HMR] Detected local css modules. Reload all css");
console.log("[HMR] Detected local CSS Modules. Reload all CSS");
reloadAll();
return;
}
if (reloaded) {
// biome-ignore lint/complexity/useOptionalChain: not use optionalChain to support legacy browser
console.log("[HMR] css reload %s", src && src.join(" "));
console.log("[HMR] CSS reload %s", src && src.join(" "));
}
else {
console.log("[HMR] Reload all css");
console.log("[HMR] Reload all CSS");
reloadAll();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function isUrlRequest(url: string): boolean {

function cssReload(moduleId: string, options: Record<string, any>) {
if (noDocument) {
console.log("no window.document found, will not HMR CSS");
console.log("[HMR] No `window.document` found, CSS HMR disabled");

return noop;
}
Expand All @@ -226,7 +226,7 @@ function cssReload(moduleId: string, options: Record<string, any>) {
const reloaded = reloadStyle(src);

if (options.locals) {
console.log("[HMR] Detected local css modules. Reload all css");
console.log("[HMR] Detected local CSS Modules. Reload all CSS");

reloadAll();

Expand All @@ -235,9 +235,9 @@ function cssReload(moduleId: string, options: Record<string, any>) {

if (reloaded) {
// biome-ignore lint/complexity/useOptionalChain: not use optionalChain to support legacy browser
console.log("[HMR] css reload %s", src && src.join(" "));
console.log("[HMR] CSS reload %s", src && src.join(" "));
} else {
console.log("[HMR] Reload all css");
console.log("[HMR] Reload all CSS");

reloadAll();
}
Expand Down
22 changes: 11 additions & 11 deletions tests/plugin-test/css-extract/__snapshots__/HMR.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -52,47 +52,47 @@ exports[`HMR hotLoader works for non-locals 1`] = `
"
`;

exports[`HMR should handle error event 1`] = `"[HMR] css reload %s"`;
exports[`HMR should handle error event 1`] = `"[HMR] CSS reload %s"`;

exports[`HMR should handle error event 2`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\">"`;

exports[`HMR should reloads with # link href 1`] = `"[HMR] css reload %s"`;
exports[`HMR should reloads with # link href 1`] = `"[HMR] CSS reload %s"`;

exports[`HMR should reloads with # link href 2`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\"><link rel=\\"shortcut icon\\" href=\\"#href\\">"`;

exports[`HMR should reloads with absolute remove url 1`] = `"[HMR] css reload %s"`;
exports[`HMR should reloads with absolute remove url 1`] = `"[HMR] CSS reload %s"`;

exports[`HMR should reloads with absolute remove url 2`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\"><link rel=\\"stylesheet\\" href=\\"http://dev.com/dist/main.css\\">"`;

exports[`HMR should reloads with browser extension protocol 1`] = `"[HMR] css reload %s"`;
exports[`HMR should reloads with browser extension protocol 1`] = `"[HMR] CSS reload %s"`;

exports[`HMR should reloads with browser extension protocol 2`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\"><link rel=\\"stylesheet\\" href=\\"chrome-extension://main.css\\">"`;

exports[`HMR should reloads with link without href 1`] = `"[HMR] css reload %s"`;
exports[`HMR should reloads with link without href 1`] = `"[HMR] CSS reload %s"`;

exports[`HMR should reloads with link without href 2`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\"><link rel=\\"shortcut icon\\">"`;

exports[`HMR should reloads with locals 1`] = `"[HMR] Detected local css modules. Reload all css"`;
exports[`HMR should reloads with locals 1`] = `"[HMR] Detected local CSS Modules. Reload all CSS"`;

exports[`HMR should reloads with locals 2`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\">"`;

exports[`HMR should reloads with non http/https link href 1`] = `"[HMR] css reload %s"`;
exports[`HMR should reloads with non http/https link href 1`] = `"[HMR] CSS reload %s"`;

exports[`HMR should reloads with non http/https link href 2`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\"><link rel=\\"shortcut icon\\" href=\\"data:;base64,=\\">"`;

exports[`HMR should reloads with non-file script in the end of page 1`] = `"[HMR] Reload all css"`;
exports[`HMR should reloads with non-file script in the end of page 1`] = `"[HMR] Reload all CSS"`;

exports[`HMR should reloads with non-file script in the end of page 2`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\">"`;

exports[`HMR should work reload all css 1`] = `"[HMR] Reload all css"`;
exports[`HMR should work reload all css 1`] = `"[HMR] Reload all CSS"`;

exports[`HMR should work reload all css 2`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\">"`;

exports[`HMR should works 1`] = `"[HMR] css reload %s"`;
exports[`HMR should works 1`] = `"[HMR] CSS reload %s"`;

exports[`HMR should works 2`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\">"`;

exports[`HMR should works with multiple updates 1`] = `"[HMR] css reload %s"`;
exports[`HMR should works with multiple updates 1`] = `"[HMR] CSS reload %s"`;

exports[`HMR should works with multiple updates 2`] = `"<link rel=\\"stylesheet\\" href=\\"/dist/main.css\\"><link rel=\\"stylesheet\\" href=\\"http://localhost/dist/main.css?1479427200000\\">"`;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,24 @@ function isUrlRequest(url) {
}
function cssReload(moduleId, options) {
if (noDocument) {
console.log("no window.document found, will not HMR CSS");
console.log("[HMR] No `window.document` found, CSS HMR disabled");
return noop;
}
const getScriptSrc = getCurrentScriptUrl(moduleId);
function update() {
const src = getScriptSrc(options.filename);
const reloaded = reloadStyle(src);
if (options.locals) {
console.log("[HMR] Detected local css modules. Reload all css");
console.log("[HMR] Detected local CSS Modules. Reload all CSS");
reloadAll();
return;
}
if (reloaded) {
// biome-ignore lint/complexity/useOptionalChain: not use optionalChain to support legacy browser
console.log("[HMR] css reload %s", src && src.join(" "));
console.log("[HMR] CSS reload %s", src && src.join(" "));
}
else {
console.log("[HMR] Reload all css");
console.log("[HMR] Reload all CSS");
reloadAll();
}
}
Expand Down
8 changes: 4 additions & 4 deletions tests/plugin-test/css-extract/cases/hmr/expected/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,24 +160,24 @@ function isUrlRequest(url) {
}
function cssReload(moduleId, options) {
if (noDocument) {
console.log("no window.document found, will not HMR CSS");
console.log("[HMR] No `window.document` found, CSS HMR disabled");
return noop;
}
const getScriptSrc = getCurrentScriptUrl(moduleId);
function update() {
const src = getScriptSrc(options.filename);
const reloaded = reloadStyle(src);
if (options.locals) {
console.log("[HMR] Detected local css modules. Reload all css");
console.log("[HMR] Detected local CSS Modules. Reload all CSS");
reloadAll();
return;
}
if (reloaded) {
// biome-ignore lint/complexity/useOptionalChain: not use optionalChain to support legacy browser
console.log("[HMR] css reload %s", src && src.join(" "));
console.log("[HMR] CSS reload %s", src && src.join(" "));
}
else {
console.log("[HMR] Reload all css");
console.log("[HMR] Reload all CSS");
reloadAll();
}
}
Expand Down
Loading