@lwc/engine-core 8.11.0 → 8.12.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.
@@ -1,3 +1,4 @@
1
+ import { normalizeClass } from '@lwc/shared';
1
2
  import type { SanitizedHtmlContent } from './sanitized-html-content';
2
3
  import type { Key, VComment, VCustomElement, VElement, VElementData, VFragment, VNode, VNodes, VScopedSlotFragment, VStatic, VStaticPart, VStaticPartData, VText } from './vnodes';
3
4
  import type { LightningElementConstructor } from './base-lightning-element';
@@ -41,16 +42,6 @@ declare function ddc(sel: string, Ctor: LightningElementConstructor | null | und
41
42
  */
42
43
  declare function dc(Ctor: LightningElementConstructor | null | undefined, data: VElementData, children?: VNodes): VCustomElement | null;
43
44
  declare function shc(content: unknown): SanitizedHtmlContent;
44
- /**
45
- * [ncls] - Normalize class name attribute.
46
- *
47
- * Transforms the provided class property value from an object/string into a string the diffing algo
48
- * can operate on.
49
- *
50
- * This implementation is borrowed from Vue:
51
- * https://github.com/vuejs/core/blob/e790e1bdd7df7be39e14780529db86e4da47a3db/packages/shared/src/normalizeProp.ts#L63-L82
52
- */
53
- declare function ncls(value: unknown): string | undefined;
54
45
  declare const api: Readonly<{
55
46
  s: typeof s;
56
47
  h: typeof h;
@@ -72,7 +63,7 @@ declare const api: Readonly<{
72
63
  ssf: typeof ssf;
73
64
  ddc: typeof ddc;
74
65
  sp: typeof sp;
75
- ncls: typeof ncls;
66
+ ncls: typeof normalizeClass;
76
67
  }>;
77
68
  export default api;
78
69
  export type RenderAPI = typeof api;
package/dist/index.cjs.js CHANGED
@@ -5932,45 +5932,7 @@ function shc(content) {
5932
5932
  const sanitizedString = shared.sanitizeHtmlContent(content);
5933
5933
  return createSanitizedHtmlContent(sanitizedString);
5934
5934
  }
5935
- /**
5936
- * [ncls] - Normalize class name attribute.
5937
- *
5938
- * Transforms the provided class property value from an object/string into a string the diffing algo
5939
- * can operate on.
5940
- *
5941
- * This implementation is borrowed from Vue:
5942
- * https://github.com/vuejs/core/blob/e790e1bdd7df7be39e14780529db86e4da47a3db/packages/shared/src/normalizeProp.ts#L63-L82
5943
- */
5944
- function ncls(value) {
5945
- if (shared.isUndefined(value) || shared.isNull(value)) {
5946
- // Returning undefined here improves initial render cost, because the old vnode's class will be considered
5947
- // undefined in the `patchClassAttribute` routine, so `oldClass === newClass` will be true so we return early
5948
- return undefined;
5949
- }
5950
- let res = '';
5951
- if (shared.isString(value)) {
5952
- res = value;
5953
- }
5954
- else if (shared.isArray(value)) {
5955
- for (let i = 0; i < value.length; i++) {
5956
- const normalized = ncls(value[i]);
5957
- if (normalized) {
5958
- res += normalized + ' ';
5959
- }
5960
- }
5961
- }
5962
- else if (shared.isObject(value) && !shared.isNull(value)) {
5963
- // Iterate own enumerable keys of the object
5964
- const keys = shared.keys(value);
5965
- for (let i = 0; i < keys.length; i += 1) {
5966
- const key = keys[i];
5967
- if (value[key]) {
5968
- res += key + ' ';
5969
- }
5970
- }
5971
- }
5972
- return shared.StringTrim.call(res);
5973
- }
5935
+ const ncls = shared.normalizeClass;
5974
5936
  const api = shared.freeze({
5975
5937
  s,
5976
5938
  h,
@@ -7723,6 +7685,8 @@ if (process.env.IS_BROWSER && isGlobalAriaPolyfillLoaded()) {
7723
7685
  * SPDX-License-Identifier: MIT
7724
7686
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7725
7687
  */
7688
+ // Used as a perf optimization to avoid creating and discarding sets unnecessarily.
7689
+ const EMPTY_SET = new Set();
7726
7690
  // flag indicating if the hydration recovered from the DOM mismatch
7727
7691
  let hasMismatch = false;
7728
7692
  function hydrateRoot(vm) {
@@ -8098,6 +8062,22 @@ function validateAttrs(vnode, elm, data, renderer, shouldValidateAttr) {
8098
8062
  }
8099
8063
  return nodesAreCompatible;
8100
8064
  }
8065
+ function checkClassesCompatibility(first, second) {
8066
+ if (first.size !== second.size) {
8067
+ return false;
8068
+ }
8069
+ for (const f of first) {
8070
+ if (!second.has(f)) {
8071
+ return false;
8072
+ }
8073
+ }
8074
+ for (const s of second) {
8075
+ if (!first.has(s)) {
8076
+ return false;
8077
+ }
8078
+ }
8079
+ return true;
8080
+ }
8101
8081
  function validateClassAttr(vnode, elm, data, renderer) {
8102
8082
  const { owner } = vnode;
8103
8083
  // classMap is never available on VStaticPartData so it can default to undefined
@@ -8107,17 +8087,19 @@ function validateClassAttr(vnode, elm, data, renderer) {
8107
8087
  // ---------- Step 1: get the classes from the element and the vnode
8108
8088
  // Use a Set because we don't care to validate mismatches for 1) different ordering in SSR vs CSR, or 2)
8109
8089
  // duplicated class names. These don't have an effect on rendered styles.
8110
- const elmClasses = new Set(shared.ArrayFrom(elm.classList));
8090
+ const elmClasses = elm.classList.length ? new Set(shared.ArrayFrom(elm.classList)) : EMPTY_SET;
8111
8091
  let vnodeClasses;
8112
8092
  if (!shared.isUndefined(className)) {
8113
8093
  // ignore empty spaces entirely, filter them out using `filter(..., Boolean)`
8114
- vnodeClasses = new Set(shared.ArrayFilter.call(shared.StringSplit.call(className, /\s+/), Boolean));
8094
+ const classes = shared.ArrayFilter.call(shared.StringSplit.call(className, /\s+/), Boolean);
8095
+ vnodeClasses = classes.length ? new Set(classes) : EMPTY_SET;
8115
8096
  }
8116
8097
  else if (!shared.isUndefined(classMap)) {
8117
- vnodeClasses = new Set(shared.keys(classMap));
8098
+ const classes = shared.keys(classMap);
8099
+ vnodeClasses = classes.length ? new Set(classes) : EMPTY_SET;
8118
8100
  }
8119
8101
  else {
8120
- vnodeClasses = new Set();
8102
+ vnodeClasses = EMPTY_SET;
8121
8103
  }
8122
8104
  // ---------- Step 2: handle the scope tokens
8123
8105
  // we don't care about legacy for hydration. it's a new use case
@@ -8129,7 +8111,12 @@ function validateClassAttr(vnode, elm, data, renderer) {
8129
8111
  // Consequently, hydration mismatches will occur if scoped CSS token classnames
8130
8112
  // are rendered during SSR. This needs to be accounted for when validating.
8131
8113
  if (!shared.isNull(scopeToken)) {
8132
- vnodeClasses.add(scopeToken);
8114
+ if (vnodeClasses === EMPTY_SET) {
8115
+ vnodeClasses = new Set([scopeToken]);
8116
+ }
8117
+ else {
8118
+ vnodeClasses.add(scopeToken);
8119
+ }
8133
8120
  }
8134
8121
  // This tells us which `*-host` scope token was rendered to the element's class.
8135
8122
  // For now we just ignore any mismatches involving this class.
@@ -8140,27 +8127,12 @@ function validateClassAttr(vnode, elm, data, renderer) {
8140
8127
  vnodeClasses.delete(elmHostScopeToken);
8141
8128
  }
8142
8129
  // ---------- Step 3: check for compatibility
8143
- let nodesAreCompatible = true;
8144
- if (vnodeClasses.size !== elmClasses.size) {
8145
- nodesAreCompatible = false;
8146
- }
8147
- else {
8148
- for (const vnodeClass of vnodeClasses) {
8149
- if (!elmClasses.has(vnodeClass)) {
8150
- nodesAreCompatible = false;
8151
- }
8152
- }
8153
- for (const elmClass of elmClasses) {
8154
- if (!vnodeClasses.has(elmClass)) {
8155
- nodesAreCompatible = false;
8156
- }
8157
- }
8158
- }
8159
- if (process.env.NODE_ENV !== 'production' && !nodesAreCompatible) {
8130
+ const classesAreCompatible = checkClassesCompatibility(vnodeClasses, elmClasses);
8131
+ if (process.env.NODE_ENV !== 'production' && !classesAreCompatible) {
8160
8132
  const prettyPrint = (set) => JSON.stringify(shared.ArrayJoin.call(shared.ArraySort.call(shared.ArrayFrom(set)), ' '));
8161
8133
  logWarn(`Mismatch hydrating element <${getProperty(elm, 'tagName').toLowerCase()}>: attribute "class" has different values, expected ${prettyPrint(vnodeClasses)} but found ${prettyPrint(elmClasses)}`, vnode.owner);
8162
8134
  }
8163
- return nodesAreCompatible;
8135
+ return classesAreCompatible;
8164
8136
  }
8165
8137
  function validateStyleAttr(vnode, elm, data, renderer) {
8166
8138
  // Note styleDecls is always undefined for VStaticPartData, casting here to default it to undefined
@@ -8599,5 +8571,5 @@ exports.swapTemplate = swapTemplate;
8599
8571
  exports.track = track;
8600
8572
  exports.unwrap = unwrap;
8601
8573
  exports.wire = wire;
8602
- /** version: 8.11.0 */
8574
+ /** version: 8.12.0 */
8603
8575
  //# sourceMappingURL=index.cjs.js.map