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

Add manifest V3 true HMR #8145

Merged
merged 14 commits into from
Jun 13, 2022
Merged

Add manifest V3 true HMR #8145

merged 14 commits into from
Jun 13, 2022

Conversation

101arrowz
Copy link
Member

@101arrowz 101arrowz commented May 26, 2022

↪️ Pull Request

Adds true HMR for all assets in a Manifest V3 web extension. Unfortunately this is mostly useless for the foreseeable future because of a Chromium bug. However hot reload at least works for the options page and sandbox pages now, just not for content scripts.

Fixes #8168, which currently breaks pretty much all MV3 extensions with the default background script.

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

@parcel-benchmark
Copy link

parcel-benchmark commented May 26, 2022

Benchmark Results

Kitchen Sink 🚨

Timings

Description Time Difference
Cold FAILED -0.00ms
Cached FAILED -0.00ms

Cold Bundles

No bundles found, this is probably a failed build...

Cached Bundles

No bundles found, this is probably a failed build...

React HackerNews ✅

Timings

Description Time Difference
Cold 8.73s -25.00ms
Cached 464.00ms +27.00ms ⚠️

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

AtlasKit Editor ✅

Timings

Description Time Difference
Cold 1.55m -926.00ms
Cached 2.46s -49.00ms

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

Three.js ✅

Timings

Description Time Difference
Cold 6.41s +71.00ms
Cached 254.00ms -3.00ms

Cold Bundles

No bundle changes detected.

Cached Bundles

No bundle changes detected.

Click here to view a detailed benchmark overview.

@101arrowz 101arrowz marked this pull request as ready for review May 29, 2022 02:10
@101arrowz
Copy link
Member Author

101arrowz commented May 29, 2022

This is very imperfect but fixes a major bug with @parcel/config-webextension on v2.6.0 caused by a mistake in the HMR runtime. If nothing else, it should be merged to fix that issue.

Copy link
Member

@devongovett devongovett left a comment

Choose a reason for hiding this comment

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

Thanks, this looks good. A few questions.

try {
__parcel__importScripts__(asset.url);
resolve();
} catch (err) {
Copy link
Member

Choose a reason for hiding this comment

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

importScripts is synchronous, so this would currently catch any type error thrown by the imported code too. Maybe better to detect ESM (e.g. try..catch around import.meta, which throws an error when not in a module).

Copy link
Member Author

Choose a reason for hiding this comment

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

I thought import.meta was invalid syntax in some browsers but I can change it.

Copy link
Member

Choose a reason for hiding this comment

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

Going to send the outputFormat from the HMR server as part of the asset instead.

? window
: typeof global !== 'undefined'
? global
: {};
Copy link
Member

Choose a reason for hiding this comment

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

Why was this necessary? global should be injected by parcel when needed...

Copy link
Member Author

@101arrowz 101arrowz Jun 8, 2022

Choose a reason for hiding this comment

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

It wasn't for some reason. I don't think global is actually a property that exists in browsers anyway...just in Node.js

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

I tested and it seems to be working, but maybe I missed something

packages/runtimes/hmr/src/loaders/hmr-runtime.js Outdated Show resolved Hide resolved
packages/reporters/dev-server/src/Server.js Show resolved Hide resolved
@devongovett
Copy link
Member

Pushed a few small updates. Hopefully I didn't break anything. Let me know.

@devongovett devongovett merged commit 52296ad into v2 Jun 13, 2022
@devongovett devongovett deleted the true-mv3-hmr branch June 13, 2022 01:20
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.

v2.6.0 BUG: web-extension, content script, importScripts() is not supported in module workers
4 participants