@lwc/engine-core 6.3.0 → 6.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,8 +42,8 @@ export interface RendererAPI {
42
42
  isConnected: (node: N) => boolean;
43
43
  insertStylesheet: (content: string, target?: ShadowRoot) => void;
44
44
  assertInstanceOfHTMLElement: (elm: any, msg: string) => void;
45
- createCustomElement: (tagName: string, upgradeCallback: LifecycleCallback, useNativeLifecycle: boolean) => E;
46
- defineCustomElement: (tagName: string) => void;
45
+ createCustomElement: (tagName: string, upgradeCallback: LifecycleCallback, useNativeLifecycle: boolean, isFormAssociated: boolean) => E;
46
+ defineCustomElement: (tagName: string, isFormAssociated: boolean) => void;
47
47
  ownerDocument(elm: E): Document;
48
48
  registerContextConsumer: (element: E, adapterContextToken: string, subscriptionPayload: WireContextSubscriptionPayload) => void;
49
49
  attachInternals: (elm: E) => ElementInternals;
package/dist/index.cjs.js CHANGED
@@ -1667,79 +1667,6 @@ function warnIfInvokedDuringConstruction(vm, methodOrPropName) {
1667
1667
  logError(`this.${methodOrPropName} should not be called during the construction of the custom element for ${getComponentTag(vm)} because the element is not yet in the DOM or has no children yet.`);
1668
1668
  }
1669
1669
  }
1670
- // List of properties on ElementInternals that are formAssociated can be found in the spec:
1671
- // https://html.spec.whatwg.org/multipage/custom-elements.html#form-associated-custom-elements
1672
- const formAssociatedProps = new Set([
1673
- 'setFormValue',
1674
- 'form',
1675
- 'setValidity',
1676
- 'willValidate',
1677
- 'validity',
1678
- 'validationMessage',
1679
- 'checkValidity',
1680
- 'reportValidity',
1681
- 'labels',
1682
- ]);
1683
- // Verify that access to a form-associated property of the ElementInternals proxy has formAssociated set in the LWC.
1684
- function verifyPropForFormAssociation(propertyKey, isFormAssociated) {
1685
- if (shared.isString(propertyKey) && formAssociatedProps.has(propertyKey) && !isFormAssociated) {
1686
- //Note this error message mirrors Chrome and Firefox error messages, in Safari the error is slightly different.
1687
- throw new DOMException(`Failed to execute '${propertyKey}' on 'ElementInternals': The target element is not a form-associated custom element.`);
1688
- }
1689
- }
1690
- const elementInternalsAccessorAllowList = new Set(['shadowRoot', 'role', ...formAssociatedProps]);
1691
- // Prevent access to properties not defined in the HTML spec in case browsers decide to
1692
- // provide new APIs that provide access to form associated properties.
1693
- // This can be removed along with UpgradeableConstructor.
1694
- function isAllowedElementInternalAccessor(propertyKey) {
1695
- let isAllowedAccessor = false;
1696
- // As of this writing all ElementInternal property keys as described in the spec are implemented with strings
1697
- // in Chrome, Firefox, and Safari
1698
- if (shared.isString(propertyKey)) {
1699
- // Allow list is based on HTML spec:
1700
- // https://html.spec.whatwg.org/multipage/custom-elements.html#the-elementinternals-interface
1701
- isAllowedAccessor =
1702
- elementInternalsAccessorAllowList.has(propertyKey) || /^aria/.test(propertyKey);
1703
- if (!isAllowedAccessor && process.env.NODE_ENV !== 'production') {
1704
- logWarn('Only properties defined in the ElementInternals HTML spec are available.');
1705
- }
1706
- }
1707
- return isAllowedAccessor;
1708
- }
1709
- // Wrap all ElementInternal objects in a proxy to prevent form association when `formAssociated` is not set on an LWC.
1710
- // This is needed because the 1UpgradeableConstructor1 always sets `formAssociated=true`, which means all
1711
- // ElementInternal objects will have form-associated properties set when an LWC is placed in a form.
1712
- // We are doing this to guard against customers taking a dependency on form elements being associated to ElementInternals
1713
- // when 'formAssociated' has not been set on the LWC.
1714
- function createElementInternalsProxy(elementInternals, isFormAssociated) {
1715
- const elementInternalsProxy = new Proxy(elementInternals, {
1716
- set(target, propertyKey, newValue) {
1717
- if (isAllowedElementInternalAccessor(propertyKey)) {
1718
- // Verify that formAssociated is set for form associated properties
1719
- verifyPropForFormAssociation(propertyKey, isFormAssociated);
1720
- return Reflect.set(target, propertyKey, newValue);
1721
- }
1722
- // As of this writing ElementInternals do not have non-string properties that can be set.
1723
- return false;
1724
- },
1725
- get(target, propertyKey) {
1726
- if (
1727
- // Pass through Object.prototype methods such as toString()
1728
- shared.hasOwnProperty.call(Object.prototype, propertyKey) ||
1729
- // As of this writing, ElementInternals only uses Symbol.toStringTag which is called
1730
- // on Object.hasOwnProperty invocations
1731
- Symbol.for('Symbol.toStringTag') === propertyKey ||
1732
- // ElementInternals allow listed properties
1733
- isAllowedElementInternalAccessor(propertyKey)) {
1734
- // Verify that formAssociated is set for form associated properties
1735
- verifyPropForFormAssociation(propertyKey, isFormAssociated);
1736
- const propertyValue = Reflect.get(target, propertyKey);
1737
- return shared.isFunction(propertyValue) ? propertyValue.bind(target) : propertyValue;
1738
- }
1739
- },
1740
- });
1741
- return elementInternalsProxy;
1742
- }
1743
1670
  // Type assertion because we need to build the prototype before it satisfies the interface.
1744
1671
  LightningElement.prototype = {
1745
1672
  constructor: LightningElement,
@@ -1833,13 +1760,14 @@ LightningElement.prototype = {
1833
1760
  },
1834
1761
  attachInternals() {
1835
1762
  const vm = getAssociatedVM(this);
1836
- const { elm, def: { formAssociated }, renderer: { attachInternals }, } = vm;
1763
+ const { elm, apiVersion, renderer: { attachInternals }, } = vm;
1764
+ if (!shared.isAPIFeatureEnabled(8 /* APIFeature.ENABLE_ELEMENT_INTERNALS */, apiVersion)) {
1765
+ throw new Error(`The attachInternals API is only supported in API version 61 and above. To use this API please update the LWC component API version.`);
1766
+ }
1837
1767
  if (vm.shadowMode === 1 /* ShadowMode.Synthetic */) {
1838
- throw new Error('attachInternals API is not supported in light DOM or synthetic shadow.');
1768
+ throw new Error('attachInternals API is not supported in synthetic shadow.');
1839
1769
  }
1840
- const internals = attachInternals(elm);
1841
- // #TODO[2970]: remove proxy once `UpgradeableConstructor` has been removed
1842
- return createElementInternalsProxy(internals, Boolean(formAssociated));
1770
+ return attachInternals(elm);
1843
1771
  },
1844
1772
  get isConnected() {
1845
1773
  const vm = getAssociatedVM(this);
@@ -4313,7 +4241,8 @@ function mountCustomElement(vnode, parent, anchor, renderer) {
4313
4241
  // compatibility, we lower case the tagname here.
4314
4242
  const normalizedTagname = sel.toLowerCase();
4315
4243
  const useNativeLifecycle = shouldUseNativeCustomElementLifecycle(ctor);
4316
- const elm = createCustomElement(normalizedTagname, upgradeCallback, useNativeLifecycle);
4244
+ const isFormAssociated = Boolean(ctor.formAssociated);
4245
+ const elm = createCustomElement(normalizedTagname, upgradeCallback, useNativeLifecycle, isFormAssociated);
4317
4246
  vnode.elm = elm;
4318
4247
  vnode.vm = vm;
4319
4248
  linkNodeToShadow(elm, owner, renderer);
@@ -6549,14 +6478,7 @@ function forceRehydration(vm) {
6549
6478
  }
6550
6479
  }
6551
6480
  function runFormAssociatedCustomElementCallback(vm, faceCb) {
6552
- const { renderMode, shadowMode, def: { formAssociated }, } = vm;
6553
- // Technically the UpgradableConstructor always sets `static formAssociated = true` but silently fail here to match browser behavior.
6554
- if (shared.isUndefined(formAssociated) || shared.isFalse(formAssociated)) {
6555
- if (process.env.NODE_ENV !== 'production') {
6556
- logWarn(`Form associated lifecycle methods must have the 'static formAssociated' value set in the component's prototype chain.`);
6557
- }
6558
- return;
6559
- }
6481
+ const { renderMode, shadowMode } = vm;
6560
6482
  if (shadowMode === 1 /* ShadowMode.Synthetic */ && renderMode !== 0 /* RenderMode.Light */) {
6561
6483
  throw new Error('Form associated lifecycle methods are not available in synthetic shadow. Please use native shadow or light DOM.');
6562
6484
  }
@@ -7049,7 +6971,7 @@ function hydrateCustomElement(elm, vnode, renderer) {
7049
6971
  }
7050
6972
  const { sel, mode, ctor, owner } = vnode;
7051
6973
  const { defineCustomElement, getTagName } = renderer;
7052
- defineCustomElement(shared.StringToLowerCase.call(getTagName(elm)));
6974
+ defineCustomElement(shared.StringToLowerCase.call(getTagName(elm)), Boolean(ctor.formAssociated));
7053
6975
  const vm = createVM(elm, ctor, renderer, {
7054
6976
  mode,
7055
6977
  owner,
@@ -7669,5 +7591,5 @@ exports.swapTemplate = swapTemplate;
7669
7591
  exports.track = track;
7670
7592
  exports.unwrap = unwrap;
7671
7593
  exports.wire = wire;
7672
- /** version: 6.3.0 */
7594
+ /** version: 6.3.1 */
7673
7595
  //# sourceMappingURL=index.cjs.js.map