-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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
Fix duplicate asset references #9109
Conversation
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.
Nice one! Looks good to me.
@@ -1122,6 +1122,11 @@ export default class BundleGraph { | |||
} | |||
|
|||
isAssetReferenced(bundle: Bundle, asset: Asset): boolean { | |||
// If the asset is available in multiple bundles, it's referenced. | |||
if (this.getBundlesWithAsset(asset).length > 1) { |
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.
Just because an asset is in multiple bundles doesn't mean it is referenced between multiple bundles though right? The references could be totally self contained within that bundle.
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.
Does Parcel really know how all assets are going to be loaded though? We have scenrios where we add bundles to HTML dynamically and Parcel isn't aware that the two are linked. I know this isn't ideal, but I feel like we should be resilient to these kinds of issues.
Also check out the test I added, that was failing before I made this fix and that scenario should definitely work IMO.
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.
Right yeah I was more wondering about it because the of the name of the function like Niklas mentioned
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.
Yeah I hear that. I can move it the fix, however I feel like that leaves an issue in isAssetReferenced
. Shouldn't it return true for the scenario I outlined in the test?
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.
depends on the definition of "referenced" I guess. If we mean "this exact instance of an asset is referenced from another bundle", then a duplicated asset wouldn't count. But if we want duplicated assets to behave at runtime like they aren't duplicated, then it would make sense.
I do wonder if this should just be a part of the if condition in the scopehoisting packager, instead of changing the bundlegraph method. |
@mischnic The reason I modified this method was that it's used twice in the scope hoisting packager and nowhere else. I'm happy to move it if we prefer. |
Benchmark ResultsKitchen Sink ✅
Timings
Cold Bundles
Cached Bundles
React HackerNews ✅
Timings
Cold Bundles
Cached Bundles
AtlasKit Editor ✅
Timings
Cold Bundles
Cached Bundles
Three.js ✅
Timings
Cold BundlesNo bundle changes detected. Cached BundlesNo bundle changes detected. |
↪️ Pull Request
It's currently possible that assets can be duplicated but not wrapped in the packager. This causes the duplicated asset to be evaluated more than once and receive a unique module scope.
The fix is to ensure that all duplicated assets return true when when checking if an asset is referenced.
💻 Examples
🚨 Test instructions
Test added
✔️ PR Todo