@lwc/engine-core 2.45.1 → 2.45.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.
@@ -6240,6 +6240,27 @@ function textNodeContentsAreEqual(node, vnode, renderer) {
6240
6240
  }
6241
6241
  return false;
6242
6242
  }
6243
+ // The validationOptOut static property can be an array of attribute names.
6244
+ // Any attribute names specified in that array will not be validated, and the
6245
+ // LWC runtime will assume that VDOM attrs and DOM attrs are in sync.
6246
+ function getValidationPredicate(optOutStaticProp) {
6247
+ if (shared.isUndefined(optOutStaticProp)) {
6248
+ return (_attrName) => true;
6249
+ }
6250
+ // If validationOptOut is true, no attributes will be checked for correctness
6251
+ // and the runtime will assume VDOM attrs and DOM attrs are in sync.
6252
+ if (shared.isTrue(optOutStaticProp)) {
6253
+ return (_attrName) => false;
6254
+ }
6255
+ // If validationOptOut is an array of strings, attributes specified in the
6256
+ // array will be "opted out". Attributes not specified in the array will still
6257
+ // be validated.
6258
+ if (shared.isArray(optOutStaticProp) && shared.arrayEvery(optOutStaticProp, shared.isString)) {
6259
+ return (attrName) => !shared.ArrayIncludes.call(optOutStaticProp, attrName);
6260
+ }
6261
+ logWarn('Validation opt out must be `true` or an array of attributes that should not be validated.');
6262
+ return (_attrName) => true;
6263
+ }
6243
6264
  function hydrateText(node, vnode, renderer) {
6244
6265
  var _a;
6245
6266
  if (!hasCorrectNodeType(vnode, node, 3 /* EnvNodeTypes.TEXT */, renderer)) {
@@ -6318,8 +6339,19 @@ function hydrateElement(elm, vnode, renderer) {
6318
6339
  return elm;
6319
6340
  }
6320
6341
  function hydrateCustomElement(elm, vnode, renderer) {
6342
+ const { validationOptOut } = vnode.ctor;
6343
+ const shouldValidateAttr = getValidationPredicate(validationOptOut);
6344
+ // The validationOptOut static property can be an array of attribute names.
6345
+ // Any attribute names specified in that array will not be validated, and the
6346
+ // LWC runtime will assume that VDOM attrs and DOM attrs are in sync.
6347
+ //
6348
+ // If validationOptOut is true, no attributes will be checked for correctness
6349
+ // and the runtime will assume VDOM attrs and DOM attrs are in sync.
6350
+ //
6351
+ // Therefore, if validationOptOut is falsey or an array of strings, we need to
6352
+ // examine some or all of the custom element's attributes.
6321
6353
  if (!hasCorrectNodeType(vnode, elm, 1 /* EnvNodeTypes.ELEMENT */, renderer) ||
6322
- !isMatchingElement(vnode, elm, renderer)) {
6354
+ !isMatchingElement(vnode, elm, renderer, shouldValidateAttr)) {
6323
6355
  return handleMismatch(elm, vnode, renderer);
6324
6356
  }
6325
6357
  const { sel, mode, ctor, owner } = vnode;
@@ -6413,7 +6445,7 @@ function hasCorrectNodeType(vnode, node, nodeType, renderer) {
6413
6445
  }
6414
6446
  return true;
6415
6447
  }
6416
- function isMatchingElement(vnode, elm, renderer) {
6448
+ function isMatchingElement(vnode, elm, renderer, shouldValidateAttr = () => true) {
6417
6449
  const { getProperty } = renderer;
6418
6450
  if (vnode.sel.toLowerCase() !== getProperty(elm, 'tagName').toLowerCase()) {
6419
6451
  if (process.env.NODE_ENV !== 'production') {
@@ -6421,10 +6453,14 @@ function isMatchingElement(vnode, elm, renderer) {
6421
6453
  }
6422
6454
  return false;
6423
6455
  }
6424
- const hasIncompatibleAttrs = validateAttrs(vnode, elm, renderer);
6425
- const hasIncompatibleClass = validateClassAttr(vnode, elm, renderer);
6426
- const hasIncompatibleStyle = validateStyleAttr(vnode, elm, renderer);
6427
- return hasIncompatibleAttrs && hasIncompatibleClass && hasIncompatibleStyle;
6456
+ const hasCompatibleAttrs = validateAttrs(vnode, elm, renderer, shouldValidateAttr);
6457
+ const hasCompatibleClass = shouldValidateAttr('class')
6458
+ ? validateClassAttr(vnode, elm, renderer)
6459
+ : true;
6460
+ const hasCompatibleStyle = shouldValidateAttr('style')
6461
+ ? validateStyleAttr(vnode, elm, renderer)
6462
+ : true;
6463
+ return hasCompatibleAttrs && hasCompatibleClass && hasCompatibleStyle;
6428
6464
  }
6429
6465
  function attributeValuesAreEqual(vnodeValue, value) {
6430
6466
  const vnodeValueAsString = String(vnodeValue);
@@ -6439,12 +6475,15 @@ function attributeValuesAreEqual(vnodeValue, value) {
6439
6475
  // In all other cases, the two values are not considered equal
6440
6476
  return false;
6441
6477
  }
6442
- function validateAttrs(vnode, elm, renderer) {
6478
+ function validateAttrs(vnode, elm, renderer, shouldValidateAttr) {
6443
6479
  const { data: { attrs = {} }, } = vnode;
6444
6480
  let nodesAreCompatible = true;
6445
6481
  // Validate attributes, though we could always recovery from those by running the update mods.
6446
6482
  // Note: intentionally ONLY matching vnodes.attrs to elm.attrs, in case SSR is adding extra attributes.
6447
6483
  for (const [attrName, attrValue] of Object.entries(attrs)) {
6484
+ if (!shouldValidateAttr(attrName)) {
6485
+ continue;
6486
+ }
6448
6487
  const { owner } = vnode;
6449
6488
  const { getAttribute } = renderer;
6450
6489
  const elmAttrValue = getAttribute(elm, attrName);
@@ -6907,5 +6946,5 @@ exports.swapTemplate = swapTemplate;
6907
6946
  exports.track = track;
6908
6947
  exports.unwrap = unwrap;
6909
6948
  exports.wire = wire;
6910
- /* version: 2.45.1 */
6949
+ /* version: 2.45.2 */
6911
6950
  //# sourceMappingURL=engine-core.cjs.js.map