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

Initial flag does not take into account lazy loading #400

Closed
skovhus opened this issue Dec 17, 2024 · 7 comments
Closed

Initial flag does not take into account lazy loading #400

skovhus opened this issue Dec 17, 2024 · 7 comments
Assignees
Labels
bug Something isn't working

Comments

@skovhus
Copy link

skovhus commented Dec 17, 2024

Currently the plugin detects if a chunk is initial based on the [isDynamicEntry information from rollup](https://github.com/relative-ci/rollup-plugin-webpack-stats/blob/master/src/transform.ts#L140). This is a pretty broken heuristic as a chunk might be synchronously imported by a chunk that is dynamic.

Example

A (initial) lazy loads B that synchronously loads C.

Expected: C should not be marked initial
Currently: C is marked as initial

@vio vio added the bug Something isn't working label Dec 18, 2024
@vio vio self-assigned this Dec 18, 2024
@vio
Copy link
Member

vio commented Dec 18, 2024

@skovhus thanks for checking and for opening the issue!

rollup doesn't provide the initial field and atm we are only using the chunk isDynamicEntry property. We will need to build the chunks dependency tree to detect the async status for a 2nd level chunk. Rollup provides data that can allow us to build the tree, we will have a look in the following days.

In the meantime, if you need to fix the data for specific chunks, you can use the transform option: https://github.com/relative-ci/rollup-plugin-webpack-stats?tab=readme-ov-file#vitejs---update-initial-flag-for-chunks-where-the-inital-flag-is-incorrectly-set-to-false

@skovhus
Copy link
Author

skovhus commented Dec 18, 2024

Yeah we are already using the transform to traverse our tree of dependencies and correct all initial flags. Great that you added lower level Rollup sources to that function.

@vio
Copy link
Member

vio commented Dec 23, 2024

@skovhus, we are testing a fix on [email protected]. The initial flag is now looked up based on the issuer chunks, so if a chunk is synchronously loaded by an async chunk, it is flagged as not initial.

Let me know how it goes if you get the chance to try it. If you notice any issues, it would be very helpful if you could share the rollup stats JSON file(rollup-plugin-stats - no sources by default, you can send it as an attachment to the email address listed on my profile).

@vio
Copy link
Member

vio commented Jan 13, 2025

The changes are now available on v2.0.0-beta.6, currently testing it with couple larger projects. Please let us know how it looks if you manage to try it.

image

@vio
Copy link
Member

vio commented Jan 21, 2025

Changes available on [email protected]. Feel free to reopen in case you still have issues.

@vio vio closed this as completed Jan 21, 2025
@skovhus
Copy link
Author

skovhus commented Jan 21, 2025

Thanks!

We ended up with a custom implementation, but I'll have a look at this next time we touch this.

@vio
Copy link
Member

vio commented Jan 22, 2025

Great! Let us know how it goes when you get the chance to update it ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants