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

update ReactFlightWebpackPlugin to be compatiable with webpack v5 #22739

Merged

Conversation

michenly
Copy link
Contributor

Summary

Current React Server Component uses webpack 4 when webpack 5 had been out for more than 1 year.
This PR updated the current plugin packages/react-server-dom-webpack/src/ReactFlightWebpackPlugin.js to be compatible with the latest webpack 5

How did you test this change?

The original development was done in reactjs/server-components-demo#52 and written in typescript.

I tested it by using the plugin in server-components-demo project

  • run npm run start
  • manually tested the application for everything to be the same.
  • compare react-client-manifest.json build output in webpack 4 & webpack 5 (the content are exactly the same with the exception of vendor files are named differently in webpack 5)
  • compare build assets output to be the same

@facebook-github-bot
Copy link

Hi @michenly!

Thank you for your pull request and welcome to our community.

Action Required

In 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.

Process

In 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 CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@fb.com. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

1 similar comment
@facebook-github-bot
Copy link

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Facebook open source project. Thanks!

@@ -268,7 +330,8 @@ export default class ReactFlightWebpackPlugin {
(err2: null | Error, deps: Array<ModuleDependency>) => {
if (err2) return cb(err2);
const clientRefDeps = deps.map(dep => {
const request = join(resolvedDirectory, dep.request);
// use userRequest instead of request. request always end with undefined which is wrong
const request = join(resolvedDirectory, dep.userRequest);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

the only part I slightly question

compilation.hooks.processAssets.tap(
{
name: PLUGIN_NAME,
stage: Compilation.PROCESS_ASSETS_STAGE_REPORT,
Copy link
Collaborator

@gaearon gaearon Nov 25, 2021

Choose a reason for hiding this comment

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

Should this be PROCESS_ASSETS_STAGE_REPORT or PROCESS_ASSETS_STAGE_DERIVED?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

PROCESS_ASSETS_STAGE_REPORT — creating assets for the reporting purposes.
PROCESS_ASSETS_STAGE_DERIVED — derive new assets from the existing assets.

They both sound possible from the description alone.

However, I went with PROCESS_ASSETS_STAGE_REPORT because the type def of PROCESS_ASSETS_STAGE_DERIVED had mentioned NOT treating existing assets as complete which is not the scenario here.

});
};

normalModuleFactory.hooks.parser
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why is this better than tapping into buildModule?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

buildModule in webpack 5 no longer let you modify dependencies. (there is actually a line right after the hook that wipes it out, see details here).

parser is the recommended way going forward

@gaearon gaearon merged commit 0cc724c into facebook:main Nov 25, 2021
@gaearon
Copy link
Collaborator

gaearon commented Nov 25, 2021

Looks good to me, thanks.

@michenly michenly deleted the react-flight-webpack-plugin-to-webpack5 branch November 26, 2021 23:32
@michenly
Copy link
Contributor Author

@gaearon is it possible for me to publish a new version of react-server-dom-webpack or is that something your team will have to deal with?

facebook-github-bot pushed a commit to facebook/react-native that referenced this pull request Dec 14, 2021
Summary:
This sync includes the following changes:
- **[f2a59df48](facebook/react@f2a59df48 )**: Remove unstableAvoidThisFallback from OSS ([#22884](facebook/react#22884)) //<salazarm>//
- **[24dd07bd2](facebook/react@24dd07bd2 )**: Add custom element property support behind a flag ([#22184](facebook/react#22184)) //<Joey Arhar>//
- **[72e48b8e1](facebook/react@72e48b8e1 )**: Fix: Don't skip writing updated package.json //<Andrew Clark>//
- **[e39b2c899](facebook/react@e39b2c899 )**: Fix peer deps for use-sync-external-store //<Andrew Clark>//
- **[ec78b135f](facebook/react@ec78b135f )**: Don't override use-sync-external-store peerDeps ([#22882](facebook/react#22882)) //<Andrew Clark>//
- **[5041c37d2](facebook/react@5041c37d2 )**: Remove hydrate option from createRoot ([#22878](facebook/react#22878)) //<salazarm>//
- **[3f9480f0f](facebook/react@3f9480f0f )**: enable continuous replay flag ([#22863](facebook/react#22863)) //<salazarm>//
- **[4729ff6d1](facebook/react@4729ff6d1 )**: Implement identifierPrefix option for useId ([#22855](facebook/react#22855)) //<Andrew Clark>//
- **[ed00d2c3d](facebook/react@ed00d2c3d )**: Remove unused flag ([#22854](facebook/react#22854)) //<Dan Abramov>//
- **[0cc724c77](facebook/react@0cc724c77 )**: update ReactFlightWebpackPlugin to be compatiable with webpack v5 ([#22739](facebook/react#22739)) //<Michelle Chen>//
- **[4e6eec69b](facebook/react@4e6eec69b )**: fix: document can be `null`, not just `undefined` ([#22695](facebook/react#22695)) //<Simen Bekkhus>//

Changelog:
[General][Changed] - React Native sync for revisions c1220eb...a049aa0

jest_e2e[run_all_tests]

Reviewed By: rickhanlonii

Differential Revision: D33062386

fbshipit-source-id: 37e497947efad5696c251096da8a92ccdc6dcea7
@sebmarkbage
Copy link
Collaborator

I just had a chance to review this properly. Thanks for the detailed work here and preserving the exact details!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants