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
Changes from 2 commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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,16 @@ 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 { | ||
// Otherwise, merge. | ||
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 is my mistake, but this comment doesn't make sense here anymore since we don't merge until later |
||
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 +552,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 +607,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 +672,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 +694,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 +747,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 +780,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 +1341,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 | ||
); | ||
} |
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.