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

[scoped-custom-element-registry] customize() eagerly swallows any exception and causes a confusing error message #608

Open
3 of 5 tasks
denilsonsa opened this issue Feb 24, 2025 · 0 comments

Comments

@denilsonsa
Copy link

denilsonsa commented Feb 24, 2025

Description

This piece of code is swallowing all exceptions, and ends up triggering another one:

try {
new definition.elementClass();
} catch (_) {
patchHTMLElement(definition.elementClass);
new definition.elementClass();
}

On Firefox and on Safari:

Uncaught TypeError: Cannot instantiate a custom element inside its own constructor during upgrades

On Chrome:

Uncaught TypeError: Failed to construct 'HTMLElement': This instance is already constructed

Example

This happened in our big web application. I tried reproducing it in a smaller scale, but I still cannot figure out how to trigger the customize() function, and thus my minimal testcase still cannot reproduce this bug.

Steps to reproduce

  1. Have a large enterprise web application with dozens of components. Then start migrating it from the company-library v2 to v4, which also migrates Lit from v1 to v3.
    • Seriously, if I had a minimal testcase that could show the bug to you, I would add it here.
  2. Somehow, a page fails to load. The error message is cryptic (as described above).
  3. After a lot of debugging, figure out that scoped-custom-element-registry.js:386 is capturing all exceptions, and then constructing the HTML element again on the next line.
    • When I inspected the value of the _ exception, I got the actual error message that showed me what went wrong. Here some examples of the actual error messages I found so far:
      • Value passed to 'css' function must be a 'css' function
      • TypeError: this.renderOptions is undefined

Expected behavior

The actual error message from the actual exception cause by my source-code should be shown to the developer.

Actual behavior

A completely unrelated and cryptic exception is shown to the developer, which sounds like a bug in the scoped-custom-element-registry exception handling. (And also a limitation on the JavaScript exception handling primitives.)

Version

  • @webcomponents/scoped-custom-element-registry 0.0.9 (the latest version)

Browsers affected

  • Chrome
  • Firefox
  • Edge (untested, but certainly also affected, as Edge used the same engine as Chrome)
  • Safari
  • IE 11 (no one cares anymore)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant