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

chore(@automattic/composite-checkout): Update webpack-dev-server #49183

Merged
merged 2 commits into from
Feb 16, 2021

Conversation

scinos
Copy link
Contributor

@scinos scinos commented Jan 22, 2021

Changes proposed in this Pull Request

  • Uses a version of webpack-dev-server compatible with webpack 5

Changelog

Testing instructions

  • Checkout this branch and run composite-checkout-demo. Verify http://localhost:3000 loads without problems.

@scinos scinos requested a review from a team as a code owner January 22, 2021 11:29
@matticbot
Copy link
Contributor

@matticbot matticbot added the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Jan 22, 2021
@scinos scinos requested a review from a team January 22, 2021 11:29
@scinos scinos self-assigned this Jan 22, 2021
@matticbot
Copy link
Contributor

matticbot commented Jan 22, 2021

Here is how your PR affects size of JS and CSS bundles shipped to the user's browser:

App Entrypoints (~69 bytes removed 📉 [gzipped])

name                   parsed_size           gzip_size
entry-main                  -105 B  (-0.0%)      -29 B  (-0.0%)
entry-login                 -105 B  (-0.0%)      -27 B  (-0.0%)
entry-gutenboarding         -105 B  (-0.0%)      -25 B  (-0.0%)
entry-domains-landing       -105 B  (-0.0%)      -33 B  (-0.0%)

Common code that is always downloaded and parsed every time the app is loaded, no matter which route is used.

Legend

What is parsed and gzip size?

Parsed Size: Uncompressed size of the JS and CSS files. This much code needs to be parsed and stored in memory.
Gzip Size: Compressed size of the JS and CSS files. This much data needs to be downloaded over network.

Generated by performance advisor bot at iscalypsofastyet.com.

@scinos scinos marked this pull request as draft January 22, 2021 11:33
@scinos
Copy link
Contributor Author

scinos commented Jan 22, 2021

Moved to [draft] until I understand why the increase in bundle size

Copy link
Member

@sirbrillig sirbrillig left a comment

Choose a reason for hiding this comment

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

This looks fine in general. Let me know if I can help!

@scinos scinos force-pushed the update/webpack-dev-server-4.0.0-beta branch from 414fdc0 to 9c80a9a Compare January 26, 2021 09:50
@scinos scinos marked this pull request as ready for review January 27, 2021 05:10
@scinos scinos force-pushed the update/webpack-dev-server-4.0.0-beta branch from 9c80a9a to f600247 Compare January 27, 2021 08:17
@scinos scinos changed the title [@automattic/composite-checkout] Update webpack-dev-server chore(@automattic/composite-checkout): Update webpack-dev-server Jan 28, 2021
Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

Seems to need a rebase. Also, any finds as to where the bundle changes came from?

@scinos scinos force-pushed the update/webpack-dev-server-4.0.0-beta branch from f600247 to 1399edd Compare February 15, 2021 05:51
@scinos
Copy link
Contributor Author

scinos commented Feb 15, 2021

Also, any finds as to where the bundle changes came from?

Yes! And it is rather interesting:

  • Before webpack 5 - Webpack 4 uses its own set of polyfills for node modules. So when a package does require("util"), webpack bundled its own polyfill. As util is a node module, many packages don't have an explicit dependency on util in their package.json.

  • With webpack 5 (i.e. trunk) - Webpack doesn't include those polyfills anymore, is up to the consumer to install them. Because we have some packages depending on util (from https://github.com/browserify/node-util), we end up having [email protected] in node_modules/util, and that's the version webpack will use to polyfill require("util").

  • With this PR - webpack-dev-server brings in a new util version that gets hoisted, and now node_modules/util points to [email protected]. That's the version webpack will use to polyfill require("util"). As such, any bundle that were doing require("util") will now use a different version of util. This new version of util is bigger because it has more dependencies, therefore the bundlers are bigger.


I think the new situation is correct: webpack uses the latest util to polyfill require('util'). But I don't like that it happens by accident: if yarn decides to hoist an older version of util, bundle sizes will change again for no apparent reason.

