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

Use stable ids in names of inline bundles #4188

Closed
wants to merge 1 commit into from

Conversation

padmaia
Copy link
Contributor

@padmaia padmaia commented Feb 20, 2020

↪️ Pull Request

Fixes #4145

The issue was caused by a bundle that contained a hash reference to an inline parent bundle, which is something I didn't anticipate, but is apparently needed for scope hoisting. @devongovett @mischnic Is this expected?

See below for a visual of the bundle graph. In this case the blue bundle is referencing the pink bundle.

bundle_graph

To fix this, I changed the default namer to not use content hash references in inline bundle names. It still uses some characters of the bundle id to ensure uniqueness. This seems like a safe option since inline bundles are not served by themselves so their names do not need to be long term cacheable.

🚨 Test instructions

Reproduced the failure in the linked issue and tested that the changes were able to build the code successfully. We should probably add some integration tests, but I wanted to make sure that this scenario is expected.

✔️ PR Todo

  • Probably add some integration tests

@@ -91,7 +91,8 @@ export default new Namer({
// `index.css`.
let name = nameFromContent(mainBundle, options.rootDir);
if (!bundle.isEntry) {
name += '.' + bundle.hashReference;
let hash = bundle.isInline ? bundle.id.slice(-8) : bundle.hashReference;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: inline below?

@parcel-benchmark
Copy link

Benchmark Results

packages/benchmarks/kitchen-sink ✅

Timings

Description Time Difference
Cold 3.50s -1.47s 🚀
Cached 3.05s -302.00ms 🚀

Cold Bundles

Bundle Size Difference Time Difference
dist/parcel.d5807e82.webp 102.94kb +0.00b 77.00ms -850.00ms 🚀
dist/index.js 1.07kb +5.00b ⚠️ 184.00ms -750.00ms 🚀

Cached Bundles

Bundle Size Difference Time Difference
dist/parcel.d5807e82.webp 102.94kb +0.00b 1.00ms -2.00ms 🚀
dist/index.js 1.07kb +5.00b ⚠️ 5.00ms -0.00ms

packages/benchmarks/react-hn ✅

Timings

Description Time Difference
Cold 7.51s -389.00ms 🚀
Cached 3.35s -131.00ms

Cold Bundles

Bundle Size Difference Time Difference
dist/index.js 64.04kb +397.00b ⚠️ 1.09s -100.00ms 🚀

Cached Bundles

Bundle Size Difference Time Difference
dist/index.js 64.04kb +397.00b ⚠️ 272.00ms +267.00ms ⚠️

packages/benchmarks/ak-editor ✅

Timings

Description Time Difference
Cold 3.64s -852.00ms 🚀
Cached 3.50s +373.00ms ⚠️

Cold Bundles

Bundle Size Difference Time Difference
dist/index.js 743.00b +7.00b ⚠️ 158.00ms -821.00ms 🚀

Cached Bundles

Bundle Size Difference Time Difference
dist/index.js 743.00b +7.00b ⚠️ 6.00ms -0.00ms

Click here to view a detailed benchmark overview.

Copy link
Member

@mischnic mischnic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just tested this with the repro in the linked issue, but I think the issue is bigger:

The blue JS bundle imports the pink JS bundle, but the pink JS bundle is inlined into the HTML asset, so it actually cannot be imported.

<!-- index.html -->
<script type="module">
	export var $d8762107a9da24ea5810e689596fa963$exports = {};

	// ...
	import("" + "./options.6b63f96a.js");
</script>
// options.6b63f96a.js
import { $d8762107a9da24ea5810e689596fa963$exports } 
  from "./4145-hashReferences-scope-hoist.1370e440.js"; // the inline bundle above, doesn't exist
console.log("options", $d8762107a9da24ea5810e689596fa963$exports.default);

@padmaia
Copy link
Contributor Author

padmaia commented Feb 20, 2020

@mischnic Yeah that seemed weird to me, that's why I asked if it was expected. So it's scope hoisting bug? Should it be importing the bundle that contains the inline bundle instead?

@mischnic
Copy link
Member

mischnic commented Feb 20, 2020

So it's scope hoisting bug?

And/or a bundler bug...

Should it be importing the bundle that contains the inline bundle instead?

importing a html file doesn't work, so one option would be to emit a new bundle with the shared assets.

@padmaia
Copy link
Contributor Author

padmaia commented Mar 4, 2020

I am going to close this as the right solution is probably to not name inline bundles at all (See #4172)

@padmaia padmaia closed this Mar 4, 2020
@mischnic mischnic deleted the fix-hash-references-to-inline-bundles branch March 4, 2020 19:20
@mischnic mischnic restored the fix-hash-references-to-inline-bundles branch March 4, 2020 19:20
@mischnic mischnic deleted the fix-hash-references-to-inline-bundles branch August 17, 2020 10:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Error: Cannot read property 'hashReferences' of undefined
4 participants