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: webpack 5 and worker-loader support #21050

Merged
merged 6 commits into from Jan 14, 2021
Merged
Show file tree
Hide file tree
Changes from 2 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
2 changes: 1 addition & 1 deletion .github/workflows/build_test_deploy.yml
Expand Up @@ -185,7 +185,7 @@ jobs:
- run: yarn list webpack react react-dom
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs-only' }}

- run: xvfb-run node run-tests.js test/integration/{link-ref,production,basic,async-modules,font-optimization,ssr-ctx}/test/index.test.js test/acceptance/*.test.js
- run: xvfb-run node run-tests.js test/integration/{link-ref,production,basic,async-modules,font-optimization,ssr-ctx,worker-loader}/test/index.test.js test/acceptance/*.test.js
if: ${{ steps.docs-change.outputs.DOCS_CHANGE != 'docs-only' }}

testFirefox:
Expand Down
12 changes: 6 additions & 6 deletions package.json
Expand Up @@ -44,6 +44,11 @@
"@babel/preset-react": "7.12.10",
"@fullhuman/postcss-purgecss": "1.3.0",
"@mdx-js/loader": "0.18.0",
"@opentelemetry/exporter-zipkin": "0.14.0",
"@opentelemetry/node": "0.14.0",
"@opentelemetry/plugin-http": "0.14.0",
"@opentelemetry/plugin-https": "0.14.0",
"@opentelemetry/tracing": "0.14.0",
"@types/cheerio": "0.22.16",
"@types/fs-extra": "8.1.0",
"@types/http-proxy": "1.17.3",
Expand Down Expand Up @@ -129,12 +134,7 @@
"wait-port": "0.2.2",
"web-streams-polyfill": "2.1.1",
"webpack-bundle-analyzer": "4.3.0",
"worker-loader": "2.0.0",
"@opentelemetry/exporter-zipkin": "0.14.0",
"@opentelemetry/node": "0.14.0",
"@opentelemetry/plugin-http": "0.14.0",
"@opentelemetry/plugin-https": "0.14.0",
"@opentelemetry/tracing": "0.14.0"
"worker-loader": "3.0.7"
},
"resolutions": {
"browserslist": "^4.14.7",
Expand Down
2 changes: 2 additions & 0 deletions packages/react-refresh-utils/ReactRefreshWebpackPlugin.ts
Expand Up @@ -95,6 +95,7 @@ function webpack5(compiler: Compiler) {
// @ts-ignore This exists in webpack 5
const { runtimeTemplate } = this.compilation
return Template.asString([
`if (${RuntimeGlobals.interceptModuleExecution}) {`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a specific integration test to be added for this case? It's unclear what it solves.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@timneutkens React refresh template is injected in web worker bundle and an exception is created: Uncaught TypeError: Cannot read property 'push' of undefined

Here there is a repro https://github.com/ramasilveyra/bug-repro-next-w5-worker

I will update pr description with this info.

The exception happens when web worker is executed, so the current worker loader test covers this case.

`${
RuntimeGlobals.interceptModuleExecution
}.push(${runtimeTemplate.basicFunction('options', [
Expand Down Expand Up @@ -127,6 +128,7 @@ function webpack5(compiler: Compiler) {
]
)}`,
])})`,
'}',
])
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/integration/worker-loader/next.config.js
Expand Up @@ -4,7 +4,7 @@ module.exports = {
test: /\.worker\.(js|ts|tsx)$/,
loader: 'worker-loader',
options: {
name: 'static/[hash].worker.js',
filename: 'static/[hash].worker.js',
publicPath: '/_next/',
},
})
Expand Down
3 changes: 1 addition & 2 deletions test/integration/worker-loader/test/index.test.js
Expand Up @@ -9,8 +9,7 @@ const context = {}

jest.setTimeout(1000 * 60 * 2)

// TODO: Upgrade worker-loader when it's published with webpack 5 support
describe.skip('Web Workers with Fast Refresh', () => {
describe('Web Workers with Fast Refresh', () => {
beforeAll(async () => {
context.appPort = await findPort()
context.server = await launchApp(appDir, context.appPort)
Expand Down
22 changes: 7 additions & 15 deletions yarn.lock
Expand Up @@ -9840,7 +9840,7 @@ loader-utils@2.0.0, loader-utils@^2.0.0:
emojis-list "^3.0.0"
json5 "^2.1.2"

loader-utils@^1.0.0, loader-utils@^1.0.1, loader-utils@^1.0.2, loader-utils@^1.1.0, loader-utils@^1.2.3:
loader-utils@^1.0.1, loader-utils@^1.0.2, loader-utils@^1.1.0, loader-utils@^1.2.3:
version "1.4.0"
resolved "https://registry.yarnpkg.com/loader-utils/-/loader-utils-1.4.0.tgz#c579b5e34cb34b1a74edc6c1fb36bfa371d5a613"
dependencies:
Expand Down Expand Up @@ -13966,14 +13966,6 @@ schema-utils@2.7.1, schema-utils@^2.0.0, schema-utils@^2.6.5, schema-utils@^2.6.
ajv "^6.12.4"
ajv-keywords "^3.5.2"

schema-utils@^0.4.0:
version "0.4.7"
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-0.4.7.tgz#ba74f597d2be2ea880131746ee17d0a093c68187"
integrity sha512-v/iwU6wvwGK8HbU9yi3/nhGzP0yGSuhQMzL6ySiec1FSrZZDkhm4noOSWzrNFo/jEc+SJY6jRTwuwbSXJPDUnQ==
dependencies:
ajv "^6.1.0"
ajv-keywords "^3.1.0"

schema-utils@^1.0.0:
version "1.0.0"
resolved "https://registry.yarnpkg.com/schema-utils/-/schema-utils-1.0.0.tgz#0b79a93204d7b600d4b2850d1f66c2a34951c770"
Expand Down Expand Up @@ -16026,13 +16018,13 @@ worker-farm@^1.7.0:
dependencies:
errno "~0.1.7"

worker-loader@2.0.0:
version "2.0.0"
resolved "https://registry.yarnpkg.com/worker-loader/-/worker-loader-2.0.0.tgz#45fda3ef76aca815771a89107399ee4119b430ac"
integrity sha512-tnvNp4K3KQOpfRnD20m8xltE3eWh89Ye+5oj7wXEEHKac1P4oZ6p9oTj8/8ExqoSBnk9nu5Pr4nKfQ1hn2APJw==
worker-loader@3.0.7:
version "3.0.7"
resolved "https://registry.yarnpkg.com/worker-loader/-/worker-loader-3.0.7.tgz#9cf2122a9a781d6742cb873c58c3769591b31988"
integrity sha512-LjYLuYJw6kqQKDoygpoD5vWeR1CbZjuVSW3/8pFsptMlUl8gatNM/pszhasSDAWt+dYxMipWB6695k+1zId+iQ==
dependencies:
loader-utils "^1.0.0"
schema-utils "^0.4.0"
loader-utils "^2.0.0"
schema-utils "^3.0.0"

wrap-ansi@^2.0.0:
version "2.1.0"
Expand Down