@lwc/engine-core 7.2.1 → 7.2.2

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) 2024 Salesforce, Inc.
3
3
  */
4
- import { noop, StringToLowerCase, isNull, ArrayPush as ArrayPush$1, ArrayJoin, isFrozen, isUndefined as isUndefined$1, defineProperty, ArrayIndexOf, ArrayPop, create, isFalse, isFunction as isFunction$1, isObject, seal, isAPIFeatureEnabled, isArray as isArray$1, keys, hasOwnProperty as hasOwnProperty$1, entries, AriaPropNameToAttrNameMap, getPropertyDescriptor, forEach, defineProperties, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, assign, assert, freeze, KEY__SYNTHETIC_MODE, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, getOwnPropertyNames as getOwnPropertyNames$1, getOwnPropertyDescriptors, htmlPropertyToAttribute, ArraySlice, ArrayMap, KEY__SCOPED_CSS, ArraySplice, kebabCaseToCamelCase, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, isString, StringSlice, isTrue, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, ArraySome, isNumber, StringReplace, StringTrim, htmlEscape, StringCharAt, ArrayUnshift, 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, ArrayShift } from '@lwc/shared';
4
+ import { noop, StringToLowerCase, isNull, ArrayPush as ArrayPush$1, ArrayJoin, isFrozen, isUndefined as isUndefined$1, defineProperty, ArrayIndexOf, ArrayPop, create, isFalse, isFunction as isFunction$1, isObject, seal, isAPIFeatureEnabled, isArray as isArray$1, keys, hasOwnProperty as hasOwnProperty$1, entries, AriaPropNameToAttrNameMap, getPropertyDescriptor, forEach, defineProperties, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, assign, assert, freeze, KEY__SYNTHETIC_MODE, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, getOwnPropertyNames as getOwnPropertyNames$1, getOwnPropertyDescriptors, htmlPropertyToAttribute, ArraySlice, ArrayMap, KEY__SCOPED_CSS, ArraySplice, kebabCaseToCamelCase, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, isString, StringSlice, isTrue, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, ArraySome, isNumber, StringReplace, StringTrim, ArrayFrom, htmlEscape, StringCharAt, ArrayUnshift, 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, ArrayShift } from '@lwc/shared';
5
5
  export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
6
6
 
7
7
  /*
@@ -151,7 +151,7 @@ function log(method, message, vm, once) {
151
151
  }
152
152
  alreadyLoggedMessages.add(msg);
153
153
  }
154
- // In Jest tests, reduce the warning and error verbosity by not printing the callstack
154
+ // In Vitest tests, reduce the warning and error verbosity by not printing the callstack
155
155
  if (process.env.NODE_ENV === 'test') {
156
156
  /* eslint-disable-next-line no-console */
157
157
  console[method](msg);
