-
Notifications
You must be signed in to change notification settings - Fork 46.9k
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
Webpack 5 Upgrade #22267
Webpack 5 Upgrade #22267
Conversation
Fixing devtools builds Changing to temp fix workerize loader Removing node polyfills that no longer apply to webpack
Hi @ScriptedAlchemy! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks! |
@bvaughn As requested There are some deprecation warnings on All the devtools builds seem to pass without issue, may require a test from someone more familiar with the project. I just made it compiler without errors, though the changes to that worker loader are pretty simple, I don't foresee much issue if there is any at all. the original from @developit seems to be dead, so I just searched npm for another variant before cutting a new one myself. CLA was signed even though it says it wasn't, not sure if the bot is just slow |
Comparing: e07039b...3ab20d4 Critical size changesIncludes critical production bundles, as well as any change greater than 2%:
Significant size changesIncludes any change greater than 0.2%: (No significant changes) |
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks! |
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.
Thank you so much for picking up where I left off and taking a pass at this 😁 I've left a few comments about things that seem to have broken. Happy to hop on a video call today at some point and chat about this (if it would be convenient for you!)
"webpack": "^5", | ||
"webpack-cli": "^4", | ||
"webpack-dev-server": "^4", | ||
"workerize-loader-5": "^1.4.0" |
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.
Something about this change causes the following error to be thrown in the extension process:
Uncaught ReferenceError: process is not defined
Looking at the code in question, I see:
(0, _utils.default)("ArrayExpression", {
fields: {
elements: {
validate: (0, _utils.chain)((0, _utils.assertValueType)("array"), (0, _utils.assertEach)((0, _utils.assertNodeOrValueType)("null", "Expression", "SpreadElement"))),
default: !process.env.BABEL_TYPES_8_BREAKING ? [] : undefined
}
},
visitor: ["elements"],
aliases: ["Expression"]
});
Seems like this is coming from an imported module?
Seems like the result of this error is that the named hooks feature does not work. (Clicking the little "🪄" button for an inspected element eventually times out whereas it used to work.)
To reproduce this problem, build the extension as described here and then open a website like Code Sandbox and try to inspect a component with hooks. (You can see the error thrown when the extension is initializing actually, by undocking the DevTools and opening a second level of DevTools to inspect the extension.)
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.
will look into this further
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.
🙇🏼♂️ Thanks!
@@ -50,7 +50,7 @@ | |||
"peerDependencies": { | |||
"react": "^17.0.0", | |||
"react-dom": "^17.0.0", | |||
"webpack": "^4.43.0" | |||
"webpack": "^5" |
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.
I think we need to downgrade this back to Webpack 4, e.g.
@sebmarkbage says this plug-in doesn’t work with Webpack 5 since it uses internals and plug-in apis and needs to be ported. (And there's currently no automated test coverage to verify this does or doesn't work.)
Edit 1 Apparently we can test this by building and then yarn start
ing the fixture in /fixtures/flight/
.
The built bundle has a peer dependency on Webpack 4 (via the workspaces) and this might cause problems. I'll test this.
Edit 2: @sebmarkbage has also expressed concern that this change would break this demo: https://github.com/reactjs/server-components-demo
Can we rollback the peer dependency change for this package only?
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.
Thanks for revering the change to packages/react-server-dom-webpack/package.json
peer dependencies.
I've tested the flight fixture after your most recent commit:
# root
yarn install
yarn build
# fixtures/flight
yarn install
yarn start
Loading localhost:3000 shows the following warnings/errors:
Warning: ReactDOM.render is no longer supported in React 18. Use createRoot instead. Until you switch to the new API, your app will behave as if it's running React 17. Learn more: https://reactjs.org/link/switch-to-createroot
Failed to load resource: net::ERR_CONNECTION_REFUSED
Uncaught TypeError: Failed to fetch
The above error occurred in the <Content> component:
at Content
at Suspense
Consider adding an error boundary to your tree to customize error handling behavior.
Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.
The first warning is expected and indicates that the fixture is just a little out of date. The following errors seem bad though.
For comparison, I've tested the same steps on HEAD of main branch, and I see the app load successfully. So it seems like this update certainly breaks the flight fixture – but would presumably not break the downstream packages/dependencies.
cc @sebmarkbage to confirm is this is acceptable for the time being?
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.
The fixture is acceptable but we need to fix the published package. Worst case maybe we can turn this to private: true
and exclude it from future builds to avoid confusion until it's fixed.
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.
Just to be clear, we're commenting on an outdated version of this PR here. This change was reverted in 13f3bd6 and the latest commit state makes no changes to the packages/react-server-dom-webpack/package.json
package (or its peer dependencies)
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.
Sorry for the drive-by.
says this plug-in doesn’t work with Webpack 5 since it uses internals and plug-in apis and needs to be ported. (And there's currently no automated test coverage to verify this does or doesn't work.)
I wrote a PR a while ago to support both webpack 5 and webpack 4 (https://github.com/facebook/react/pull/20524/files) in the react-dom-server-webpack
plugin package.
If there is interest, I would be happy to pick it back up and get it into a state where it could be merged in? It sounds like we'd want to add automated tests for the plugin before merging the linked PR.
"webpack-dev-server": "^3.10.3" | ||
"webpack": "^5", | ||
"webpack-cli": "^4", | ||
"webpack-dev-server": "^4" | ||
} | ||
} |
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.
The react-devtools-shell
test app is broken by this change. (I think actually it's the react-devtools-inline
package that gets broken, but I'll explain that below.)
Looks like the page is trying to request /dist/devtools.js
and it's getting a 400 response. (Interestingly, the page is also requesting /devtools.js
and that's returning okay.)
Editing the index.html
file so the <script>
tag loads /devtools.js
instead (no /dist/...
) fixes the failed network requests, but still doesn't fix the broken shell.
I see the following error in the console:
Uncaught TypeError: (0 , react_devtools_inline_backend__WEBPACK_IMPORTED_MODULE_2__.initialize) is not a function
I also see a few (related?) warnings in the console when running the test shell:
WARNING in ./src/devtools.js 14:0-17
export 'initialize' (imported as 'initializeBackend') was not found in 'react-devtools-inline/backend' (possible exports: backend)
WARNING in ./src/devtools.js 17:17-35
export 'initialize' (imported as 'initializeFrontend') was not found in 'react-devtools-inline/frontend' (possible exports: frontend)
WARNING in ./src/devtools.js 20:0-15
export 'activate' (imported as 'activateBackend') was not found in 'react-devtools-inline/backend' (possible exports: backend)
Inspecting the imported module, it looks like there's an extra backend
wrapper now, e.g.
// module:
{
backend: {
activate: (...),
initialize: (...)
}
}
Whereas before it was:
// module:
{
activate: (...),
initialize: (...)
}
This behavior can be reproduced by following the steps here:
https://github.com/facebook/react/blob/main/packages/react-devtools/CONTRIBUTING.md#option-1-fastest-using-the-test-shell
Then loading localhost:8080.
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.
I think we could work around this by updating the entrypoint files like so:
react-devtools-inline/backend.js
module.exports = require('./dist/backend').backend;
react-devtools-inline/frontend.js
module.exports = require('./dist/frontend').frontend;
But I don't know why this is necessary or (more importantly) what other places it might cause trouble.
Anyway, in the spirit of testing, I've made this change locally to see if things works otherwise– and it looks like the DevTools UI is not visible in the test shell (so something is still broken) and I see the following two errors in the console:
GET http://localhost:8080/dist/devtools.js net::ERR_ABORTED 404 (Not Found)
GET http://localhost:8080/dist/app.js net::ERR_ABORTED 404 (Not Found)
Here's my local changes when testing this (in case it helps you any):
diff --git a/packages/react-devtools-inline/backend.js b/packages/react-devtools-inline/backend.js
index 2c2a32d45..dbfbf7b34 100644
--- a/packages/react-devtools-inline/backend.js
+++ b/packages/react-devtools-inline/backend.js
@@ -1 +1 @@
-module.exports = require('./dist/backend');
+module.exports = require('./dist/backend').backend;
diff --git a/packages/react-devtools-inline/frontend.js b/packages/react-devtools-inline/frontend.js
index a86be2237..4700af89e 100644
--- a/packages/react-devtools-inline/frontend.js
+++ b/packages/react-devtools-inline/frontend.js
@@ -1 +1 @@
-module.exports = require('./dist/frontend');
+module.exports = require('./dist/frontend').frontend;
\ No newline at end of file
diff --git a/packages/react-devtools-shell/src/app/index.js b/packages/react-devtools-shell/src/app/index.js
index 805cd0a2a..4278daaf0 100644
--- a/packages/react-devtools-shell/src/app/index.js
+++ b/packages/react-devtools-shell/src/app/index.js
@@ -12,7 +12,7 @@ import Iframe from './Iframe';
import EditableProps from './EditableProps';
import ElementTypes from './ElementTypes';
import Hydration from './Hydration';
-import InlineWarnings from './InlineWarnings';
+// import InlineWarnings from './InlineWarnings';
import InspectableElements from './InspectableElements';
import ReactNativeWeb from './ReactNativeWeb';
import ToDoList from './ToDoList';
@@ -53,7 +53,7 @@ function mountTestApp() {
mountHelper(Hydration);
mountHelper(ElementTypes);
mountHelper(EditableProps);
- mountHelper(InlineWarnings);
+ // mountHelper(InlineWarnings);
mountHelper(ReactNativeWeb);
mountHelper(Toggle);
mountHelper(ErrorBoundaries);
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.
Looks like I can fix the GET failures by modifying the following files:
diff --git a/packages/react-devtools-shell/index.html b/packages/react-devtools-shell/index.html
index 410dc5bdc..732ba5db6 100644
--- a/packages/react-devtools-shell/index.html
+++ b/packages/react-devtools-shell/index.html
@@ -64,6 +64,6 @@
<!-- This script installs the hook, injects the backend, and renders the DevTools UI -->
<!-- In DEV mode, this file is served by the Webpack dev server -->
<!-- For production builds, it's built by Webpack and uploaded from the local file system -->
- <script src="dist/devtools.js"></script>
+ <script src="devtools.js"></script>
</body>
</html>
\ No newline at end of file
diff --git a/packages/react-devtools-shell/src/devtools.js b/packages/react-devtools-shell/src/devtools.js
index fda4c91b7..c7fbd3a1c 100644
--- a/packages/react-devtools-shell/src/devtools.js
+++ b/packages/react-devtools-shell/src/devtools.js
@@ -50,7 +50,7 @@ mountButton.addEventListener('click', function() {
}
});
-inject('dist/app.js', () => {
+inject('app.js', () => {
initDevTools({
connect(cb) {
const root = createRoot(container);
But now for some reason the test app code loads 3 times in the page (so there's 3 duplicate copies) and DevTools UI is still not visible at all (though it's loading). It looks like the CSS/styles are weird somehow, because the DevTools UI is loading in the background (behind the duplicate copies of the app).
Digging in a little more, I see a lot of <div>
elements in the root of the page (outside of the <iframe>
the test app is supposed to load into). Deleting them reveals the DevTools UI underneath, and it even mostly works, but there are a lot of "duplicate ID" errors in the console (presumably from the duplicate test apps) so...something wonky is still going on here.
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.
Possibly related to the "3 copies of the app are on the page" thing I mentioned above– the console also shows 3 copies of these logs:
VM7176 devtools.js:17483 [HMR] Waiting for update signal from WDS...
VM7176 devtools.js:4692 Download the React DevTools for a better development experience: https://reactjs.org/link/react-devtools
log.js:24 [HMR] Waiting for update signal from WDS...
react-dom.development.js:29044 Download the React DevTools for a better development experience: https://reactjs.org/link/react-devtools
console.js:29 [HMR] Waiting for update signal from WDS...
react-dom.development.js:29044 Download the React DevTools for a better development experience: https://reactjs.org/link/react-devtools
VM7176 devtools.js:11398 [webpack-dev-server] Hot Module Replacement enabled.
index.js:519 [webpack-dev-server] Hot Module Replacement enabled.
index.js:519 [webpack-dev-server] Hot Module Replacement enabled.
VM7176 devtools.js:11398 [webpack-dev-server] Live Reloading enabled.
index.js:519 [webpack-dev-server] Live Reloading enabled.
index.js:519 [webpack-dev-server] Live Reloading enabled.
Spaces added by me to highlight the fact that– although the content of the logs is the same, the file locations are different. I think this suggests that Webpack is bundling things oddly?
Looks like a small conflict in |
Not a problem. Rebase or merge commit? What's the preference? |
@ScriptedAlchemy No strong preference. We do a squash commit when merging anyway. |
Just checking in to see how this is going 😄 |
This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated. |
## Summary - Updated `webpack` (and all related packages) to v5 in `react-devtools-*` packages. - I haven't touched any `TODO (Webpack 5)`. Tried to poke it, but each my attempt failed and parsing hook names feature stopped working. I will work on this in a separate PR. - This work is one of prerequisites for updating Firefox extension to manifests v3 related PRs: #22267 #26506 ## How did you test this change? Tested on all surfaces, explicitly checked that parsing hook names feature still works.
Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you! |
## Summary - Updated `webpack` (and all related packages) to v5 in `react-devtools-*` packages. - I haven't touched any `TODO (Webpack 5)`. Tried to poke it, but each my attempt failed and parsing hook names feature stopped working. I will work on this in a separate PR. - This work is one of prerequisites for updating Firefox extension to manifests v3 related PRs: facebook#22267 facebook#26506 ## How did you test this change? Tested on all surfaces, explicitly checked that parsing hook names feature still works.
Summary
Upgrading devtools builds to work with webpack 5
How did you test this change?
I ran the build and it passed