Fix duplicate asset references#9109
Conversation
lettertwo
left a comment
There was a problem hiding this comment.
Nice one! Looks good to me.
|
|
||
| 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.
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.
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.
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.
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.
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