@@ -5255,22 +5255,30 @@ function s(slotName, data, children, slotset) {
5255
5255
  if (renderMode === 0 /* RenderMode.Light */ &&
5256
5256
  isAPIFeatureEnabled(6 /* APIFeature.USE_LIGHT_DOM_SLOT_FORWARDING */, apiVersion) &&
5257
5257
  (isVBaseElement(vnode) || isVStatic(vnode)) &&
5258
- // We only need to copy the vnodes when the slot assignment changes, copying every time causes issues with
5259
- // disconnected/connected callback firing.
5260
5258
  vnode.slotAssignment !== data.slotAssignment) {
5261
- // When the light DOM slot assignment (slot attribute) changes we can't use the same reference
5262
- // to the vnode because the current way the diffing algo works, it will replace the original reference
5263
- // to the host element with a new one. This means the new element will be mounted and immediately unmounted.
5264
- // Creating a copy of the vnode to preserve a reference to the previous host element.
5265
- if (isUndefined$1(vnode.elm)) {
5266
- // vnode.elm is undefined during initial render.
5267
- // We don't need to clone at this point because it doesn't need to be unmounted.
5268
- vnode.slotAssignment = data.slotAssignment;
5269
- }
5270
- else {
5271
- // Clone when the vnode.elm is defined to ensure we don't lose reference to the previous element.
5272
- // This is specifically for slot forwarding.
5273
- clonedVNode = { ...vnode, slotAssignment: data.slotAssignment };
5259
+ // When the light DOM slot assignment (slot attribute) changes, we can't use the same reference
5260
+ // to the vnode because the current way the diffing algo works, it will replace the original
5261
+ // reference to the host element with a new one. This means the new element will be mounted and
5262
+ // immediately unmounted. Creating a copy of the vnode preserves a reference to the previous
5263
+ // host element.
5264
+ clonedVNode = { ...vnode, slotAssignment: data.slotAssignment };
5265
+ // For disconnectedCallback to work correctly in synthetic lifecycle mode, we need to link the
5266
+ // current VM's velements to the clone, so that when the VM unmounts, the clone also unmounts.
5267
+ // Note this only applies to VCustomElements, since those are the elements that we manually need
5268
+ // to call disconnectedCallback for, when running in synthetic lifecycle mode.
5269
+ //
5270
+ // You might think it would make more sense to add the clonedVNode to the same velements array
5271
+ // as the original vnode's VM (i.e. `vnode.owner.velements`) rather than the current VM (i.e.
5272
+ // `vmBeingRendered.velements`), but this actually might not trigger disconnectedCallback
5273
+ // in synthetic lifecycle mode. The reason for this is that a reactivity change may cause
5274
+ // the slottable component to unmount, but _not_ the slotter component (see issue #4446).
5275
+ //
5276
+ // If this occurs, then the slottable component (i.e .this component we are rendering right
5277
+ // now) is the one that needs to own the clone. Whereas if a reactivity change higher in the
5278
+ // tree causes the slotter to unmount, then the slottable will also unmount. So using the
5279
+ // current VM works either way.
5280
+ if (isVCustomElement(vnode)) {
5281
+ addVNodeToChildLWC(clonedVNode);
5274
5282
  }
5275
5283
  }
5276
5284
  // If the slot content is standard type, the content is static, no additional
@@ -5792,6 +5800,44 @@ function logGlobalOperationEnd(opId, vm) {
5792
5800
  }
5793
5801
  }
5794
5802
 
5803
+ /*
5804
+ * Copyright (c) 2024, Salesforce, Inc.
5805
+ * All rights reserved.
5806
+ * SPDX-License-Identifier: MIT
5807
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5808
+ */
5809
+ // HAS_SCOPED_STYLE | SHADOW_MODE_SYNTHETIC = 3
5810
+ const MAX_CACHE_KEY = 3;
5811
+ // Mapping of cacheKeys to `string[]` (assumed to come from a tagged template literal) to an Element.
5812
+ // Note that every unique tagged template literal will have a unique `string[]`. So by using `string[]`
5813
+ // as the WeakMap key, we effectively associate each Element with a unique tagged template literal.
5814
+ // See: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals#tagged_templates
5815
+ // Also note that this array only needs to be large enough to account for the maximum possible cache key
5816
+ const fragmentCache = ArrayFrom({ length: MAX_CACHE_KEY + 1 }, () => new WeakMap());
5817
+ // Only used in LWC's Karma tests
5818
+ if (process.env.NODE_ENV === 'test-karma-lwc') {
5819
+ window.__lwcResetFragmentCache = () => {
5820
+ for (let i = 0; i < fragmentCache.length; i++) {
5821
+ fragmentCache[i] = new WeakMap();
5822
+ }
5823
+ };
5824
+ }
5825
+ function checkIsBrowser() {
5826
+ // The fragment cache only serves prevent calling innerHTML multiple times which doesn't happen on the server.
5827
+ /* istanbul ignore next */
5828
+ if (!process.env.IS_BROWSER) {
5829
+ throw new Error('The fragment cache is intended to only be used in @lwc/engine-dom, not @lwc/engine-server');
5830
+ }
5831
+ }
5832
+ function getFromFragmentCache(cacheKey, strings) {
5833
+ checkIsBrowser();
5834
+ return fragmentCache[cacheKey].get(strings);
5835
+ }
5836
+ function setInFragmentCache(cacheKey, strings, element) {
5837
+ checkIsBrowser();
5838
+ fragmentCache[cacheKey].set(strings, element);
5839
+ }
5840
+
5795
5841
  /*
5796
5842
  * Copyright (c) 2024, Salesforce, Inc.
5797
5843
  * All rights reserved.
@@ -5935,43 +5981,24 @@ function serializeClassAttribute(part, classToken) {
5935
5981
  const computedClassName = `${classToken} ${keys(classMap).join(' ')}`.trim();
5936
5982
  return computedClassName.length ? ` class="${htmlEscape(computedClassName, true)}"` : '';
5937
5983
  }
5938
- // This should be a no-op outside of LWC's Karma tests, where it's not needed
5939
- let registerFragmentCache = noop;
5940
- // Only used in LWC's Karma tests
5941
- if (process.env.NODE_ENV === 'test-karma-lwc') {
5942
- // Keep track of fragmentCaches, so we can clear them in LWC's Karma tests
5943
- const fragmentCaches = [];
5944
- registerFragmentCache = (fragmentCache) => {
5945
- fragmentCaches.push(fragmentCache);
5946
- };
5947
- window.__lwcResetFragmentCaches = () => {
5948
- for (const fragmentCache of fragmentCaches) {
5949
- for (const key of keys(fragmentCache)) {
5950
- delete fragmentCache[key];
5951
- }
5952
- }
5953
- };
5954
- }
5955
5984
  function buildParseFragmentFn(createFragmentFn) {
5956
- return (strings, ...keys) => {
5957
- const cache = create(null);
5958
- registerFragmentCache(cache);
5959
- return function (parts) {
5985
+ return function parseFragment(strings, ...keys) {
5986
+ return function applyFragmentParts(parts) {
5960
5987
  const { context: { hasScopedStyles, stylesheetToken, legacyStylesheetToken }, shadowMode, renderer, } = getVMBeingRendered();
5961
5988
  const hasStyleToken = !isUndefined$1(stylesheetToken);
5962
5989
  const isSyntheticShadow = shadowMode === 1 /* ShadowMode.Synthetic */;
5963
5990
  const hasLegacyToken = lwcRuntimeFlags.ENABLE_LEGACY_SCOPE_TOKENS && !isUndefined$1(legacyStylesheetToken);
5964
5991
  let cacheKey = 0;
5965
5992
  if (hasStyleToken && hasScopedStyles) {
5966
- cacheKey |= 1 /* FragmentCache.HAS_SCOPED_STYLE */;
5993
+ cacheKey |= 1 /* FragmentCacheKey.HAS_SCOPED_STYLE */;
5967
5994
  }
5968
5995
  if (hasStyleToken && isSyntheticShadow) {
5969
- cacheKey |= 2 /* FragmentCache.SHADOW_MODE_SYNTHETIC */;
5996
+ cacheKey |= 2 /* FragmentCacheKey.SHADOW_MODE_SYNTHETIC */;
5970
5997
  }
5971
5998
  // Cache is only here to prevent calling innerHTML multiple times which doesn't happen on the server.
5972
5999
  if (process.env.IS_BROWSER) {
5973
6000
  // Disable this on the server to prevent cache poisoning when expressions are used.
5974
- const cached = cache[cacheKey];
6001
+ const cached = getFromFragmentCache(cacheKey, strings);
5975
6002
  if (!isUndefined$1(cached)) {
5976
6003
  return cached;
5977
6004
  }
@@ -6011,8 +6038,12 @@ function buildParseFragmentFn(createFragmentFn) {
6011
6038
  }
6012
6039
  }
6013
6040
  htmlFragment += strings[strings.length - 1];
6014
- cache[cacheKey] = createFragmentFn(htmlFragment, renderer);
6015
- return cache[cacheKey];
6041
+ const element = createFragmentFn(htmlFragment, renderer);
6042
+ // Cache is only here to prevent calling innerHTML multiple times which doesn't happen on the server.
6043
+ if (process.env.IS_BROWSER) {
6044
+ setInFragmentCache(cacheKey, strings, element);
6045
+ }
6046
+ return element;
6016
6047
  };
6017
6048
  };
6018
6049
  }
@@ -8045,5 +8076,5 @@ function readonly(obj) {
8045
8076
  }
8046
8077
 
8047
8078
  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, shouldBeFormAssociated, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
8048
- /** version: 7.2.1 */
8079
+ /** version: 7.2.2 */
8049
8080
  //# sourceMappingURL=index.js.map