-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Turbopack: inner graph tree shaking #85973
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
90b7b38
Add config
mischnic fa9f546
Add test
mischnic 87a0169
NODE_ENV = "production" in execution tests
mischnic 68ecfa2
Import Webpack tests
mischnic 9458f6f
Add client reference tree shaking test
mischnic 71b3096
WIP
mischnic 93ed60f
fixup
mischnic fed488e
fixup
mischnic File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
basegraph in the returnedBaseAndFullModuleGraphstruct is not having unused references removed whenturbopack_remove_unused_importsis enabled, creating inconsistency with how it's handled inproject.rs.View Details
📝 Patch Details
Analysis
Inconsistent binding_usage info in per-page module graphs causes incorrect graph traversals when
turbopack_remove_unused_importsis enabledWhat fails: The
basegraph inBaseAndFullModuleGraphreturned fromAppProject::module_graphs_for_endpoint()does not have unused references removed whenturbopack_remove_unused_importsis enabled, while the whole-app version does. This causes graph traversals that useiter_graphs_neighbors_rev()(such as inNextDynamicGraph::get_next_dynamic_imports_for_endpoint()andClientReferencesGraph::get_client_references_for_endpoint()) to produce inconsistent results depending on which code path is used.How to reproduce:
turbopack_remove_unused_importsin next.config.jsper_page_module_graphsetting)What happens: Graph traversals like
traverse_edges_from_entries_dfs()andtraverse_nodes_from_entries_dfs()called duringget_next_dynamic_imports_for_endpoint()andget_client_references_for_endpoint()useiter_graphs_neighbors_rev()which filters out edges marked as unused viabinding_usageinfo. In the whole-app path (project.rs, lines 1996-2006), thebasegraph has binding_usage info set viawithout_unused_references(). In the per-page path (app.rs, lines 945-980), thebasegraph does NOT have this binding_usage info, causing the graph traversals to include edges that should be skipped.Expected behavior: The
basefield inBaseAndFullModuleGraphshould have consistent binding_usage info regardless of whether the whole-app or per-page code path is used. Whenturbopack_remove_unused_importsis enabled, binding_usage should be set on the base graph in both cases so that subsequent graph traversals produce consistent results.Reference: