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

Build: Improve how combined assets are generated #3309

Closed

Conversation

gziolo
Copy link
Member

@gziolo gziolo commented Sep 22, 2022

Trac ticket: https://core.trac.wordpress.org/ticket/56615

It reverts the temporary workaround for the failing Test NPM CI check on Windows: https://core.trac.wordpress.org/changeset/54277.

It's based on the finding from @jsnajdr that stable hashes are only guaranteed for the production version of the build. In effect, I'm applying the following changes:

  • generate combined asset files for both production and development
  • store in the repository only the production version of the combined assets for packages, we use everything else only in development
  • to make unit tests work, ensure that they ignore react fast refresh and use the production version of combined assets that are present in the source code

This Pull Request is for code review only. Please keep all other discussion in the Trac ticket. Do not merge this Pull Request. See GitHub Pull Requests for Code Review in the Core Handbook for more details.

@gziolo gziolo force-pushed the update/combined-assets-improved branch from 7ca93e1 to aa83b13 Compare September 22, 2022 07:26
@gziolo gziolo force-pushed the update/combined-assets-improved branch from aa83b13 to 29bca0e Compare September 22, 2022 07:48
@gziolo gziolo self-assigned this Sep 22, 2022
@gziolo gziolo force-pushed the update/combined-assets-improved branch 2 times, most recently from d62fe46 to 53ae3f0 Compare September 22, 2022 08:39
@jsnajdr
Copy link
Member

jsnajdr commented Sep 22, 2022

It's based on the finding from @jsnajdr that stable hashes are only guaranteed for the production version of the build.

I did some more debugging today and it seems that not even production build reliably guarantees stable order of modules and stable hashes. When the chunk modules are written to a file, they are ordered by module.identifier(), which is not the thing that you defined in optimization.moduleIds, e.g., named or deterministic, but the module's request field, which is the full absolute path to the module, like /Users/jsnajdr/project/src/index.js. See this webpack method that returns this.request and doesn't really look at anything else:

https://github.com/webpack/webpack/blob/9fcaa243573005d6fdece9a3f8d89a0e8b399613/lib/NormalModule.js#L338-L349

The real reason why production builds are OK is that production uses module concatenation. The offending date-fns modules are concatenated into another module and are no longer written separately. Then the unstable sorting doesn't happen.

I'll be investigating further in cooperation with @ockham

@gziolo gziolo force-pushed the update/combined-assets-improved branch from 53ae3f0 to 849b671 Compare September 22, 2022 09:12
@gziolo
Copy link
Member Author

gziolo commented Sep 22, 2022

I'll be investigating further in cooperation with @ockham

Thank you so much for sharing your findings. That would be great to confirm it won't cause similar issues in the future.

In the meantime, I applied all the necessary changes to make CI happy. I think it's a good improvement on its own as it allows us to keep only the file with combined assets for production to ensure that they never differ between platforms.

@ockham
Copy link
Contributor

ockham commented Sep 22, 2022

I'll be investigating further in cooperation with @ockham

Thank you so much for sharing your findings. That would be great to confirm it won't cause similar issues in the future.

Update: @jsnajdr prepared a minimal test case that I ran on Windows. He'll use the results to file a bug report against Webpack.

Copy link
Contributor

@ockham ockham left a comment

Choose a reason for hiding this comment

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

Thank you @gziolo! LGTM :shipit:

@jsnajdr
Copy link
Member

jsnajdr commented Sep 23, 2022

Webpack bug reported here: webpack/webpack#16289

@gziolo
Copy link
Member Author

gziolo commented Sep 23, 2022

@gziolo gziolo closed this Sep 23, 2022
@gziolo gziolo deleted the update/combined-assets-improved branch September 23, 2022 08:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
3 participants