Skip to content
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

Merged
merged 4 commits into from
Jul 31, 2023
Merged

Conversation

mattcompiles
Copy link
Contributor

↪️ 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

  • Added/updated unit tests for this change
  • Filled out test instructions (In case there aren't any unit tests)
  • Included links to related issues/PRs

Copy link
Member

@lettertwo lettertwo left a 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) {
Copy link
Member

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.

Copy link
Contributor Author

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.

Copy link
Member

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

Copy link
Contributor Author

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?

Copy link
Member

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.

@mischnic
Copy link
Member

I do wonder if this should just be a part of the if condition in the scopehoisting packager, instead of changing the bundlegraph method.

@mattcompiles
Copy link
Contributor Author

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.

@parcel-benchmark
Copy link

Benchmark Results

Kitchen Sink ✅

Timings

Description Time Difference
Cold 1.43s -55.00ms
Cached 272.00ms +29.00ms ⚠️

Cold Bundles

Bundle Size Difference Time Difference
dist/legacy/parcel.7cdb0fad.webp 102.94kb +0.00b 221.00ms -28.00ms 🚀
dist/legacy/parcel.7cdb0fad.webp 102.94kb +0.00b 229.00ms -21.00ms 🚀
dist/modern/parcel.7cdb0fad.webp 102.94kb +0.00b 228.00ms -23.00ms 🚀
dist/legacy/index.7d75205b.js 1.63kb +0.00b 319.00ms -44.00ms 🚀
dist/legacy/index.d20f91ee.js 1.19kb +0.00b 319.00ms -44.00ms 🚀
dist/modern/index.1ee30fe4.js 1.12kb +0.00b 319.00ms -44.00ms 🚀
dist/legacy/index.html 826.00b +0.00b 340.00ms -60.00ms 🚀
dist/modern/index.html 749.00b +0.00b 340.00ms -59.00ms 🚀
dist/legacy/index.b8ae99ba.css 94.00b +0.00b 230.00ms -30.00ms 🚀
dist/modern/index.31cedca9.css 94.00b +0.00b 230.00ms -31.00ms 🚀

Cached Bundles

Bundle Size Difference Time Difference
dist/legacy/parcel.7cdb0fad.webp 102.94kb +0.00b 219.00ms -11.00ms 🚀
dist/modern/parcel.7cdb0fad.webp 102.94kb +0.00b 220.00ms -11.00ms

React HackerNews ✅

Timings

Description Time Difference
Cold 3.94s -34.00ms
Cached 362.00ms -15.00ms

Cold Bundles

Bundle Size Difference Time Difference
dist/PermalinkedComment.b41e2791.js 4.07kb +0.00b 371.00ms +61.00ms ⚠️
dist/UserProfile.2a2fa310.js 1.51kb +0.00b 371.00ms +62.00ms ⚠️
dist/NotFound.13a965e5.js 399.00b +0.00b 371.00ms +62.00ms ⚠️
dist/logo.8dd07848.png 244.00b +0.00b 257.00ms -16.00ms 🚀

Cached Bundles

Bundle Size Difference Time Difference
dist/index.js 460.80kb +0.00b 941.00ms -55.00ms 🚀
dist/logo.8dd07848.png 244.00b +0.00b 271.00ms -51.00ms 🚀

AtlasKit Editor ✅

Timings

Description Time Difference
Cold 34.09s -1.02s
Cached 2.01s +41.00ms

Cold Bundles

Bundle Size Difference Time Difference
dist/pdfRenderer.488477b0.js 1.11mb +0.00b 11.01s -597.00ms 🚀
dist/media-viewer.6b8adda1.js 537.45kb +0.00b 10.44s +2.35s ⚠️
dist/ConfigPanelFieldsLoader.54b2cecc.js 306.94kb +0.00b 7.36s -733.00ms 🚀
dist/card.583a1f18.js 140.31kb +0.00b 7.36s -733.00ms 🚀
dist/ElementBrowser.8e866a0e.js 62.33kb +0.00b 7.36s -734.00ms 🚀
dist/archive.a2217524.js 60.29kb +0.00b 10.46s +2.37s ⚠️
dist/esm.1a044825.js 59.85kb +0.00b 7.36s -733.00ms 🚀
dist/DatePicker.9c23032b.js 47.98kb +0.00b 5.20s -349.00ms 🚀
dist/DatePicker.a3ad9fca.js 25.15kb +0.00b 5.20s -349.00ms 🚀
dist/ConfigPanelFieldsLoader.3cdf42ed.js 15.95kb +0.00b 7.36s -734.00ms 🚀
dist/ui.f919792f.js 14.62kb +0.00b 7.36s -734.00ms 🚀
dist/ConfigPanelFieldsLoader.0c1e88b7.js 13.78kb +0.00b 7.36s -734.00ms 🚀
dist/pdfRenderer.187ba54d.js 12.21kb +0.00b 7.39s -706.00ms 🚀
dist/mobile-upload.41e1ddfc.js 7.99kb +0.00b 7.36s -734.00ms 🚀
dist/mobile-upload.f2b8a53f.js 7.99kb +0.00b 7.36s -733.00ms 🚀
dist/media-viewer-analytics-error-boundary.c1511b0d.js 3.32kb +0.00b 10.46s +2.37s ⚠️
dist/ru.896915b9.js 2.94kb +0.00b 7.36s +1.81s ⚠️
dist/uk.48c97550.js 2.89kb +0.00b 7.36s -733.00ms 🚀
dist/codeViewerRenderer.f99075be.js 2.74kb +0.00b 7.39s -705.00ms 🚀
dist/th.31044730.js 2.73kb +0.00b 7.36s -733.00ms 🚀
dist/ResourcedEmojiComponent.1ec35575.js 2.60kb +0.00b 5.20s -348.00ms 🚀
dist/pl.5f36d63e.js 2.38kb +0.00b 5.20s -349.00ms 🚀
dist/cs.971d1d60.js 2.36kb +0.00b 5.20s -350.00ms 🚀
dist/de.6efbb375.js 2.30kb +0.00b 5.20s -350.00ms 🚀
dist/fr.af2c92ae.js 2.25kb +0.00b 5.20s -348.00ms 🚀
dist/es.23f0c164.js 2.25kb +0.00b 5.20s -348.00ms 🚀
dist/hu.8323f36b.js 2.23kb +0.00b 5.20s -348.00ms 🚀
dist/fi.7ed4b1b5.js 2.22kb +0.00b 5.20s -348.00ms 🚀
dist/ja.5653161c.js 2.22kb +0.00b 5.20s -348.00ms 🚀
dist/vi.d8dcb67a.js 2.22kb +0.00b 7.36s -733.00ms 🚀
dist/pt_BR.eccfad73.js 2.19kb +0.00b 5.20s -349.00ms 🚀
dist/tr.46f26598.js 2.16kb +0.00b 7.36s -733.00ms 🚀
dist/ko.2cf2bbda.js 2.11kb +0.00b 5.20s -349.00ms 🚀
dist/sv.13d93533.js 2.10kb +0.00b 7.36s -733.00ms 🚀
dist/it.601d375a.js 2.10kb +0.00b 5.20s -349.00ms 🚀
dist/nb.b300dd3e.js 2.09kb +0.00b 5.20s -349.00ms 🚀
dist/da.21385cf2.js 2.07kb +0.00b 5.20s -350.00ms 🚀
dist/nl.3999ea58.js 2.07kb +0.00b 5.20s -349.00ms 🚀
dist/zh_TW.afaf6222.js 1.98kb +0.00b 7.36s -733.00ms 🚀
dist/zh.fcdc32bb.js 1.96kb +0.00b 7.36s -734.00ms 🚀
dist/feedback.fd1f6260.js 1.89kb +0.00b 5.20s -348.00ms 🚀
dist/workerHasher.4b89e1de.js 1.69kb +0.00b 7.36s -733.00ms 🚀
dist/workerHasher.06536d4e.js 1.69kb +0.00b 7.36s -733.00ms 🚀
dist/heading6.974f167d.js 1.49kb +0.00b 5.20s -348.00ms 🚀
dist/heading5.023a8f1f.js 1.36kb +0.00b 5.20s -272.00ms 🚀
dist/expand.801fc3a0.js 1.31kb +0.00b 5.20s -348.00ms 🚀
dist/sk.101f1705.js 786.00b +0.00b 7.36s -452.00ms 🚀
dist/pt_PT.402f9c4e.js 765.00b +0.00b 5.20s -349.00ms 🚀
dist/et.69382942.js 763.00b +0.00b 5.20s -348.00ms 🚀
dist/simpleHasher.8b7def87.js 719.00b +0.00b 7.36s -734.00ms 🚀
dist/simpleHasher.38195df7.js 719.00b +0.00b 7.36s -733.00ms 🚀
dist/is.5b945719.js 625.00b +0.00b 5.20s -348.00ms 🚀
dist/ro.a6eff34a.js 612.00b +0.00b 5.20s -349.00ms 🚀
dist/en_GB.61f7112a.js 602.00b +0.00b 5.20s -349.00ms 🚀
dist/en.41261459.js 599.00b +0.00b 5.20s -349.00ms 🚀
dist/index.html 240.00b +0.00b 10.50s +5.72s ⚠️

Cached Bundles

Bundle Size Difference Time Difference
dist/refractor.c460668c.js 601.81kb +0.00b 9.77s -639.00ms 🚀
dist/media-viewer.6b8adda1.js 537.45kb +0.00b 9.78s -640.00ms 🚀
dist/popup.c282bed0.js 324.59kb +0.00b 9.77s -639.00ms 🚀
dist/EmojiPickerComponent.1a5571cb.js 189.81kb +0.00b 9.68s -730.00ms 🚀
dist/ConfigPanelFieldsLoader.d25d4efc.js 83.10kb +0.00b 9.68s -707.00ms 🚀
dist/esm.1c9ef78b.js 63.49kb +0.00b 9.77s -640.00ms 🚀
dist/archive.a2217524.js 60.29kb +0.00b 9.78s -640.00ms 🚀
dist/component-lazy.1b33c14d.js 59.63kb +0.00b 5.17s +450.00ms ⚠️
dist/esm.3fa8c7de.js 39.56kb +0.00b 9.78s -639.00ms 🚀
dist/smartMediaEditor.0fdaaac3.js 21.89kb +0.00b 9.78s -639.00ms 🚀
dist/esm.699bbabf.js 20.65kb +0.00b 9.78s -639.00ms 🚀
dist/dropzone.7e088531.js 13.61kb +0.00b 9.78s -639.00ms 🚀
dist/pdfRenderer.187ba54d.js 12.21kb +0.00b 9.68s +620.00ms ⚠️
dist/dropzone.09d0b890.js 11.64kb +0.00b 9.78s -639.00ms 🚀
dist/Toolbar.7b6f497e.js 9.53kb +0.00b 9.79s -629.00ms 🚀
dist/clipboard.f5f3497c.js 8.07kb +0.00b 9.78s -639.00ms 🚀
dist/mobile-upload.40a8f0fb.js 7.99kb +0.00b 9.78s -639.00ms 🚀
dist/browser.333a8efe.js 7.33kb +0.00b 9.77s -640.00ms 🚀
dist/index.7deb84cc.js 7.32kb +0.00b 9.79s -629.00ms 🚀
dist/index.b16227d6.css 4.08kb +0.00b 9.79s -634.00ms 🚀
dist/media-viewer-analytics-error-boundary.c1511b0d.js 3.32kb +0.00b 9.78s -640.00ms 🚀
dist/media-picker-analytics-error-boundary.418c2c46.js 3.32kb +0.00b 9.78s -639.00ms 🚀
dist/media-card-analytics-error-boundary.7d513b72.js 3.32kb +0.00b 9.78s -639.00ms 🚀
dist/codeViewerRenderer.f99075be.js 2.74kb +0.00b 9.78s +714.00ms ⚠️
dist/ko.2cf2bbda.js 2.11kb +0.00b 5.17s -1.10s 🚀
dist/nl.3999ea58.js 2.07kb +0.00b 5.17s -1.10s 🚀
dist/workerHasher.dd4d2a38.js 1.69kb +0.00b 9.77s -640.00ms 🚀
dist/workerHasher.eae92e5c.js 1.69kb +0.00b 9.78s -639.00ms 🚀
dist/workerHasher.cfe5994f.js 1.69kb +0.00b 9.78s -639.00ms 🚀
dist/heading3.9ad47cbe.js 1.48kb +0.00b 5.16s +436.00ms ⚠️
dist/heading2.bffcdf12.js 1.30kb +0.00b 5.16s +435.00ms ⚠️
dist/heading4.05995ed9.js 1.25kb +0.00b 5.16s +436.00ms ⚠️
dist/pt_PT.402f9c4e.js 765.00b +0.00b 6.72s +447.00ms ⚠️
dist/simpleHasher.308c3a38.js 719.00b +0.00b 9.78s -639.00ms 🚀
dist/simpleHasher.f29b9a84.js 719.00b +0.00b 9.78s -639.00ms 🚀
dist/simpleHasher.d2c7eaf0.js 719.00b +0.00b 9.78s -639.00ms 🚀
dist/ro.a6eff34a.js 612.00b +0.00b 6.84s +560.00ms ⚠️
dist/index.html 240.00b +0.00b 9.82s -638.00ms 🚀

Three.js ✅

Timings

Description Time Difference
Cold 3.05s +43.00ms
Cached 302.00ms -7.00ms

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

Click here to view a detailed benchmark overview.

@mattcompiles mattcompiles merged commit ce656c2 into v2 Jul 31, 2023
16 checks passed
@mattcompiles mattcompiles deleted the fix-duplicate-asset-references branch July 31, 2023 05:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants