@lwc/ssr-runtime 8.12.0 → 8.12.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
@@ -328,14 +328,14 @@ function isObject(obj) {
328
328
  function isString(obj) {
329
329
  return typeof obj === 'string';
330
330
  }
331
- const OtS$1 = {}.toString;
331
+ const OtS = {}.toString;
332
332
  /**
333
333
  * Converts the argument to a string, safely accounting for objects with "null" prototype.
334
334
  * Note that `toString(null)` returns `"[object Null]"` rather than `"null"`.
335
335
  * @param obj Value to convert to a string.
336
336
  * @returns String representation of the value.
337
337
  */
338
- function toString$1(obj) {
338
+ function toString(obj) {
339
339
  if (obj?.toString) {
340
340
  // Arrays might hold objects with "null" prototype So using
341
341
  // Array.prototype.toString directly will cause an error Iterate through
@@ -351,13 +351,13 @@ function toString$1(obj) {
351
351
  // 4. Array#toString converts recursive references to arrays to ''
352
352
  // Ex: arr = [1]; arr.push(arr, 2); arr.toString() === '1,,2'; toString(arr) throws
353
353
  // Ref: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/toString
354
- return ArrayJoin.call(ArrayMap.call(obj, toString$1), ',');
354
+ return ArrayJoin.call(ArrayMap.call(obj, toString), ',');
355
355
  }
356
356
  return obj.toString();
357
357
  }
358
358
  else if (typeof obj === 'object') {
359
359
  // This catches null and returns "[object Null]". Weird, but kept for backwards compatibility.
360
- return OtS$1.call(obj);
360
+ return OtS.call(obj);
361
361
  }
362
362
  else {
363
363
  return String(obj);
@@ -457,43 +457,6 @@ const { AriaAttrNameToPropNameMap, AriaPropNameToAttrNameMap } = /*@__PURE__*/ (
457
457
  function isAriaAttribute(attrName) {
458
458
  return attrName in AriaAttrNameToPropNameMap;
459
459
  }
460
- // This list is based on https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
461
- const GLOBAL_ATTRIBUTE = /*@__PURE__*/ new Set([
462
- 'accesskey',
463
- 'autocapitalize',
464
- 'autofocus',
465
- 'class',
466
- 'contenteditable',
467
- 'dir',
468
- 'draggable',
469
- 'enterkeyhint',
470
- 'exportparts',
471
- 'hidden',
472
- 'id',
473
- 'inputmode',
474
- 'is',
475
- 'itemid',
476
- 'itemprop',
477
- 'itemref',
478
- 'itemscope',
479
- 'itemtype',
480
- 'lang',
481
- 'nonce',
482
- 'part',
483
- 'slot',
484
- 'spellcheck',
485
- 'style',
486
- 'tabindex',
487
- 'title',
488
- 'translate',
489
- ]);
490
- /**
491
- *
492
- * @param attrName
493
- */
494
- function isGlobalHtmlAttribute(attrName) {
495
- return GLOBAL_ATTRIBUTE.has(attrName);
496
- }
497
460
  // These are HTML standard prop/attribute IDL mappings, but are not predictable based on camel/kebab-case conversion
498
461
  const SPECIAL_PROPERTY_ATTRIBUTE_MAPPING = /*@__PURE__@*/ new Map([
499
462
  ['accessKey', 'accesskey'],
@@ -513,6 +476,21 @@ const SPECIAL_PROPERTY_ATTRIBUTE_MAPPING = /*@__PURE__@*/ new Map([
513
476
  ['useMap', 'usemap'],
514
477
  ['htmlFor', 'for'],
515
478
  ]);
479
+ // Global properties that this framework currently reflects. For CSR, the native
480
+ // descriptors for these properties are added from HTMLElement.prototype to
481
+ // LightningElement.prototype. For SSR, in order to match CSR behavior, this
482
+ // list is used to determine which attributes to reflect.
483
+ const REFLECTIVE_GLOBAL_PROPERTY_SET = /*@__PURE__@*/ new Set([
484
+ 'accessKey',
485
+ 'dir',
486
+ 'draggable',
487
+ 'hidden',
488
+ 'id',
489
+ 'lang',
490
+ 'spellcheck',
491
+ 'tabIndex',
492
+ 'title',
493
+ ]);
516
494
  /**
517
495
  * Map associating previously transformed HTML property into HTML attribute.
518
496
  */
@@ -649,7 +627,7 @@ function setHooks(hooks) {
649
627
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
650
628
  */
651
629
  const DEFAULT_SSR_MODE = 'sync';
652
- /** version: 8.12.0 */
630
+ /** version: 8.12.2 */
653
631
 
654
632
  /*
655
633
  * Copyright (c) 2024, Salesforce, Inc.
@@ -733,18 +711,6 @@ class ClassList {
733
711
  const { isArray } = Array;
734
712
  const { prototype: ObjectDotPrototype, getPrototypeOf, create: ObjectCreate, defineProperty: ObjectDefineProperty, isExtensible, getOwnPropertyDescriptor, getOwnPropertyNames, getOwnPropertySymbols, preventExtensions, hasOwnProperty, } = Object;
735
713
  const { push: ArrayPush, concat: ArrayConcat } = Array.prototype;
736
- const OtS = {}.toString;
737
- function toString(obj) {
738
- if (obj && obj.toString) {
739
- return obj.toString();
740
- }
741
- else if (typeof obj === 'object') {
742
- return OtS.call(obj);
743
- }
744
- else {
745
- return obj + '';
746
- }
747
- }
748
714
  function isUndefined(obj) {
749
715
  return obj === undefined;
750
716
  }
@@ -982,10 +948,6 @@ class ReactiveProxyHandler extends BaseProxyHandler {
982
948
  return true;
983
949
  }
984
950
  setPrototypeOf(shadowTarget, prototype) {
985
- /* istanbul ignore else */
986
- if (process.env.NODE_ENV !== 'production') {
987
- throw new Error(`Invalid setPrototypeOf invocation for reactive proxy ${toString(this.originalTarget)}. Prototype of reactive objects cannot be changed.`);
988
- }
989
951
  }
990
952
  preventExtensions(shadowTarget) {
991
953
  if (isExtensible(shadowTarget)) {
@@ -1049,147 +1011,31 @@ class ReadOnlyHandler extends BaseProxyHandler {
1049
1011
  if (!isUndefined(wrappedSetter)) {
1050
1012
  return wrappedSetter;
1051
1013
  }
1052
- const handler = this;
1053
1014
  const set = function (v) {
1054
- /* istanbul ignore else */
1055
- if (process.env.NODE_ENV !== 'production') {
1056
- const { originalTarget } = handler;
1057
- throw new Error(`Invalid mutation: Cannot invoke a setter on "${originalTarget}". "${originalTarget}" is read-only.`);
1058
- }
1059
1015
  };
1060
1016
  setterMap.set(originalSet, set);
1061
1017
  return set;
1062
1018
  }
1063
1019
  set(shadowTarget, key, value) {
1064
- /* istanbul ignore else */
1065
- if (process.env.NODE_ENV !== 'production') {
1066
- const { originalTarget } = this;
1067
- const msg = isArray(originalTarget)
1068
- ? `Invalid mutation: Cannot mutate array at index ${key.toString()}. Array is read-only.`
1069
- : `Invalid mutation: Cannot set "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`;
1070
- throw new Error(msg);
1071
- }
1072
1020
  /* istanbul ignore next */
1073
1021
  return false;
1074
1022
  }
1075
1023
  deleteProperty(shadowTarget, key) {
1076
- /* istanbul ignore else */
1077
- if (process.env.NODE_ENV !== 'production') {
1078
- const { originalTarget } = this;
1079
- throw new Error(`Invalid mutation: Cannot delete "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
1080
- }
1081
1024
  /* istanbul ignore next */
1082
1025
  return false;
1083
1026
  }
1084
1027
  setPrototypeOf(shadowTarget, prototype) {
1085
- /* istanbul ignore else */
1086
- if (process.env.NODE_ENV !== 'production') {
1087
- const { originalTarget } = this;
1088
- throw new Error(`Invalid prototype mutation: Cannot set prototype on "${originalTarget}". "${originalTarget}" prototype is read-only.`);
1089
- }
1090
1028
  }
1091
1029
  preventExtensions(shadowTarget) {
1092
- /* istanbul ignore else */
1093
- if (process.env.NODE_ENV !== 'production') {
1094
- const { originalTarget } = this;
1095
- throw new Error(`Invalid mutation: Cannot preventExtensions on ${originalTarget}". "${originalTarget} is read-only.`);
1096
- }
1097
1030
  /* istanbul ignore next */
1098
1031
  return false;
1099
1032
  }
1100
1033
  defineProperty(shadowTarget, key, descriptor) {
1101
- /* istanbul ignore else */
1102
- if (process.env.NODE_ENV !== 'production') {
1103
- const { originalTarget } = this;
1104
- throw new Error(`Invalid mutation: Cannot defineProperty "${key.toString()}" on "${originalTarget}". "${originalTarget}" is read-only.`);
1105
- }
1106
1034
  /* istanbul ignore next */
1107
1035
  return false;
1108
1036
  }
1109
1037
  }
1110
1038
 
1111
- function extract(objectOrArray) {
1112
- if (isArray(objectOrArray)) {
1113
- return objectOrArray.map((item) => {
1114
- const original = unwrap(item);
1115
- if (original !== item) {
1116
- return extract(original);
1117
- }
1118
- return item;
1119
- });
1120
- }
1121
- const obj = ObjectCreate(getPrototypeOf(objectOrArray));
1122
- const names = getOwnPropertyNames(objectOrArray);
1123
- return ArrayConcat.call(names, getOwnPropertySymbols(objectOrArray)).reduce((seed, key) => {
1124
- const item = objectOrArray[key];
1125
- const original = unwrap(item);
1126
- if (original !== item) {
1127
- seed[key] = extract(original);
1128
- }
1129
- else {
1130
- seed[key] = item;
1131
- }
1132
- return seed;
1133
- }, obj);
1134
- }
1135
- const formatter = {
1136
- header: (plainOrProxy) => {
1137
- const originalTarget = unwrap(plainOrProxy);
1138
- // if originalTarget is falsy or not unwrappable, exit
1139
- if (!originalTarget || originalTarget === plainOrProxy) {
1140
- return null;
1141
- }
1142
- const obj = extract(plainOrProxy);
1143
- return ['object', { object: obj }];
1144
- },
1145
- hasBody: () => {
1146
- return false;
1147
- },
1148
- body: () => {
1149
- return null;
1150
- },
1151
- };
1152
- // Inspired from paulmillr/es6-shim
1153
- // https://github.com/paulmillr/es6-shim/blob/master/es6-shim.js#L176-L185
1154
- /* istanbul ignore next */
1155
- function getGlobal() {
1156
- // the only reliable means to get the global object is `Function('return this')()`
1157
- // However, this causes CSP violations in Chrome apps.
1158
- if (typeof globalThis !== 'undefined') {
1159
- return globalThis;
1160
- }
1161
- if (typeof self !== 'undefined') {
1162
- return self;
1163
- }
1164
- if (typeof window !== 'undefined') {
1165
- return window;
1166
- }
1167
- if (typeof global !== 'undefined') {
1168
- return global;
1169
- }
1170
- // Gracefully degrade if not able to locate the global object
1171
- return {};
1172
- }
1173
- function init() {
1174
- /* istanbul ignore if */
1175
- if (process.env.NODE_ENV === 'production') {
1176
- // this method should never leak to prod
1177
- throw new ReferenceError();
1178
- }
1179
- const global = getGlobal();
1180
- // Custom Formatter for Dev Tools. To enable this, open Chrome Dev Tools
1181
- // - Go to Settings,
1182
- // - Under console, select "Enable custom formatters"
1183
- // For more information, https://docs.google.com/document/d/1FTascZXT9cxfetuPRT2eXPQKXui4nWFivUnS_335T3U/preview
1184
- const devtoolsFormatters = global.devtoolsFormatters || [];
1185
- ArrayPush.call(devtoolsFormatters, formatter);
1186
- global.devtoolsFormatters = devtoolsFormatters;
1187
- }
1188
-
1189
- /* istanbul ignore else */
1190
- if (process.env.NODE_ENV !== 'production') {
1191
- init();
1192
- }
1193
1039
  function defaultValueIsObservable(value) {
1194
1040
  // intentionally checking for null
1195
1041
  if (value === null) {
@@ -1381,7 +1227,7 @@ function filterProperties(props, publicFields, privateFields) {
1381
1227
  keys(props).forEach((propName) => {
1382
1228
  const attrName = htmlPropertyToAttribute(propName);
1383
1229
  if (publicFieldSet.has(propName) ||
1384
- ((isGlobalHtmlAttribute(attrName) || isAriaAttribute(attrName)) &&
1230
+ ((REFLECTIVE_GLOBAL_PROPERTY_SET.has(propName) || isAriaAttribute(attrName)) &&
1385
1231
  !privateFieldSet.has(propName))) {
1386
1232
  propsToAssign[propName] = props[propName];
1387
1233
  }
@@ -1467,7 +1313,7 @@ const ariaDescriptor = (attrName) => ({
1467
1313
  this.removeAttribute(attrName);
1468
1314
  }
1469
1315
  else {
1470
- this.setAttribute(attrName, toString$1(newValue));
1316
+ this.setAttribute(attrName, toString(newValue));
1471
1317
  }
1472
1318
  }
1473
1319
  },
@@ -1485,7 +1331,7 @@ const tabIndexDescriptor = () => ({
1485
1331
  const num = Number(newValue);
1486
1332
  const normalizedValue = isFinite(num) ? String(Math.trunc(num)) : '0';
1487
1333
  if (normalizedValue !== currentValue) {
1488
- this.setAttribute('tabindex', toString$1(newValue));
1334
+ this.setAttribute('tabindex', toString(newValue));
1489
1335
  }
1490
1336
  },
1491
1337
  });
@@ -1544,24 +1390,24 @@ class LightningElement {
1544
1390
  return (__classPrivateFieldSet(this, _LightningElement_classList, new ClassList(this), "f"));
1545
1391
  }
1546
1392
  setAttribute(attrName, attrValue) {
1547
- const normalizedName = StringToLowerCase.call(toString$1(attrName));
1393
+ const normalizedName = StringToLowerCase.call(toString(attrName));
1548
1394
  const normalizedValue = String(attrValue);
1549
1395
  __classPrivateFieldGet(this, _LightningElement_attrs, "f")[normalizedName] = normalizedValue;
1550
1396
  mutationTracker.add(this, normalizedName);
1551
1397
  }
1552
1398
  getAttribute(attrName) {
1553
- const normalizedName = StringToLowerCase.call(toString$1(attrName));
1399
+ const normalizedName = StringToLowerCase.call(toString(attrName));
1554
1400
  if (hasOwnProperty$1.call(__classPrivateFieldGet(this, _LightningElement_attrs, "f"), normalizedName)) {
1555
1401
  return __classPrivateFieldGet(this, _LightningElement_attrs, "f")[normalizedName];
1556
1402
  }
1557
1403
  return null;
1558
1404
  }
1559
1405
  hasAttribute(attrName) {
1560
- const normalizedName = StringToLowerCase.call(toString$1(attrName));
1406
+ const normalizedName = StringToLowerCase.call(toString(attrName));
1561
1407
  return hasOwnProperty$1.call(__classPrivateFieldGet(this, _LightningElement_attrs, "f"), normalizedName);
1562
1408
  }
1563
1409
  removeAttribute(attrName) {
1564
- const normalizedName = StringToLowerCase.call(toString$1(attrName));
1410
+ const normalizedName = StringToLowerCase.call(toString(attrName));
1565
1411
  delete __classPrivateFieldGet(this, _LightningElement_attrs, "f")[normalizedName];
1566
1412
  // Track mutations for removal of non-existing attributes
1567
1413
  mutationTracker.add(this, normalizedName);
@@ -1660,6 +1506,12 @@ function renderAttrsPrivate(instance, attrs, hostScopeToken, scopeToken) {
1660
1506
  let hasClassAttribute = false;
1661
1507
  for (const attrName of getOwnPropertyNames$1(attrs)) {
1662
1508
  let attrValue = attrs[attrName];
1509
+ // Backwards compatibility with historical patchStyleAttribute() behavior:
1510
+ // https://github.com/salesforce/lwc/blob/59e2c6c/packages/%40lwc/engine-core/src/framework/modules/computed-style-attr.ts#L40
1511
+ if (attrName === 'style' && (!isString(attrValue) || attrValue === '')) {
1512
+ // If the style attribute is invalid, we don't render it.
1513
+ continue;
1514
+ }
1663
1515
  if (isNull(attrValue) || isUndefined$1(attrValue)) {
1664
1516
  attrValue = '';
1665
1517
  }
@@ -1934,5 +1786,5 @@ function createContextProvider(adapter) {
1934
1786
  }
1935
1787
 
1936
1788
  export { ClassList, LightningElement, SYMBOL__DEFAULT_TEMPLATE, SYMBOL__GENERATE_MARKUP, SYMBOL__SET_INTERNALS, api, connectContext, createContextProvider, createElement, establishContextfulRelationship, fallbackTmpl, fallbackTmplNoYield, filterProperties, freezeTemplate, getComponentDef, getReadOnlyProxy, hasScopedStaticStylesheets, hot, htmlEscape, isComponentConstructor, massageTextContent, mutationTracker, normalizeClass, parseFragment, parseSVGFragment, readonly, registerComponent, registerDecorators, registerTemplate, renderAttrs, renderAttrsNoYield, serverSideRenderComponent as renderComponent, renderStylesheets, renderer, sanitizeAttribute, sanitizeHtmlContent, serverSideRenderComponent, setFeatureFlag, setFeatureFlagForTest, setHooks, swapComponent, swapStyle, swapTemplate, toIteratorDirective, track, unwrap$1 as unwrap, validateStyleTextContents, wire };
1937
- /** version: 8.12.0 */
1789
+ /** version: 8.12.2 */
1938
1790
  //# sourceMappingURL=index.js.map