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

fix: don't crash in web workers #1004

Merged
merged 3 commits into from Dec 6, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions src/index.js
Expand Up @@ -825,6 +825,7 @@ class MiniCssExtractPlugin {
}

return Template.asString([
'if (typeof document === "undefined") return;',
`var createStylesheet = ${runtimeTemplate.basicFunction(
"chunkId, fullhref, oldTag, resolve, reject",
[
Expand Down
Expand Up @@ -73,7 +73,7 @@ __webpack_require__.r(__webpack_exports__);
/******/
/******/ /* webpack/runtime/getFullHash */
/******/ (() => {
/******/ __webpack_require__.h = () => ("945622d4f51f3fe3a0d0")
/******/ __webpack_require__.h = () => ("4568ffdcdfced785eabc")
/******/ })();
/******/
/******/ /* webpack/runtime/global */
Expand Down Expand Up @@ -171,6 +171,7 @@ __webpack_require__.r(__webpack_exports__);
/******/
/******/ /* webpack/runtime/css loading */
/******/ (() => {
/******/ if (typeof document === "undefined") return;
/******/ var createStylesheet = (chunkId, fullhref, oldTag, resolve, reject) => {
/******/ var linkTag = document.createElement("link");
/******/
Expand Down
3 changes: 2 additions & 1 deletion test/cases/chunkFilename-fullhash/expected/webpack-5/main.js
Expand Up @@ -73,7 +73,7 @@ __webpack_require__.r(__webpack_exports__);
/******/
/******/ /* webpack/runtime/getFullHash */
/******/ (() => {
/******/ __webpack_require__.h = () => ("de494c1e7411c41d8362")
/******/ __webpack_require__.h = () => ("9ee2d65d5d13f2b4323d")
/******/ })();
/******/
/******/ /* webpack/runtime/global */
Expand Down Expand Up @@ -171,6 +171,7 @@ __webpack_require__.r(__webpack_exports__);
/******/
/******/ /* webpack/runtime/css loading */
/******/ (() => {
/******/ if (typeof document === "undefined") return;
/******/ var createStylesheet = (chunkId, fullhref, oldTag, resolve, reject) => {
/******/ var linkTag = document.createElement("link");
/******/
Expand Down
1 change: 1 addition & 0 deletions test/cases/hmr/expected/main.js
Expand Up @@ -934,6 +934,7 @@ __webpack_require__.r(__webpack_exports__);
/******/
/******/ /* webpack/runtime/css loading */
/******/ (() => {
/******/ if (typeof document === "undefined") return;
/******/ var createStylesheet = (chunkId, fullhref, oldTag, resolve, reject) => {
/******/ var linkTag = document.createElement("link");
/******/
Expand Down
1 change: 1 addition & 0 deletions test/cases/insert-function/expected/main.js
Expand Up @@ -155,6 +155,7 @@
/******/
/******/ /* webpack/runtime/css loading */
/******/ (() => {
/******/ if (typeof document === "undefined") return;
/******/ var createStylesheet = (chunkId, fullhref, oldTag, resolve, reject) => {
/******/ var linkTag = document.createElement("link");
/******/
Expand Down
1 change: 1 addition & 0 deletions test/cases/insert-string/expected/main.js
Expand Up @@ -155,6 +155,7 @@
/******/
/******/ /* webpack/runtime/css loading */
/******/ (() => {
/******/ if (typeof document === "undefined") return;
/******/ var createStylesheet = (chunkId, fullhref, oldTag, resolve, reject) => {
/******/ var linkTag = document.createElement("link");
/******/
Expand Down
1 change: 1 addition & 0 deletions test/cases/insert-undefined/expected/main.js
Expand Up @@ -155,6 +155,7 @@
/******/
/******/ /* webpack/runtime/css loading */
/******/ (() => {
/******/ if (typeof document === "undefined") return;
/******/ var createStylesheet = (chunkId, fullhref, oldTag, resolve, reject) => {
/******/ var linkTag = document.createElement("link");
/******/
Expand Down
6 changes: 3 additions & 3 deletions test/manual/index.html
Expand Up @@ -5,7 +5,7 @@
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>mini-css-extract-plugin testcase</title>
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="stylesheet" type="text/css" href="/dist/preloaded1.chunk.css" />
<link rel="stylesheet" type="text/css" href="dist/preloaded1.chunk.css" />
<style>
.test {
background: lightcoral;
Expand All @@ -23,7 +23,7 @@
background: lightgreen;
}
</style>
<link rel="stylesheet" type="text/css" href="/dist/main.css" />
<link rel="stylesheet" type="text/css" href="dist/main.css" />
</head>
<body>
<div class="test initial-css">Initial CSS: Must be green</div>
Expand Down Expand Up @@ -97,6 +97,6 @@
</p>
</div>
<div class="errors"></div>
<script async defer src="/dist/main.js"></script>
<script async defer src="dist/main.js"></script>
</body>
</html>
8 changes: 8 additions & 0 deletions test/manual/src/index.js
Expand Up @@ -94,3 +94,11 @@ makeButton(".crossorigin", () => {
__webpack_public_path__ = originalPublicPath;
return promise;
});

const worker = new Worker(new URL("./worker.js", import.meta.url));

worker.postMessage("test");

worker.addEventListener("message", (event) => {
console.log(`Received message from worker: ${event.data}`);
});
3 changes: 3 additions & 0 deletions test/manual/src/worker.css
@@ -0,0 +1,3 @@
body {
background: green;
}
15 changes: 15 additions & 0 deletions test/manual/src/worker.js
@@ -0,0 +1,15 @@
import "./worker.css";

// eslint-disable-next-line no-undef
self.onmessage = (event) => {
console.log(`Received message from application: ${event.data}`);

// eslint-disable-next-line no-undef
self.postMessage("I'm alive!");
};

async function load() {
return import("./simple.css");
}

load();
8 changes: 6 additions & 2 deletions test/manual/webpack.config.js
Expand Up @@ -12,11 +12,15 @@ const ENABLE_ES_MODULE =
: true;

const OLD_API =
typeof process.env.OLD_API !== "undefined" ? yn(process.env.OLD_API) : true;
typeof process.env.OLD_API !== "undefined" ? yn(process.env.OLD_API) : false;

console.log(OLD_API);
console.log("OPTIONS:");
console.log("ENABLE_HMR:", ENABLE_HMR);
console.log("ENABLE_ES_MODULE:", ENABLE_ES_MODULE);
console.log("OLD_API:", OLD_API);

module.exports = {
devtool: false,
mode: "development",
output: {
chunkFilename: "[name].chunk.js",
Expand Down