-
Notifications
You must be signed in to change notification settings - Fork 13.5k
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
bug: side effects with reassignment in ionic 6 + webpack, vite #24280
Comments
@ptmkenny can you provide a sample repository reproducing this issue? On an initial look, it doesn't appear the build output is a production build, where the treeshaking happens. |
Thanks for the issue! This issue has been labeled as Please reproduce this issue in an Ionic starter application and provide a way for us to access it (GitHub repo, StackBlitz, etc). Without a reliable code reproduction, it is unlikely we will be able to resolve the issue, leading to it being closed. If you have already provided a code snippet and are seeing this message, it is likely that the code snippet was not enough for our team to reproduce the issue. For a guide on how to create a good reproduction, see our Contributing Guide. |
We've created a few examples locally with Vue and React and have been able to identify a relationship between Stencil version upgrades and bundle size increases. |
Thanks! We identified two issues that are causing treeshaking to not behave as expected.
Treeshaking should be fixed for Webpack 5, Vite, Rollup, ES Build, etc users in the next release of Ionic 6. It should be slightly better for Webpack 4 users, but that |
It's not included in the 6.0.0-rc.4, isn't it? I've noticed significant bundle size increase after Swiper has been added in 6.0.0-rc.3 but this is probably a general problem with tree shaking when using Vite. |
It is included in 6.0.0-rc.4. As I mentioned in #24280 (comment), you should only notice a small improvement at the moment because of the lingering |
@liamdebeasi Thank you for explaining |
Thanks for the updates! @liamdebeasi I updated to Ionic 6.0 official, and since you said Webpack 5 seems to be working, based on the CRA 5 alpha discussion, I updated my Ionic app to CRA5 alpha:
My app builds, and I can use it, but the bundle size is still huge (about 3x what it used to be): This is building with CRA5 alpha, which I understand is now using Webpack 5 under the hood. |
Darn, seems like Webpack 5 is still impacted. Thanks for the additional info! |
Following up on this: This issue is happening due to a bug in Webpack. I have reported the issue here: webpack/webpack#14963 We are investigating potential workarounds and will follow up here when we have more to share. edit Jan 27 2022: This also impacts Vite. See #24655. We have an experimental fix that seems to resolve this issue. I will update this thread when I have more to share. |
Any updates? I noticed while looking at some bundle stuff that my bundle is now much larger since migrating from Ionic 5 + Webpack to Ionic 6 + Vite. Partly because ~30% (341kB uncompressed) of the vendor bundle is related to |
The fix for this was merged into the Stencil codebase recently: ionic-team/stencil@5dccc85 We are waiting on a stable Stencil release before updating Ionic. |
I noticed the change between Ionic 6.0.2 and 6.0.8. Edit: See new comment |
It seems to be a change in Vite that changed the sizes. Vite 2.6.10 + Ionic 6.0.2
Vite 2.6.10 + Ionic 6.0.8
Vite 2.8.4 + Ionic 6.0.2
Vite 2.8.4 + Ionic 6.0.8
|
The change happens in Vite between 2.6.14 (latest 2.6.x) and 2.7.0. |
Relevant change is in Vite 2.7.0-beta.5. Specifically, these changes in - // check for deep import, e.g. "my-lib/foo"
- const deepMatch = nestedPath.match(deepImportRE)
-
- const pkgId = deepMatch ? deepMatch[1] || deepMatch[2] : nestedPath
+ const possiblePkgIds: string[] = []
+ for (let prevSlashIndex = -1; ; ) {
+ let slashIndex = nestedPath.indexOf('/', prevSlashIndex + 1)
+ if (slashIndex < 0) {
+ slashIndex = nestedPath.length
+ }
+
+ const part = nestedPath.slice(
+ prevSlashIndex + 1,
+ (prevSlashIndex = slashIndex)
+ )
+ if (!part) {
+ break
+ }
+
+ // Assume path parts with an extension are not package roots, except for the
+ // first path part (since periods are sadly allowed in package names).
+ // At the same time, skip the first path part if it begins with "@"
+ // (since "@foo/bar" should be treated as the top-level path).
+ if (possiblePkgIds.length ? path.extname(part) : part[0] === '@') {
+ continue
+ }
+
+ const possiblePkgId = nestedPath.slice(0, slashIndex)
+ possiblePkgIds.push(possiblePkgId)
+ } - const pkg = resolvePackageData(pkgId, basedir, options.preserveSymlinks)
+ const pkgId = possiblePkgIds.reverse().find((pkgId) => {
+ pkg = resolvePackageData(pkgId, basedir, options.preserveSymlinks)
+ return pkg
+ }) Removing that
|
Via some more modding of Vite's guts to choose a hardcoded package name for these cases, I've narrowed it down to the change between |
Thanks for the issue. This has been resolved via #24895, and a fix will be available in an upcoming release of Ionic Framework. There are two issues being discussed in this thread:
The linked PR does not do anything to address issue 2 as this is due to a change in Vite, not Ionic. The good news is that this Swiper code is being removed in the next major release of Ionic, so this issue should go away on its own. For now, you may want to consider staying with Vite 2.6.x. Alternatively, you could file an issue on the Vite repo to see if the Vite team is willing to work on a fix. I am going to close this issue. Thanks! |
Thanks for the issue! This issue is being locked to prevent comments that are not relevant to the original issue. If this is still an issue with the latest version of Ionic, please create a new issue and ensure the template is fully filled out. |
Prerequisites
Ionic Framework Version
Current Behavior
I have an Ionic React v5 app that I upgraded to v6. When I did so and inspected the bundle size:
react-scripts build --stats; webpack-bundle-analyzer build/bundle-stats.json
I noticed that the node-modules bundle is now 3x larger (from ~500 kB to 1.4 MB).
Here's my Ionic 5 app bundle:
And here's the Ionic 6 bundle:
The only changes between the code for Ionic v5 and v6 are a few lines to update a datetime component, so these builds are basically identical except for the Ionic version.
Expected Behavior
When upgrading to the next major Ionic version, the bundle size should be roughly the same or smaller than the previous version.
I read in the beta announcement that even smaller bundles are coming to Vue first, and then React and Angular, but I didn't except a massive size increase.
Steps to Reproduce
Update a moderately sized app from v5 to v6.
Code Reproduction URL
No response
Ionic Info
Additional Information
No response
The text was updated successfully, but these errors were encountered: