Closed Bug 2020008 Opened 4 months ago Closed 4 months ago

Handle module import error in customElements.js

Categories

(Toolkit :: General, task)

task

Tracking

()

RESOLVED FIXED
150 Branch
Tracking Status
firefox150 --- fixed

People

(Reporter: arai, Assigned: arai)

Details

Attachments

(1 file)

derived from bug 2019262 and bug 2018794.

In the customElements.js, we're using ChromeUtils.importESModule to sync-import modules.

https://searchfox.org/firefox-main/rev/4bc9c2f9b62e7cb44894d581c8171edbf0f7e27f/toolkit/content/customElements.js#899-904

customElements.setElementCreationCallback(
  tag,
  function customElementCreationCallback() {
    ChromeUtils.importESModule(script, { global: "current" });
  }
);

There are four problems here:

  • (A) those modules are imported both with the regular module loader and sync module loader, which is actually prohibited in the design
  • (B) bug 2018794 happens likely because the page performs navigation while initializing custom elements and importing modules, which results in the import failure
  • (C) ChromeUtils.importESModule's sync module loader conflicts with the regular module loader's failure
  • (D) CustomElementRegistry doesn't expect errors in the callback, and thus just propagating the import error still causes crash

https://searchfox.org/firefox-main/rev/4bc9c2f9b62e7cb44894d581c8171edbf0f7e27f/dom/base/CustomElementRegistry.cpp#526-527,531-532

NS_IMETHODIMP
CustomElementRegistry::RunCustomElementCreationCallback::Run() {
...
  MOZ_ASSERT(NS_SUCCEEDED(er.StealNSResult()),
             "chrome JavaScript error in the callback.");

(C) is going to be addressed in bug 2019262, and (B) is going to be addressed in bug 2018794.
(D) need to be addressed here, and the option I'm thinking is to wrap the ChromeUtils.importESModule call with try-catch and define an empty element on failure.

(A) is something that should ultimately be solved, but that requires huge amount of rewrite I think.

No longer blocks: 2018794
Pushed by arai_a@mac.com: https://github.com/mozilla-firefox/firefox/commit/ee0e1a6c52c9 https://hg.mozilla.org/integration/autoland/rev/daab4290330f Fallback to an empty element if the custom element's module import fails. r=hjones
Status: ASSIGNED → RESOLVED
Closed: 4 months ago
Resolution: --- → FIXED
Target Milestone: --- → 150 Branch

Authored by https://github.com/arai-a
https://github.com/mozilla/enterprise-firefox/commit/ee0e1a6c52c9d357ef04a892b57363e28203124c
[enterprise-main] Bug 2020008 - Fallback to an empty element if the custom element's module import fails. r=hjones

QA Whiteboard: [qa-triage-done-c151/b150]
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: