@lwc/engine-core 5.2.2 → 6.0.0

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.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (C) 2023 salesforce.com, inc.
3
3
  */
4
- import { noop, StringToLowerCase, isNull, ArrayPush as ArrayPush$1, ArrayJoin, isFrozen, isUndefined as isUndefined$1, defineProperty, ArrayIndexOf, ArraySplice, create, seal, isArray as isArray$1, isFunction as isFunction$1, keys, hasOwnProperty as hasOwnProperty$1, globalThis as globalThis$1, entries, AriaPropNameToAttrNameMap, getPropertyDescriptor, forEach, defineProperties, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, assign, isObject, freeze, KEY__SYNTHETIC_MODE, isString, assert, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, isFalse, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, getOwnPropertyNames as getOwnPropertyNames$1, getOwnPropertyDescriptors, htmlPropertyToAttribute, ArraySlice, ArrayMap, KEY__SCOPED_CSS, kebabCaseToCamelCase, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, StringSlice, ArrayShift, ArrayUnshift, isTrue, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, ArraySome, ArrayPop, isAPIFeatureEnabled, isNumber, StringReplace, LOWEST_API_VERSION, KEY__NATIVE_GET_ELEMENT_BY_ID, KEY__NATIVE_QUERY_SELECTOR_ALL, ID_REFERENCING_ATTRIBUTES_SET, KEY__SHADOW_TOKEN, ArrayFilter, StringSplit, arrayEvery, ArrayIncludes, ArrayCopyWithin, ArrayFill, ArraySort, ArrayReverse } from '@lwc/shared';
4
+ import { noop, StringToLowerCase, isNull, ArrayPush as ArrayPush$1, ArrayJoin, isFrozen, isUndefined as isUndefined$1, defineProperty, ArrayIndexOf, ArraySplice, create, seal, isAPIFeatureEnabled, isArray as isArray$1, isFunction as isFunction$1, keys, hasOwnProperty as hasOwnProperty$1, globalThis as globalThis$1, entries, AriaPropNameToAttrNameMap, getPropertyDescriptor, forEach, defineProperties, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, assign, freeze, isObject, KEY__SYNTHETIC_MODE, isString, assert, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, isFalse, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, getOwnPropertyNames as getOwnPropertyNames$1, getOwnPropertyDescriptors, htmlPropertyToAttribute, ArraySlice, ArrayMap, KEY__SCOPED_CSS, kebabCaseToCamelCase, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, StringSlice, ArrayShift, ArrayUnshift, isTrue, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, ArraySome, ArrayPop, isNumber, StringReplace, LOWEST_API_VERSION, KEY__NATIVE_GET_ELEMENT_BY_ID, KEY__NATIVE_QUERY_SELECTOR_ALL, ID_REFERENCING_ATTRIBUTES_SET, KEY__SHADOW_TOKEN, ArrayFilter, StringSplit, arrayEvery, ArrayIncludes, ArrayCopyWithin, ArrayFill, ArraySort, ArrayReverse } from '@lwc/shared';
5
5
  export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
6
6
 
7
7
  /*
@@ -354,6 +354,14 @@ function guid() {
354
354
  }
355
355
  return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
356
356
  }
357
+ function shouldUseNativeCustomElementLifecycle(ctor) {
358
+ if (lwcRuntimeFlags.DISABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
359
+ // temporary "kill switch"
360
+ return false;
361
+ }
362
+ const apiVersion = getComponentAPIVersion(ctor);
363
+ return isAPIFeatureEnabled(7 /* APIFeature.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE */, apiVersion);
364
+ }
357
365
  // Borrowed from Vue template compiler.
358
366
  // https://github.com/vuejs/vue/blob/531371b818b0e31a989a06df43789728f23dc4e8/src/platforms/web/util/style.js#L5-L16
359
367
  const DECLARATION_DELIMITER = /;(?![^(]*\))/g;
@@ -722,28 +730,6 @@ function getCustomElementRestrictionsDescriptors(elm) {
722
730
  }),
723
731
  };
724
732
  }
725
- function getLightningElementPrototypeRestrictionsDescriptors(proto) {
726
- assertNotProd(); // this method should never leak to prod
727
- const originalDispatchEvent = proto.dispatchEvent;
728
- return {
729
- dispatchEvent: generateDataDescriptor({
730
- value(event) {
731
- const vm = getAssociatedVM(this);
732
- if (!isNull(event) && isObject(event)) {
733
- const { type } = event;
734
- if (!/^[a-z][a-z0-9_]*$/.test(type)) {
735
- logError(`Invalid event type "${type}" dispatched in element ${getComponentTag(vm)}.` +
736
- ` Event name must start with a lowercase letter and followed only lowercase` +
737
- ` letters, numbers, and underscores`, vm);
738
- }
739
- }
740
- // Typescript does not like it when you treat the `arguments` object as an array
741
- // @ts-ignore type-mismatch
742
- return originalDispatchEvent.apply(this, arguments);
743
- },
744
- }),
745
- };
746
- }
747
733
  // This routine will prevent access to certain properties on a shadow root instance to guarantee
748
734
  // that all components will work fine in IE11 and other browsers without shadow dom support.
749
735
  function patchShadowRootWithRestrictions(sr) {
@@ -754,9 +740,6 @@ function patchCustomElementWithRestrictions(elm) {
754
740
  const elmProto = getPrototypeOf$1(elm);
755
741
  setPrototypeOf(elm, create(elmProto, restrictionsDescriptors));
756
742
  }
757
- function patchLightningElementPrototypeWithRestrictions(proto) {
758
- defineProperties(proto, getLightningElementPrototypeRestrictionsDescriptors(proto));
759
- }
760
743
 
761
744
  function updateComponentValue(vm, key, newValue) {
762
745
  const { cmpFields } = vm;
@@ -1940,9 +1923,6 @@ defineProperty(LightningElement, 'CustomElementConstructor', {
1940
1923
  },
1941
1924
  configurable: true,
1942
1925
  });
1943
- if (process.env.NODE_ENV !== 'production') {
1944
- patchLightningElementPrototypeWithRestrictions(LightningElement.prototype);
1945
- }
1946
1926
 
1947
1927
  function createObservedFieldPropertyDescriptor(key) {
1948
1928
  return {
@@ -3591,6 +3571,9 @@ function isVFragment(vnode) {
3591
3571
  function isVScopedSlotFragment(vnode) {
3592
3572
  return vnode.type === 6 /* VNodeType.ScopedSlotFragment */;
3593
3573
  }
3574
+ function isVStatic(vnode) {
3575
+ return vnode.type === 4 /* VNodeType.Static */;
3576
+ }
3594
3577
 
3595
3578
  /*
3596
3579
  * Copyright (c) 2018, salesforce.com, inc.
@@ -3639,6 +3622,20 @@ function patchAttributes(oldVnode, vnode, renderer) {
3639
3622
  }
3640
3623
  }
3641
3624
  }
3625
+ function patchSlotAssignment(oldVnode, vnode, renderer) {
3626
+ const { slotAssignment } = vnode;
3627
+ if ((oldVnode === null || oldVnode === void 0 ? void 0 : oldVnode.slotAssignment) === slotAssignment) {
3628
+ return;
3629
+ }
3630
+ const { elm } = vnode;
3631
+ const { setAttribute, removeAttribute } = renderer;
3632
+ if (isUndefined$1(slotAssignment) || isNull(slotAssignment)) {
3633
+ removeAttribute(elm, 'slot');
3634
+ }
3635
+ else {
3636
+ setAttribute(elm, 'slot', slotAssignment);
3637
+ }
3638
+ }
3642
3639
 
3643
3640
  /*
3644
3641
  * Copyright (c) 2018, salesforce.com, inc.
@@ -4088,6 +4085,8 @@ function mountElement(vnode, parent, anchor, renderer) {
4088
4085
  }
4089
4086
  function patchStatic(n1, n2, renderer) {
4090
4087
  const elm = (n2.elm = n1.elm);
4088
+ // slotAssignments can only apply to the top level element, never to a static part.
4089
+ patchSlotAssignment(n1, n2, renderer);
4091
4090
  // The `refs` object is blown away in every re-render, so we always need to re-apply them
4092
4091
  applyStaticParts(elm, n2, renderer, false);
4093
4092
  }
@@ -4109,11 +4108,13 @@ function mountStatic(vnode, parent, anchor, renderer) {
4109
4108
  elm[KEY__SHADOW_STATIC] = true;
4110
4109
  }
4111
4110
  }
4111
+ // slotAssignments can only apply to the top level element, never to a static part.
4112
+ patchSlotAssignment(null, vnode, renderer);
4112
4113
  insertNode(elm, parent, anchor, renderer);
4113
4114
  applyStaticParts(elm, vnode, renderer, true);
4114
4115
  }
4115
4116
  function mountCustomElement(vnode, parent, anchor, renderer) {
4116
- const { sel, owner } = vnode;
4117
+ const { sel, owner, ctor } = vnode;
4117
4118
  const { createCustomElement } = renderer;
4118
4119
  /**
4119
4120
  * Note: if the upgradable constructor does not expect, or throw when we new it
@@ -4131,7 +4132,8 @@ function mountCustomElement(vnode, parent, anchor, renderer) {
4131
4132
  // compiler may generate tagnames with uppercase letters so - for backwards
4132
4133
  // compatibility, we lower case the tagname here.
4133
4134
  const normalizedTagname = sel.toLowerCase();
4134
- const elm = createCustomElement(normalizedTagname, upgradeCallback);
4135
+ const useNativeLifecycle = shouldUseNativeCustomElementLifecycle(ctor);
4136
+ const elm = createCustomElement(normalizedTagname, upgradeCallback, useNativeLifecycle);
4135
4137
  vnode.elm = elm;
4136
4138
  vnode.vm = vm;
4137
4139
  linkNodeToShadow(elm, owner, renderer);
@@ -4143,7 +4145,7 @@ function mountCustomElement(vnode, parent, anchor, renderer) {
4143
4145
  insertNode(elm, parent, anchor, renderer);
4144
4146
  if (vm) {
4145
4147
  if (process.env.IS_BROWSER) {
4146
- if (!lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
4148
+ if (!useNativeLifecycle) {
4147
4149
  if (process.env.NODE_ENV !== 'production') {
4148
4150
  // With synthetic lifecycle callbacks, it's possible for elements to be removed without the engine
4149
4151
  // noticing it (e.g. `appendChild` the same host element twice). This test ensures we don't regress.
@@ -4334,6 +4336,7 @@ function patchElementPropsAndAttrsAndRefs$1(oldVnode, vnode, renderer) {
4334
4336
  patchStyleAttribute(oldVnode, vnode, renderer);
4335
4337
  patchAttributes(oldVnode, vnode, renderer);
4336
4338
  patchProps(oldVnode, vnode, renderer);
4339
+ patchSlotAssignment(oldVnode, vnode, renderer);
4337
4340
  // The `refs` object is blown away in every re-render, so we always need to re-apply them
4338
4341
  applyRefs(vnode, vnode.owner);
4339
4342
  }
@@ -4487,7 +4490,7 @@ function createViewModelHook(elm, vnode, renderer) {
4487
4490
  return vm;
4488
4491
  }
4489
4492
  function allocateInSlot(vm, children, owner) {
4490
- var _a, _b;
4493
+ var _a;
4491
4494
  const { cmpSlots: { slotAssignments: oldSlotsMapping }, } = vm;
4492
4495
  const cmpSlotsMapping = create(null);
4493
4496
  // Collect all slots into cmpSlotsMapping
@@ -4497,8 +4500,8 @@ function allocateInSlot(vm, children, owner) {
4497
4500
  continue;
4498
4501
  }
4499
4502
  let slotName = '';
4500
- if (isVBaseElement(vnode)) {
4501
- slotName = (_b = (_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : '';
4503
+ if (isVBaseElement(vnode) || isVStatic(vnode)) {
4504
+ slotName = (_a = vnode.slotAssignment) !== null && _a !== void 0 ? _a : '';
4502
4505
  }
4503
4506
  else if (isVScopedSlotFragment(vnode)) {
4504
4507
  slotName = vnode.slotName;
@@ -4768,6 +4771,7 @@ function st(fragment, key, parts) {
4768
4771
  fragment,
4769
4772
  owner,
4770
4773
  parts,
4774
+ slotAssignment: undefined,
4771
4775
  };
4772
4776
  return vnode;
4773
4777
  }
@@ -4812,7 +4816,7 @@ function h(sel, data, children = EmptyArray) {
4812
4816
  }
4813
4817
  });
4814
4818
  }
4815
- const { key } = data;
4819
+ const { key, slotAssignment } = data;
4816
4820
  const vnode = {
4817
4821
  type: 2 /* VNodeType.Element */,
4818
4822
  sel,
@@ -4821,6 +4825,7 @@ function h(sel, data, children = EmptyArray) {
4821
4825
  elm: undefined,
4822
4826
  key,
4823
4827
  owner: vmBeingRendered,
4828
+ slotAssignment,
4824
4829
  };
4825
4830
  return vnode;
4826
4831
  }
@@ -4845,6 +4850,8 @@ function s(slotName, data, children, slotset) {
4845
4850
  assert.isTrue(isObject(data), `s() 2nd argument data must be an object.`);
4846
4851
  assert.isTrue(isArray$1(children), `h() 3rd argument children must be an array.`);
4847
4852
  }
4853
+ const vmBeingRendered = getVMBeingRendered();
4854
+ const { renderMode, apiVersion } = vmBeingRendered;
4848
4855
  if (!isUndefined$1(slotset) &&
4849
4856
  !isUndefined$1(slotset.slotAssignments) &&
4850
4857
  !isUndefined$1(slotset.slotAssignments[slotName]) &&
@@ -4867,7 +4874,6 @@ function s(slotName, data, children, slotset) {
4867
4874
  }
4868
4875
  // If the passed slot content is factory, evaluate it and add the produced vnodes
4869
4876
  if (assignedNodeIsScopedSlot) {
4870
- const vmBeingRenderedInception = getVMBeingRendered();
4871
4877
  // Evaluate in the scope of the slot content's owner
4872
4878
  // if a slotset is provided, there will always be an owner. The only case where owner is
4873
4879
  // undefined is for root components, but root components cannot accept slotted content
@@ -4881,20 +4887,33 @@ function s(slotName, data, children, slotset) {
4881
4887
  });
4882
4888
  }
4883
4889
  finally {
4884
- setVMBeingRendered(vmBeingRenderedInception);
4890
+ setVMBeingRendered(vmBeingRendered);
4885
4891
  }
4886
4892
  }
4887
4893
  else {
4894
+ // This block is for standard slots (non-scoped slots)
4895
+ let clonedVNode;
4896
+ if (renderMode === 0 /* RenderMode.Light */ &&
4897
+ isAPIFeatureEnabled(6 /* APIFeature.USE_LIGHT_DOM_SLOT_FORWARDING */, apiVersion) &&
4898
+ (isVBaseElement(vnode) || isVStatic(vnode)) &&
4899
+ // We only need to copy the vnodes when the slot assignment changes, copying every time causes issues with
4900
+ // disconnected/connected callback firing.
4901
+ vnode.slotAssignment !== data.slotAssignment) {
4902
+ // When the light DOM slot assignment (slot attribute) changes we can't use the same reference
4903
+ // to the vnode because the current way the diffing algo works, it will replace the original reference
4904
+ // to the host element with a new one. This means the new element will be mounted and immediately unmounted.
4905
+ // Creating a copy of the vnode to preserve a reference to the previous host element.
4906
+ clonedVNode = Object.assign(Object.assign({}, vnode), { slotAssignment: data.slotAssignment });
4907
+ }
4888
4908
  // If the slot content is standard type, the content is static, no additional
4889
4909
  // processing needed on the vnode
4890
- ArrayPush$1.call(newChildren, vnode);
4910
+ ArrayPush$1.call(newChildren, clonedVNode !== null && clonedVNode !== void 0 ? clonedVNode : vnode);
4891
4911
  }
4892
4912
  }
4893
4913
  }
