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: avoid errors when loading the overlay code in workers #9064

Merged
merged 2 commits into from Jul 15, 2022

Conversation

lgarron
Copy link
Contributor

@lgarron lgarron commented Jul 13, 2022

Description

HTMLElement and customElements are not defined in e.g. web workers. However, Vite sometimes tries to inject the overlay into such workers. Ideally, it would not do so (and would e.g. find another way to notify the developer about issues). But this PR offers a change that allows such workers to run, by avoiding crashes in overlay.ts when it does.

Additional context

Vite 3 requires this fix to successfully run module workers:

import { randomScrambleForEvent } from "cubing/scramble";

(async () => {
  (await randomScrambleForEvent("333")).log();
})();

What is the purpose of this pull request?

  • Bug fix
  • New Feature
  • Documentation update
  • Other

Before submitting the PR, please make sure you do the following

  • Read the Contributing Guidelines.
  • Read the Pull Request Guidelines and follow the Commit Convention.
  • Check that there isn't already a PR that solves the problem the same way to avoid creating a duplicate.
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123).
  • Ideally, include relevant tests that fail without this PR but pass with it.

`HTMLElement` and `customElements` are not defined in e.g. web workers. However, Vite sometimes tries to inject the overlay into such workers. Ideally, it would not do so (and would e.g. find another way to notify the developer about issues). But this PR offers a change that allows such workers to run, by avoiding crashes in `overlay.ts` when it does.
@netlify
Copy link

netlify bot commented Jul 13, 2022

Deploy Preview for vite-docs-main canceled.

Name Link
🔨 Latest commit 9bbeec2
🔍 Latest deploy log https://app.netlify.com/sites/vite-docs-main/deploys/62ce4bd0417e8e000881622e

@sapphi-red sapphi-red added p3-minor-bug An edge case that only affects very specific usage (priority) feat: web workers labels Jul 14, 2022
@GuskiS
Copy link

GuskiS commented Jul 15, 2022

Is this getting merged anytime soon? My app doesn't work because web worker raises error about overlay.

@patak-dev
Copy link
Member

Thanks for the PR @lgarron, let's merge this as a temporal patch. In Vite 3.1 we should refactor so workers don't include this code (by having a new /@vite/worker virtual module)

@patak-dev patak-dev changed the title fix: Avoid errors when loading the overlay code in workers. fix: avoid errors when loading the overlay code in workers Jul 15, 2022
@patak-dev patak-dev merged commit a52b45e into vitejs:main Jul 15, 2022
@lgarron lgarron deleted the overlay-worker-compat branch July 18, 2022 02:23
@kleisauke kleisauke mentioned this pull request Oct 12, 2022
7 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat: web workers p3-minor-bug An edge case that only affects very specific usage (priority)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants