@lwc/engine-core 8.1.0 → 8.1.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
@@ -3933,6 +3933,65 @@ function isVStaticPartText(vnode) {
3933
3933
  return vnode.type === 0 /* VStaticPartType.Text */;
3934
3934
  }
3935
3935
 
3936
+ const sanitizedHtmlContentSymbol = Symbol('lwc-get-sanitized-html-content');
3937
+ function isSanitizedHtmlContent(object) {
3938
+ return isObject(object) && !isNull(object) && sanitizedHtmlContentSymbol in object;
3939
+ }
3940
+ function unwrapIfNecessary(object) {
3941
+ return isSanitizedHtmlContent(object) ? object[sanitizedHtmlContentSymbol] : object;
3942
+ }
3943
+ /**
3944
+ * Wrap a pre-sanitized string designated for `.innerHTML` via `lwc:inner-html`
3945
+ * as an object with a Symbol that only we have access to.
3946
+ * @param sanitizedString
3947
+ * @returns SanitizedHtmlContent
3948
+ */
3949
+ function createSanitizedHtmlContent(sanitizedString) {
3950
+ return create(null, {
3951
+ [sanitizedHtmlContentSymbol]: {
3952
+ value: sanitizedString,
3953
+ configurable: false,
3954
+ writable: false,
3955
+ },
3956
+ });
3957
+ }
3958
+ /**
3959
+ * Safely call setProperty on an Element while handling any SanitizedHtmlContent objects correctly
3960
+ *
3961
+ * @param setProperty - renderer.setProperty
3962
+ * @param elm - Element
3963
+ * @param key - key to set
3964
+ * @param value - value to set
3965
+ */
3966
+ function safelySetProperty(setProperty, elm, key, value) {
3967
+ // See W-16614337
3968
+ // we support setting innerHTML to `undefined` because it's inherently safe
3969
+ if ((key === 'innerHTML' || key === 'outerHTML') && !isUndefined$1(value)) {
3970
+ if (isSanitizedHtmlContent(value)) {
3971
+ // it's a SanitizedHtmlContent object
3972
+ setProperty(elm, key, value[sanitizedHtmlContentSymbol]);
3973
+ }
3974
+ else {
3975
+ // not a SanitizedHtmlContent object
3976
+ if (process.env.NODE_ENV !== 'production') {
3977
+ logWarn(`Cannot set property "${key}". Instead, use lwc:inner-html or lwc:dom-manual.`);
3978
+ }
3979
+ }
3980
+ }
3981
+ else {
3982
+ setProperty(elm, key, value);
3983
+ }
3984
+ }
3985
+ /**
3986
+ * Given two objects (likely either a string or a SanitizedHtmlContent object), return true if their
3987
+ * string values are equivalent.
3988
+ * @param first
3989
+ * @param second
3990
+ */
3991
+ function isSanitizedHtmlContentEqual(first, second) {
3992
+ return unwrapIfNecessary(first) === unwrapIfNecessary(second);
3993
+ }
3994
+
3936
3995
  /*
3937
3996
  * Copyright (c) 2018, salesforce.com, inc.
3938
3997
  * All rights reserved.
@@ -3963,7 +4022,7 @@ function patchAttributes(oldVnode, vnode, renderer) {
3963
4022
  // Use kebabCaseToCamelCase directly because we don't want to set props like `ariaLabel` or `tabIndex`
3964
4023
  // on a custom element versus just using the more reliable attribute format.
3965
4024
  if (external && (propName = kebabCaseToCamelCase(key)) in elm) {
3966
- setProperty(elm, propName, cur);
4025
+ safelySetProperty(setProperty, elm, propName, cur);
3967
4026
  }
3968
4027
  else if (StringCharCodeAt.call(key, 3) === ColonCharCode) {
3969
4028
  // Assume xml namespace
@@ -4043,7 +4102,7 @@ function patchProps(oldVnode, vnode, renderer) {
4043
4102
  logWarn(`Unknown public property "${key}" of element <${elm.tagName.toLowerCase()}>. This is either a typo on the corresponding attribute "${htmlPropertyToAttribute(key)}", or the attribute does not exist in this browser or DOM implementation.`);
4044
4103
  }
4045
4104
  }
4046
- setProperty(elm, key, cur);
4105
+ safelySetProperty(setProperty, elm, key, cur);
4047
4106
  }
4048
4107
  }
4049
4108
  }
@@ -5751,7 +5810,8 @@ function setSanitizeHtmlContentHook(newHookImpl) {
5751
5810
  }
5752
5811
  // [s]anitize [h]tml [c]ontent
5753
5812
  function shc(content) {
5754
- return sanitizeHtmlContentHook(content);
5813
+ const sanitizedString = sanitizeHtmlContentHook(content);
5814
+ return createSanitizedHtmlContent(sanitizedString);
5755
5815
  }
5756
5816
  /**
5757
5817
  * [ncls] - Normalize class name attribute.
@@ -7649,6 +7709,8 @@ function hydrateComment(node, vnode, renderer) {
7649
7709
  }
7650
7710
  }
7651
7711
  const { setProperty } = renderer;
7712
+ // We only set the `nodeValue` property here (on a comment), so we don't need
7713
+ // to sanitize the content as HTML using `safelySetProperty`
7652
7714
  setProperty(node, NODE_VALUE_PROP, vnode.text ?? null);
7653
7715
  vnode.elm = node;
7654
7716
  return node;
@@ -7695,7 +7757,7 @@ function hydrateElement(elm, vnode, renderer) {
7695
7757
  const { data: { props }, } = vnode;
7696
7758
  const { getProperty } = renderer;
7697
7759
  if (!isUndefined$1(props) && !isUndefined$1(props.innerHTML)) {
7698
- if (getProperty(elm, 'innerHTML') === props.innerHTML) {
7760
+ if (isSanitizedHtmlContentEqual(getProperty(elm, 'innerHTML'), props.innerHTML)) {
7699
7761
  // Do a shallow clone since VNodeData may be shared across VNodes due to hoist optimization
7700
7762
  vnode.data = {
7701
7763
  ...vnode.data,
@@ -8369,5 +8431,5 @@ function readonly(obj) {
8369
8431
  }
8370
8432
 
8371
8433
  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 };
8372
- /** version: 8.1.0 */
8434
+ /** version: 8.1.2 */
8373
8435
  //# sourceMappingURL=index.js.map