@lwc/engine-core 8.11.0 → 8.12.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.
@@ -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
@@ -1091,18 +1091,6 @@ function updateComponentValue(vm, key, newValue) {
1091
1091
  const { isArray } = Array;
1092
1092
  const { prototype: ObjectDotPrototype, getPrototypeOf, create: ObjectCreate, defineProperty: ObjectDefineProperty, isExtensible, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, preventExtensions, hasOwnProperty, } = Object;
1093
1093
  const { push: ArrayPush, concat: ArrayConcat } = Array.prototype;
1094
- const OtS = {}.toString;
1095
- function toString(obj) {
1096
- if (obj && obj.toString) {
1097
- return obj.toString();
1098
- }
1099
- else if (typeof obj === 'object') {
1100
- return OtS.call(obj);
1101
- }
1102
- else {
1103
- return obj + '';
1104
- }
1105
- }
1106
1094
  function isUndefined(obj) {
1107
1095
  return obj === undefined;
1108
1096
  }
@@ -1340,10 +1328,6 @@ class ReactiveProxyHandler extends BaseProxyHandler {
1340
1328
  return true;
1341
1329
  }
1342
1330
  setPrototypeOf(shadowTarget, prototype) {
1343
- /* istanbul ignore else */
1344
- if (process.env.NODE_ENV !== 'production') {
1345
- throw new Error(`Invalid setPrototypeOf invocation for reactive proxy ${toString(this.originalTarget)}. Prototype of reactive objects cannot be changed.`);
1346
- }
1347
1331
  }
1348
1332
  preventExtensions(shadowTarget) {
1349
1333
  if (isExtensible(shadowTarget)) {
@@ -1407,147 +1391,31 @@ class ReadOnlyHandler extends BaseProxyHandler {
1407
1391
  if (!isUndefined(wrappedSetter)) {
1408
1392
  return wrappedSetter;
1409
1393
  }
1410
- const handler = this;
1411
1394
  const set = function (v) {
1412
- /* istanbul ignore else */
1413
- if (process.env.NODE_ENV !== 'production') {
1414
- const { originalTarget } = handler;
1415
- throw new Error(`Invalid mutation: Cannot invoke a setter on "${originalTarget}". "${originalTarget}" is read-only.`);
1416
- }
1417
1395
  };
1418
1396
  setterMap.set(originalSet, set);
1419
1397
  return set;
1420
1398
  }
1421
1399
  set(shadowTarget, key, value) {
1422
- /* istanbul ignore else */
1423
- if (process.env.NODE_ENV !== 'production') {
1424
- const { originalTarget } = this;
1425
- const msg = isArray(originalTarget)
1426
- ? `Invalid mutation: Cannot mutate array at index ${key.toString()}. Array is read-only.`
1427
- : `Invalid mutation: Cannot set "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`;
1428
- throw new Error(msg);
1429
- }
1430
1400
  /* istanbul ignore next */
1431
1401
  return false;
1432
1402
  }
1433
1403
  deleteProperty(shadowTarget, key) {
1434
- /* istanbul ignore else */
1435
- if (process.env.NODE_ENV !== 'production') {
1436
- const { originalTarget } = this;
1437
- throw new Error(`Invalid mutation: Cannot delete "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
1438
- }
1439
1404
  /* istanbul ignore next */
1440
1405
  return false;
1441
1406
  }
1442
1407
  setPrototypeOf(shadowTarget, prototype) {
1443
- /* istanbul ignore else */
1444
- if (process.env.NODE_ENV !== 'production') {
1445
- const { originalTarget } = this;
1446
- throw new Error(`Invalid prototype mutation: Cannot set prototype on "${originalTarget}". "${originalTarget}" prototype is read-only.`);
1447
- }
1448
1408
  }
1449
1409
  preventExtensions(shadowTarget) {
1450
- /* istanbul ignore else */
1451
- if (process.env.NODE_ENV !== 'production') {
1452
- const { originalTarget } = this;
1453
- throw new Error(`Invalid mutation: Cannot preventExtensions on ${originalTarget}". "${originalTarget} is read-only.`);
1454
- }
1455
1410
  /* istanbul ignore next */
1456
1411
  return false;
1457
1412
  }
1458
1413
  defineProperty(shadowTarget, key, descriptor) {
1459
- /* istanbul ignore else */
1460
- if (process.env.NODE_ENV !== 'production') {
1461
- const { originalTarget } = this;
1462
- throw new Error(`Invalid mutation: Cannot defineProperty "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
1463
- }
1464
1414
  /* istanbul ignore next */
1465
1415
  return false;
1466
1416
  }
1467
1417
  }
1468
1418
 
1469
- function extract(objectOrArray) {
1470
- if (isArray(objectOrArray)) {
1471
- return objectOrArray.map((item) => {
1472
- const original = unwrap$1(item);
1473
- if (original !== item) {
1474
- return extract(original);
1475
- }
1476
- return item;
1477
- });
1478
- }
1479
- const obj = ObjectCreate(getPrototypeOf(objectOrArray));
1480
- const names = getOwnPropertyNames(objectOrArray);
1481
- return ArrayConcat.call(names, getOwnPropertySymbols(objectOrArray)).reduce((seed, key) => {
1482
- const item = objectOrArray[key];
1483
- const original = unwrap$1(item);
1484
- if (original !== item) {
1485
- seed[key] = extract(original);
1486
- }
1487
- else {
1488
- seed[key] = item;
1489
- }
1490
- return seed;
1491
- }, obj);
1492
- }
1493
- const formatter = {
1494
- header: (plainOrProxy) => {
1495
- const originalTarget = unwrap$1(plainOrProxy);
1496
- // if originalTarget is falsy or not unwrappable, exit
1497
- if (!originalTarget || originalTarget === plainOrProxy) {
1498
- return null;
1499
- }
1500
- const obj = extract(plainOrProxy);
1501
- return ['object', { object: obj }];
1502
- },
1503
- hasBody: () => {
1504
- return false;
1505
- },
1506
- body: () => {
1507
- return null;
1508
- },
1509
- };
1510
- // Inspired from paulmillr/es6-shim
1511
- // https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js#L176-L185
1512
- /* istanbul ignore next */
1513
- function getGlobal() {
1514
- // the only reliable means to get the global object is `Function('return this')()`
1515
- // However, this causes CSP violations in Chrome apps.
1516
- if (typeof globalThis !== 'undefined') {
1517
- return globalThis;
1518
- }
1519
- if (typeof self !== 'undefined') {
1520
- return self;
1521
- }
1522
- if (typeof window !== 'undefined') {
1523
- return window;
1524
- }
1525
- if (typeof global !== 'undefined') {
1526
- return global;
1527
- }
1528
- // Gracefully degrade if not able to locate the global object
1529
- return {};
1530
- }
1531
- function init() {
1532
- /* istanbul ignore if */
1533
- if (process.env.NODE_ENV === 'production') {
1534
- // this method should never leak to prod
1535
- throw new ReferenceError();
1536
- }
1537
- const global = getGlobal();
1538
- // Custom Formatter for Dev Tools. To enable this, open Chrome Dev Tools
1539
- // - Go to Settings,
1540
- // - Under console, select "Enable custom formatters"
1541
- // For more information, https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview
1542
- const devtoolsFormatters = global.devtoolsFormatters || [];
1543
- ArrayPush.call(devtoolsFormatters, formatter);
1544
- global.devtoolsFormatters = devtoolsFormatters;
1545
- }
1546
-
1547
- /* istanbul ignore else */
1548
- if (process.env.NODE_ENV !== 'production') {
1549
- init();
1550
- }
1551
1419
  function defaultValueIsObservable(value) {
1552
1420
  // intentionally checking for null
1553
1421
  if (value === null) {
@@ -5932,45 +5800,7 @@ function shc(content) {
5932
5800
  const sanitizedString = shared.sanitizeHtmlContent(content);
5933
5801
  return createSanitizedHtmlContent(sanitizedString);
5934
5802
  }
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
- }
5803
+ const ncls = shared.normalizeClass;
5974
5804
  const api = shared.freeze({
5975
5805
  s,
5976
5806
  h,
@@ -7723,6 +7553,8 @@ if (process.env.IS_BROWSER && isGlobalAriaPolyfillLoaded()) {
7723
7553
  * SPDX-License-Identifier: MIT
7724
7554
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
7725
7555
  */
7556
+ // Used as a perf optimization to avoid creating and discarding sets unnecessarily.
7557
+ const EMPTY_SET = new Set();
7726
7558
  // flag indicating if the hydration recovered from the DOM mismatch
7727
7559
  let hasMismatch = false;
7728
7560
  function hydrateRoot(vm) {
@@ -8098,6 +7930,22 @@ function validateAttrs(vnode, elm, data, renderer, shouldValidateAttr) {
8098
7930
  }
8099
7931
  return nodesAreCompatible;
8100
7932
  }
7933
+ function checkClassesCompatibility(first, second) {
7934
+ if (first.size !== second.size) {
7935
+ return false;
7936
+ }
7937
+ for (const f of first) {
7938
+ if (!second.has(f)) {
7939
+ return false;
7940
+ }
7941
+ }
7942
+ for (const s of second) {
7943
+ if (!first.has(s)) {
7944
+ return false;
7945
+ }
7946
+ }
7947
+ return true;
7948
+ }
8101
7949
  function validateClassAttr(vnode, elm, data, renderer) {
8102
7950
  const { owner } = vnode;
8103
7951
  // classMap is never available on VStaticPartData so it can default to undefined
@@ -8107,17 +7955,19 @@ function validateClassAttr(vnode, elm, data, renderer) {
8107
7955
  // ---------- Step 1: get the classes from the element and the vnode
8108
7956
  // Use a Set because we don't care to validate mismatches for 1) different ordering in SSR vs CSR, or 2)
8109
7957
  // duplicated class names. These don't have an effect on rendered styles.
8110
- const elmClasses = new Set(shared.ArrayFrom(elm.classList));
7958
+ const elmClasses = elm.classList.length ? new Set(shared.ArrayFrom(elm.classList)) : EMPTY_SET;
8111
7959
  let vnodeClasses;
8112
7960
  if (!shared.isUndefined(className)) {
8113
7961
  // ignore empty spaces entirely, filter them out using `filter(..., Boolean)`
8114
- vnodeClasses = new Set(shared.ArrayFilter.call(shared.StringSplit.call(className, /\s+/), Boolean));
7962
+ const classes = shared.ArrayFilter.call(shared.StringSplit.call(className, /\s+/), Boolean);
7963
+ vnodeClasses = classes.length ? new Set(classes) : EMPTY_SET;
8115
7964
  }
8116
7965
  else if (!shared.isUndefined(classMap)) {
8117
- vnodeClasses = new Set(shared.keys(classMap));
7966
+ const classes = shared.keys(classMap);
7967
+ vnodeClasses = classes.length ? new Set(classes) : EMPTY_SET;
8118
7968
  }
8119
7969
  else {
8120
- vnodeClasses = new Set();
7970
+ vnodeClasses = EMPTY_SET;
8121
7971
  }
8122
7972
  // ---------- Step 2: handle the scope tokens
8123
7973
  // we don't care about legacy for hydration. it's a new use case
@@ -8129,7 +7979,12 @@ function validateClassAttr(vnode, elm, data, renderer) {
8129
7979
  // Consequently, hydration mismatches will occur if scoped CSS token classnames
8130
7980
  // are rendered during SSR. This needs to be accounted for when validating.
8131
7981
  if (!shared.isNull(scopeToken)) {
8132
- vnodeClasses.add(scopeToken);
7982
+ if (vnodeClasses === EMPTY_SET) {
7983
+ vnodeClasses = new Set([scopeToken]);
7984
+ }
7985
+ else {
7986
+ vnodeClasses.add(scopeToken);
7987
+ }
8133
7988
  }
8134
7989
  // This tells us which `*-host` scope token was rendered to the element's class.
8135
7990
  // For now we just ignore any mismatches involving this class.
@@ -8140,27 +7995,12 @@ function validateClassAttr(vnode, elm, data, renderer) {
8140
7995
  vnodeClasses.delete(elmHostScopeToken);
8141
7996
  }
8142
7997
  // ---------- 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) {
7998
+ const classesAreCompatible = checkClassesCompatibility(vnodeClasses, elmClasses);
7999
+ if (process.env.NODE_ENV !== 'production' && !classesAreCompatible) {
8160
8000
  const prettyPrint = (set) => JSON.stringify(shared.ArrayJoin.call(shared.ArraySort.call(shared.ArrayFrom(set)), ' '));
8161
8001
  logWarn(`Mismatch hydrating element <${getProperty(elm, 'tagName').toLowerCase()}>: attribute "class" has different values, expected ${prettyPrint(vnodeClasses)} but found ${prettyPrint(elmClasses)}`, vnode.owner);
8162
8002
  }
8163
- return nodesAreCompatible;
8003
+ return classesAreCompatible;
8164
8004
  }
8165
8005
  function validateStyleAttr(vnode, elm, data, renderer) {
8166
8006
  // Note styleDecls is always undefined for VStaticPartData, casting here to default it to undefined
@@ -8599,5 +8439,5 @@ exports.swapTemplate = swapTemplate;
8599
8439
  exports.track = track;
8600
8440
  exports.unwrap = unwrap;
8601
8441
  exports.wire = wire;
8602
- /** version: 8.11.0 */
8442
+ /** version: 8.12.1 */
8603
8443
  //# sourceMappingURL=index.cjs.js.map