Probably the solution (as hinted in browserify/node-util#57) is to have a explicit alias in webpack config, making sure util is always resolved to a specific version and not to whatever happens to get hoisted.

/cc @jsnajdr

@jsnajdr
Copy link
Member

jsnajdr commented Feb 15, 2021

have a explicit alias in webpack config, making sure util is always resolved to a specific version

Yes, we already have a similar alias for some @wordpress/* packages (see also #48162).

But where does that require( 'util' ) come from? I can't find any util import in the Calypso codebase itself. So is it some third party package?

Using Node packages in browser code is undesired and should be eliminated if possible.

@scinos
Copy link
Contributor Author

scinos commented Feb 15, 2021

But where does that require( 'util' ) come from? I can't find any util import in the Calypso codebase itself. So is it some third party package?

The one I found comes via ./state/utils/schema-utils.js -> node_modules/is-my-json-valid/index.js -> node_modules/generate-function/index.js -> node_modules/util/util.js

@jsnajdr
Copy link
Member

jsnajdr commented Feb 15, 2021

@scinos and npm run whybundled tells me that's actually the only place where the util module is used:

 MODULE  util
├─ imported: 1 time
├─ deps count: 1
├─ size: 20 KiB [for all included files]
├─ type: [transitive]
│  └─ util -> generate-function -> is-my-json-valid
│  
├─ chunks: vendors-node_modules_uuid_dist_esm-browser_v4_js-node_modules_crc32_lib_crc32_js-node_modules-26c5b7
├─ locations: 
│  └─ ../node_modules/util/
│  
├─ files: 
│  ├─ ../node_modules/util/support/isBufferBrowser.js
│  └─ ../node_modules/util/util.js
│  
└─ reasons:
   └─ generate-function
      └─ ../node_modules/generate-function/index.js  1:11-26  [cjs require]

@scinos scinos force-pushed the update/webpack-dev-server-4.0.0-beta branch from 1399edd to 1f1993e Compare February 16, 2021 05:05
@scinos scinos requested a review from tyxla February 16, 2021 05:22
@scinos
Copy link
Contributor Author

scinos commented Feb 16, 2021

Update: A different PR was created and merged to fix the version of util (#50074). As expected, that PR increased bundle size. Now that it is in trunk, this PR doesn't change bundle size in a significant way anymore.

Copy link
Member

@tyxla tyxla left a comment

Choose a reason for hiding this comment

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

There might be some candidates for deduping, but can be done in subsequent PRs. This looks good and works as expected 🚢

version "0.11.3"
resolved "https://registry.yarnpkg.com/faye-websocket/-/faye-websocket-0.11.3.tgz#5c0e9a8968e8912c286639fde977a8b209f2508e"
integrity sha512-D2y4bovYpzziGgbHYtGCMjlJM36vAl/y+xUyn1C+FVx8szd1E+86KwVw6XvYSzOP8iMpm1X0I4xJD+QtUb36OA==
dependencies:
websocket-driver ">=0.5.1"

faye-websocket@~0.10.0:
Copy link
Member

Choose a reason for hiding this comment

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

Could this one use some deduping?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for checking :) In this case, ~0.10.0 and ^0.11.3 don't overlap.

I've found https://semver.npmjs.com/ really useful to verify what versions can satisfy a range.

resolved "https://registry.yarnpkg.com/fsevents/-/fsevents-2.3.1.tgz#b209ab14c61012636c8863507edf7fb68cc54e9f"
integrity sha512-YR47Eg4hChJGAB1O3yEAOkGO+rlzutoICGqGo9EZ4lKWokzZRSyIW1QmTzqjtw8MJdj9srP869CuWw/hyzSiBw==

fsevents@~2.1.2:
Copy link
Member

Choose a reason for hiding this comment

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

Seems like this could use some deduping?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same, ~2.1.2 and ~2.3.1 (or ^2.1.2) don't overlap

@scinos scinos merged commit 5e25828 into trunk Feb 16, 2021
@scinos scinos deleted the update/webpack-dev-server-4.0.0-beta branch February 16, 2021 13:57
@matticbot matticbot removed the [Status] Needs Review The PR is ready for review. This also triggers e2e canary tests and wp-desktop tests automatically. label Feb 16, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants