diff --git a/packages/@lwc/engine-core/src/framework/attributes.ts b/packages/@lwc/engine-core/src/framework/attributes.ts deleted file mode 100644 index c2ea8a4b61..0000000000 --- a/packages/@lwc/engine-core/src/framework/attributes.ts +++ /dev/null @@ -1,19 +0,0 @@ -/* - * Copyright (c) 2018, salesforce.com, inc. - * All rights reserved. - * SPDX-License-Identifier: MIT - * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT - */ - -// These properties get added to LWCElement.prototype publicProps automatically -export const defaultDefHTMLPropertyNames = [ - 'accessKey', - 'dir', - 'draggable', - 'hidden', - 'id', - 'lang', - 'spellcheck', - 'tabIndex', - 'title', -]; diff --git a/packages/@lwc/engine-core/src/framework/html-properties.ts b/packages/@lwc/engine-core/src/framework/html-properties.ts index ea2377d8fe..383272495b 100644 --- a/packages/@lwc/engine-core/src/framework/html-properties.ts +++ b/packages/@lwc/engine-core/src/framework/html-properties.ts @@ -5,16 +5,16 @@ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT */ import { + AriaPropNameToAttrNameMap, create, forEach, getPropertyDescriptor, isUndefined, keys, - AriaPropNameToAttrNameMap, + REFLECTIVE_GLOBAL_PROPERTY_SET, } from '@lwc/shared'; import { HTMLElementPrototype } from './html-element'; -import { defaultDefHTMLPropertyNames } from './attributes'; /** * This is a descriptor map that contains @@ -32,7 +32,8 @@ forEach.call(keys(AriaPropNameToAttrNameMap), (propName: string) => { HTMLElementOriginalDescriptors[propName] = descriptor; } }); -forEach.call(defaultDefHTMLPropertyNames, (propName) => { + +for (const propName of REFLECTIVE_GLOBAL_PROPERTY_SET) { // Note: intentionally using our in-house getPropertyDescriptor instead of getOwnPropertyDescriptor here because // in IE11, id property is on Element.prototype instead of HTMLElement, and we suspect that more will fall into // this category, so, better to be sure. @@ -40,4 +41,4 @@ forEach.call(defaultDefHTMLPropertyNames, (propName) => { if (!isUndefined(descriptor)) { HTMLElementOriginalDescriptors[propName] = descriptor; } -}); +} diff --git a/packages/@lwc/engine-dom/src/language.ts b/packages/@lwc/engine-dom/src/language.ts new file mode 100644 index 0000000000..7dad880067 --- /dev/null +++ b/packages/@lwc/engine-dom/src/language.ts @@ -0,0 +1,15 @@ +/* + * Copyright (c) 2024, Salesforce, Inc. + * All rights reserved. + * SPDX-License-Identifier: MIT + * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT + */ + +import { getOwnPropertyDescriptors } from '@lwc/shared'; + +// Like @lwc/shared, but for DOM APIs + +export const ElementDescriptors = getOwnPropertyDescriptors(Element.prototype); + +export const ElementAttachShadow = ElementDescriptors.attachShadow.value!; +export const ElementShadowRootGetter = ElementDescriptors.shadowRoot.get!; diff --git a/packages/@lwc/engine-dom/src/renderer/index.ts b/packages/@lwc/engine-dom/src/renderer/index.ts index 64d5e66953..10558f98c9 100644 --- a/packages/@lwc/engine-dom/src/renderer/index.ts +++ b/packages/@lwc/engine-dom/src/renderer/index.ts @@ -6,6 +6,7 @@ */ import { assert, isNull, isUndefined } from '@lwc/shared'; +import { ElementAttachShadow, ElementShadowRootGetter } from '../language'; function cloneNode(node: Node, deep: boolean): Node { return node.cloneNode(deep); @@ -57,10 +58,12 @@ function attachShadow(element: Element, options: ShadowRootInit): ShadowRoot { // 1. upon initial load with an SSR-generated DOM, while in Shadow render mode // 2. when a webapp author places in their static HTML and mounts their // root component with customElement.define('c-app', Ctor) - if (!isNull(element.shadowRoot)) { - return element.shadowRoot; + // see W-17441501 + const shadowRoot = ElementShadowRootGetter.call(element); + if (!isNull(shadowRoot)) { + return shadowRoot; } - return element.attachShadow(options); + return ElementAttachShadow.call(element, options); } function setText(node: Node, content: string): void { diff --git a/packages/@lwc/engine-server/src/__tests__/fixtures/attribute-component-global-html/expected.html b/packages/@lwc/engine-server/src/__tests__/fixtures/attribute-component-global-html/expected.html index 9bcbfcdd11..c4a1b8b6e4 100644 --- a/packages/@lwc/engine-server/src/__tests__/fixtures/attribute-component-global-html/expected.html +++ b/packages/@lwc/engine-server/src/__tests__/fixtures/attribute-component-global-html/expected.html @@ -1,6 +1,6 @@