From 08061c85da6c2c2d5d11d6cdad0a9d387042a784 Mon Sep 17 00:00:00 2001 From: Simon H <5968653+dummdidumm@users.noreply.github.com> Date: Tue, 7 Jan 2025 20:26:13 +0100 Subject: [PATCH] fix: guard against `customElements` being unavailable in browser extension contexts (#14933) fixes #14739 --- .changeset/forty-books-taste.md | 5 +++++ .../svelte/src/internal/client/dom/elements/attributes.js | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) create mode 100644 .changeset/forty-books-taste.md diff --git a/.changeset/forty-books-taste.md b/.changeset/forty-books-taste.md new file mode 100644 index 0000000000..e2474c635f --- /dev/null +++ b/.changeset/forty-books-taste.md @@ -0,0 +1,5 @@ +--- +'svelte': patch +--- + +fix: guard against `customElements` being unavailable in browser extension contexts diff --git a/packages/svelte/src/internal/client/dom/elements/attributes.js b/packages/svelte/src/internal/client/dom/elements/attributes.js index 6656532986..a2fffe8696 100644 --- a/packages/svelte/src/internal/client/dom/elements/attributes.js +++ b/packages/svelte/src/internal/client/dom/elements/attributes.js @@ -221,7 +221,10 @@ export function set_custom_element_data(node, prop, value) { // Don't compute setters for custom elements while they aren't registered yet, // because during their upgrade/instantiation they might add more setters. // Instead, fall back to a simple "an object, then set as property" heuristic. - setters_cache.has(node.nodeName) || customElements.get(node.tagName.toLowerCase()) + setters_cache.has(node.nodeName) || + // customElements may not be available in browser extension contexts + !customElements || + customElements.get(node.tagName.toLowerCase()) ? get_setters(node).includes(prop) : value && typeof value === 'object' ) {