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
Do not merge isolated bundles in experimental bundler #8566
Merged
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -511,9 +511,8 @@ function createIdealGraph( | |
let bundleGroupRootAsset = nullthrows(bundleGroup.mainEntryAsset); | ||
if ( | ||
entries.has(bundleGroupRootAsset) && | ||
bundleGroupRootAsset.type === childAsset.type && | ||
childAsset.bundleBehavior !== 'inline' && | ||
dependency.bundleBehavior !== 'isolated' | ||
canMerge(bundleGroupRootAsset, childAsset) && | ||
dependency.bundleBehavior == null | ||
) { | ||
bundleId = bundleGroupNodeId; | ||
} | ||
|
@@ -523,7 +522,8 @@ function createIdealGraph( | |
asset: childAsset, | ||
type: childAsset.type, | ||
env: childAsset.env, | ||
bundleBehavior: childAsset.bundleBehavior, | ||
bundleBehavior: | ||
dependency.bundleBehavior ?? childAsset.bundleBehavior, | ||
target: referencingBundle.target, | ||
needsStableName: | ||
childAsset.bundleBehavior === 'inline' || | ||
|
@@ -534,8 +534,15 @@ function createIdealGraph( | |
: referencingBundle.needsStableName, | ||
}); | ||
bundleId = bundleGraph.addNode(bundle); | ||
|
||
// Store Type-Change bundles for later since we need to know ALL bundlegroups they are part of to reduce/combine them | ||
typeChangeIds.add(bundleId); | ||
if (parentAsset.type !== childAsset.type) { | ||
typeChangeIds.add(bundleId); | ||
} | ||
} else { | ||
bundle = bundleGraph.getNode(bundleId); | ||
invariant(bundle != null && bundle !== 'root'); | ||
|
||
if ( | ||
// If this dependency requests isolated, but the bundle is not, | ||
// make the bundle isolated for all uses. | ||
|
@@ -544,10 +551,6 @@ function createIdealGraph( | |
) { | ||
bundle.bundleBehavior = dependency.bundleBehavior; | ||
} | ||
} else { | ||
// Otherwise, merge. | ||
bundle = bundleGraph.getNode(bundleId); | ||
invariant(bundle != null && bundle !== 'root'); | ||
} | ||
|
||
bundles.set(childAsset.id, bundleId); | ||
|
@@ -603,9 +606,7 @@ function createIdealGraph( | |
b !== 'root' && | ||
a !== b && | ||
typeChangeIds.has(nodeIdB) && | ||
a.bundleBehavior !== 'inline' && | ||
b.bundleBehavior !== 'inline' && | ||
a.type === b.type | ||
canMerge(a, b) | ||
) { | ||
let bundleBbundleGroups = getBundleGroupsForBundle(nodeIdB); | ||
if (setEqual(bundleBbundleGroups, bundleABundleGroups)) { | ||
|
@@ -670,8 +671,9 @@ function createIdealGraph( | |
); | ||
if ( | ||
bundle !== 'root' && | ||
bundle.bundleBehavior !== 'inline' && | ||
!bundle.env.isIsolated() | ||
bundle.bundleBehavior == null && | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line is what caused the test change, where a bundle was previously internalized and now isn't. I think in the general case, however, that isolated bundles should not be reachable. |
||
!bundle.env.isIsolated() && | ||
bundle.env.context === root.env.context | ||
) { | ||
bundleRootGraph.addEdge( | ||
bundleRootGraph.getNodeIdByContentKey(root.id), | ||
|
@@ -691,11 +693,7 @@ function createIdealGraph( | |
} | ||
//asset node type | ||
let asset = node.value; | ||
if ( | ||
asset.bundleBehavior === 'isolated' || | ||
asset.bundleBehavior === 'inline' || | ||
root.type !== asset.type | ||
) { | ||
if (asset.bundleBehavior != null || root.type !== asset.type) { | ||
actions.skipChildren(); | ||
return; | ||
} | ||
|
@@ -748,10 +746,7 @@ function createIdealGraph( | |
]) { | ||
let bundleInGroup = nullthrows(bundleGraph.getNode(bundleIdInGroup)); | ||
invariant(bundleInGroup !== 'root'); | ||
if ( | ||
bundleInGroup.bundleBehavior === 'isolated' || | ||
bundleInGroup.bundleBehavior === 'inline' | ||
) { | ||
if (bundleInGroup.bundleBehavior != null) { | ||
continue; | ||
} | ||
|
||
|
@@ -784,7 +779,7 @@ function createIdealGraph( | |
let child = bundleRootGraph.getNode(childId); | ||
invariant(child !== 'root' && child != null); | ||
let bundleBehavior = getBundleFromBundleRoot(child).bundleBehavior; | ||
if (bundleBehavior === 'isolated' || bundleBehavior === 'inline') { | ||
if (bundleBehavior != null) { | ||
continue; | ||
} | ||
let isParallel = bundleRootGraph.hasEdge( | ||
|
@@ -1345,3 +1340,14 @@ function getEntryByTarget( | |
}); | ||
return targets; | ||
} | ||
|
||
function canMerge(a, b) { | ||
// Bundles can be merged if they have the same type and environment, | ||
// unless they are explicitly marked as isolated or inline. | ||
return ( | ||
a.type === b.type && | ||
a.env.context === b.env.context && | ||
a.bundleBehavior == null && | ||
b.bundleBehavior == null | ||
); | ||
} |
This file contains 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
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.
Speaking of fixes, I notice in the default bundler we maintain
bundleByType
, which not only holds bundles created via type change, but also all others (lazy/ parallel etc). It looks like that is how we determine where we can merge a type change bundle.In experimental, we only attempt to merge type change with type change.... does this mean we're not merging as many bundles as we could in experimental ?
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.
I think we should not merge parallel/lazy bundles, because the transformer that created those dependencies might not expect it. For example, if you have two
<script>
tags in an HTML page, those have parallel priority, but merging them would result in both scripts pointing to the same URL and (possibly?) executing twice.