4894
4914
  children = newChildren;
4895
4915
  }
4896
- const vmBeingRendered = getVMBeingRendered();
4897
- const { renderMode, shadowMode, apiVersion } = vmBeingRendered;
4916
+ const { shadowMode } = vmBeingRendered;
4898
4917
  if (renderMode === 0 /* RenderMode.Light */) {
4899
4918
  // light DOM slots - backwards-compatible behavior uses flattening, new behavior uses fragments
4900
4919
  if (isAPIFeatureEnabled(2 /* APIFeature.USE_FRAGMENTS_FOR_LIGHT_DOM_SLOTS */, apiVersion)) {
@@ -4936,7 +4955,7 @@ function c(sel, Ctor, data, children = EmptyArray) {
4936
4955
  });
4937
4956
  }
4938
4957
  }
4939
- const { key } = data;
4958
+ const { key, slotAssignment } = data;
4940
4959
  let elm, aChildren, vm;
4941
4960
  const vnode = {
4942
4961
  type: 3 /* VNodeType.CustomElement */,
@@ -4945,6 +4964,7 @@ function c(sel, Ctor, data, children = EmptyArray) {
4945
4964
  children,
4946
4965
  elm,
4947
4966
  key,
4967
+ slotAssignment,
4948
4968
  ctor: Ctor,
4949
4969
  owner: vmBeingRendered,
4950
4970
  mode: 'open', // TODO [#1294]: this should be defined in Ctor
@@ -5794,7 +5814,7 @@ function resetComponentStateWhenRemoved(vm) {
5794
5814
  // old vnode.children is removed from the DOM.
5795
5815
  function removeVM(vm) {
5796
5816
  if (process.env.NODE_ENV !== 'production') {
5797
- if (!lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE) {
5817
+ if (!shouldUseNativeCustomElementLifecycle(vm.component.constructor)) {
5798
5818
  // With native lifecycle, we cannot be certain that connectedCallback was called before a component
5799
5819
  // was removed from the VDOM. If the component is disconnected, then connectedCallback will not fire
5800
5820
  // in native mode, although it will fire in synthetic mode due to appendChild triggering it.
@@ -6122,7 +6142,7 @@ function runConnectedCallback(vm) {
6122
6142
  // This test only makes sense in the browser, with synthetic lifecycle, and when reporting is enabled or
6123
6143
  // we're in dev mode. This is to detect a particular issue with synthetic lifecycle.
6124
6144
  if (process.env.IS_BROWSER &&
6125
- !lwcRuntimeFlags.ENABLE_NATIVE_CUSTOM_ELEMENT_LIFECYCLE &&
6145
+ !shouldUseNativeCustomElementLifecycle(vm.component.constructor) &&
6126
6146
  (process.env.NODE_ENV !== 'production' || isReportingEnabled())) {
6127
6147
  if (!vm.renderer.isConnected(vm.elm)) {
6128
6148
  if (process.env.NODE_ENV !== 'production') {
@@ -7384,5 +7404,5 @@ function readonly(obj) {
7384
7404
  }
7385
7405
 
7386
7406
  export { LightningElement, profilerControl as __unstable__ProfilerControl, reportingControl as __unstable__ReportingControl, api$1 as api, computeShadowAndRenderMode, connectRootElement, createContextProviderWithRegister, createVM, disconnectRootElement, freezeTemplate, getAssociatedVMIfPresent, getComponentAPIVersion, getComponentConstructor, getComponentDef, getComponentHtmlPrototype, hydrateRoot, isComponentConstructor, parseFragment, parseSVGFragment, readonly, registerComponent, registerDecorators, registerTemplate, runFormAssociatedCallback, runFormDisabledCallback, runFormResetCallback, runFormStateRestoreCallback, sanitizeAttribute, setHooks, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
7387
- /** version: 5.2.2 */
7407
+ /** version: 6.0.0 */
7388
7408
  //# sourceMappingURL=index.js.map