@lwc/engine-core 2.11.1 → 2.11.3

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.
@@ -4802,236 +4802,6 @@ function invokeServiceHook(vm, cbs) {
4802
4802
  }
4803
4803
  }
4804
4804
 
4805
- /*
4806
- * Copyright (c) 2022, salesforce.com, inc.
4807
- * All rights reserved.
4808
- * SPDX-License-Identifier: MIT
4809
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4810
- */
4811
- function hydrate(vnode, node) {
4812
- switch (vnode.type) {
4813
- case 0 /* Text */:
4814
- hydrateText(vnode, node);
4815
- break;
4816
- case 1 /* Comment */:
4817
- hydrateComment(vnode, node);
4818
- break;
4819
- case 2 /* Element */:
4820
- hydrateElement(vnode, node);
4821
- break;
4822
- case 3 /* CustomElement */:
4823
- hydrateCustomElement(vnode, node);
4824
- break;
4825
- }
4826
- }
4827
- function hydrateText(vnode, node) {
4828
- var _a;
4829
- if (process.env.NODE_ENV !== 'production') {
4830
- validateNodeType(vnode, node, 3 /* TEXT */);
4831
- const nodeValue = getProperty(node, 'nodeValue');
4832
- if (nodeValue !== vnode.text && !(nodeValue === '\u200D' && vnode.text === '')) {
4833
- logWarn('Hydration mismatch: text values do not match, will recover from the difference', vnode.owner);
4834
- }
4835
- }
4836
- // always set the text value to the one from the vnode.
4837
- setText(node, (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
4838
- vnode.elm = node;
4839
- }
4840
- function hydrateComment(vnode, node) {
4841
- var _a;
4842
- if (process.env.NODE_ENV !== 'production') {
4843
- validateNodeType(vnode, node, 8 /* COMMENT */);
4844
- if (getProperty(node, 'nodeValue') !== vnode.text) {
4845
- logWarn('Hydration mismatch: comment values do not match, will recover from the difference', vnode.owner);
4846
- }
4847
- }
4848
- // always set the text value to the one from the vnode.
4849
- setProperty(node, 'nodeValue', (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
4850
- vnode.elm = node;
4851
- }
4852
- function hydrateElement(vnode, node) {
4853
- if (process.env.NODE_ENV !== 'production') {
4854
- validateNodeType(vnode, node, 1 /* ELEMENT */);
4855
- validateElement(vnode, node);
4856
- }
4857
- const elm = node;
4858
- vnode.elm = elm;
4859
- const { context } = vnode.data;
4860
- const isDomManual = Boolean(!shared.isUndefined(context) && !shared.isUndefined(context.lwc) && context.lwc.dom === "manual" /* Manual */);
4861
- if (isDomManual) {
4862
- // it may be that this element has lwc:inner-html, we need to diff and in case are the same,
4863
- // remove the innerHTML from props so it reuses the existing dom elements.
4864
- const { props } = vnode.data;
4865
- if (!shared.isUndefined(props) && !shared.isUndefined(props.innerHTML)) {
4866
- if (getProperty(elm, 'innerHTML') === props.innerHTML) {
4867
- // Do a shallow clone since VNodeData may be shared across VNodes due to hoist optimization
4868
- vnode.data = Object.assign(Object.assign({}, vnode.data), { props: cloneAndOmitKey(props, 'innerHTML') });
4869
- }
4870
- else {
4871
- logWarn(`Mismatch hydrating element <${getProperty(elm, 'tagName').toLowerCase()}>: innerHTML values do not match for element, will recover from the difference`, vnode.owner);
4872
- }
4873
- }
4874
- }
4875
- patchElementPropsAndAttrs(vnode);
4876
- if (!isDomManual) {
4877
- hydrateChildren(getChildNodes(vnode.elm), vnode.children, vnode.owner);
4878
- }
4879
- }
4880
- function hydrateCustomElement(vnode, node) {
4881
- if (process.env.NODE_ENV !== 'production') {
4882
- validateNodeType(vnode, node, 1 /* ELEMENT */);
4883
- validateElement(vnode, node);
4884
- }
4885
- const elm = node;
4886
- const { sel, mode, ctor, owner } = vnode;
4887
- const vm = createVM(elm, ctor, {
4888
- mode,
4889
- owner,
4890
- tagName: sel,
4891
- });
4892
- vnode.elm = elm;
4893
- vnode.vm = vm;
4894
- allocateChildren(vnode, vm);
4895
- patchElementPropsAndAttrs(vnode);
4896
- // Insert hook section:
4897
- if (process.env.NODE_ENV !== 'production') {
4898
- shared.assert.isTrue(vm.state === 0 /* created */, `${vm} cannot be recycled.`);
4899
- }
4900
- runConnectedCallback(vm);
4901
- if (vm.renderMode !== 0 /* Light */) {
4902
- // VM is not rendering in Light DOM, we can proceed and hydrate the slotted content.
4903
- // Note: for Light DOM, this is handled while hydrating the VM
4904
- hydrateChildren(getChildNodes(vnode.elm), vnode.children, vm);
4905
- }
4906
- hydrateVM(vm);
4907
- }
4908
- function hydrateChildren(elmChildren, children, vm) {
4909
- if (process.env.NODE_ENV !== 'production') {
4910
- const filteredVNodes = shared.ArrayFilter.call(children, (vnode) => !!vnode);
4911
- if (elmChildren.length !== filteredVNodes.length) {
4912
- logError(`Hydration mismatch: incorrect number of rendered nodes, expected ${filteredVNodes.length} but found ${elmChildren.length}.`, vm);
4913
- throwHydrationError();
4914
- }
4915
- }
4916
- let childNodeIndex = 0;
4917
- for (let i = 0; i < children.length; i++) {
4918
- const childVnode = children[i];
4919
- if (!shared.isNull(childVnode)) {
4920
- const childNode = elmChildren[childNodeIndex];
4921
- hydrate(childVnode, childNode);
4922
- childNodeIndex++;
4923
- }
4924
- }
4925
- }
4926
- function patchElementPropsAndAttrs(vnode) {
4927
- applyEventListeners(vnode);
4928
- patchProps(null, vnode);
4929
- }
4930
- function throwHydrationError() {
4931
- shared.assert.fail('Server rendered elements do not match client side generated elements');
4932
- }
4933
- function validateNodeType(vnode, node, nodeType) {
4934
- if (getProperty(node, 'nodeType') !== nodeType) {
4935
- logError('Hydration mismatch: incorrect node type received', vnode.owner);
4936
- shared.assert.fail('Hydration mismatch: incorrect node type received.');
4937
- }
4938
- }
4939
- function validateElement(vnode, elm) {
4940
- if (vnode.sel.toLowerCase() !== getProperty(elm, 'tagName').toLowerCase()) {
4941
- logError(`Hydration mismatch: expecting element with tag "${vnode.sel.toLowerCase()}" but found "${getProperty(elm, 'tagName').toLowerCase()}".`, vnode.owner);
4942
- throwHydrationError();
4943
- }
4944
- const hasIncompatibleAttrs = validateAttrs(vnode, elm);
4945
- const hasIncompatibleClass = validateClassAttr(vnode, elm);
4946
- const hasIncompatibleStyle = validateStyleAttr(vnode, elm);
4947
- const isVNodeAndElementCompatible = hasIncompatibleAttrs && hasIncompatibleClass && hasIncompatibleStyle;
4948
- if (!isVNodeAndElementCompatible) {
4949
- throwHydrationError();
4950
- }
4951
- }
4952
- function validateAttrs(vnode, elm) {
4953
- const { data: { attrs = {} }, } = vnode;
4954
- let nodesAreCompatible = true;
4955
- // Validate attributes, though we could always recovery from those by running the update mods.
4956
- // Note: intentionally ONLY matching vnodes.attrs to elm.attrs, in case SSR is adding extra attributes.
4957
- for (const [attrName, attrValue] of Object.entries(attrs)) {
4958
- const elmAttrValue = getAttribute(elm, attrName);
4959
- if (String(attrValue) !== elmAttrValue) {
4960
- logError(`Mismatch hydrating element <${getProperty(elm, 'tagName').toLowerCase()}>: attribute "${attrName}" has different values, expected "${attrValue}" but found "${elmAttrValue}"`, vnode.owner);
4961
- nodesAreCompatible = false;
4962
- }
4963
- }
4964
- return nodesAreCompatible;
4965
- }
4966
- function validateClassAttr(vnode, elm) {
4967
- const { data: { className, classMap }, } = vnode;
4968
- let nodesAreCompatible = true;
4969
- let vnodeClassName;
4970
- if (!shared.isUndefined(className) && String(className) !== getProperty(elm, 'className')) {
4971
- // className is used when class is bound to an expr.
4972
- nodesAreCompatible = false;
4973
- vnodeClassName = className;
4974
- }
4975
- else if (!shared.isUndefined(classMap)) {
4976
- // classMap is used when class is set to static value.
4977
- const classList = getClassList(elm);
4978
- let computedClassName = '';
4979
- // all classes from the vnode should be in the element.classList
4980
- for (const name in classMap) {
4981
- computedClassName += ' ' + name;
4982
- if (!classList.contains(name)) {
4983
- nodesAreCompatible = false;
4984
- }
4985
- }
4986
- vnodeClassName = computedClassName.trim();
4987
- if (classList.length > shared.keys(classMap).length) {
4988
- nodesAreCompatible = false;
4989
- }
4990
- }
4991
- if (!nodesAreCompatible) {
4992
- logError(`Mismatch hydrating element <${getProperty(elm, 'tagName').toLowerCase()}>: attribute "class" has different values, expected "${vnodeClassName}" but found "${getProperty(elm, 'className')}"`, vnode.owner);
4993
- }
4994
- return nodesAreCompatible;
4995
- }
4996
- function validateStyleAttr(vnode, elm) {
4997
- const { data: { style, styleDecls }, } = vnode;
4998
- const elmStyle = getAttribute(elm, 'style') || '';
4999
- let vnodeStyle;
5000
- let nodesAreCompatible = true;
5001
- if (!shared.isUndefined(style) && style !== elmStyle) {
5002
- nodesAreCompatible = false;
5003
- vnodeStyle = style;
5004
- }
5005
- else if (!shared.isUndefined(styleDecls)) {
5006
- const parsedVnodeStyle = parseStyleText(elmStyle);
5007
- const expectedStyle = [];
5008
- // styleMap is used when style is set to static value.
5009
- for (let i = 0, n = styleDecls.length; i < n; i++) {
5010
- const [prop, value, important] = styleDecls[i];
5011
- expectedStyle.push(`${prop}: ${value + (important ? ' important!' : '')}`);
5012
- const parsedPropValue = parsedVnodeStyle[prop];
5013
- if (shared.isUndefined(parsedPropValue)) {
5014
- nodesAreCompatible = false;
5015
- }
5016
- else if (!parsedPropValue.startsWith(value)) {
5017
- nodesAreCompatible = false;
5018
- }
5019
- else if (important && !parsedPropValue.endsWith('!important')) {
5020
- nodesAreCompatible = false;
5021
- }
5022
- }
5023
- if (shared.keys(parsedVnodeStyle).length > styleDecls.length) {
5024
- nodesAreCompatible = false;
5025
- }
5026
- vnodeStyle = shared.ArrayJoin.call(expectedStyle, ';');
5027
- }
5028
- if (!nodesAreCompatible) {
5029
- // style is used when class is bound to an expr.
5030
- logError(`Mismatch hydrating element <${getProperty(elm, 'tagName').toLowerCase()}>: attribute "style" has different values, expected "${vnodeStyle}" but found "${elmStyle}".`, vnode.owner);
5031
- }
5032
- return nodesAreCompatible;
5033
- }
5034
-
5035
4805
  /*
5036
4806
  * Copyright (c) 2018, salesforce.com, inc.
5037
4807
  * All rights reserved.
@@ -5077,32 +4847,12 @@ function connectRootElement(elm) {
5077
4847
  /* GlobalHydrate */
5078
4848
  , vm);
5079
4849
  }
5080
- function hydrateRootElement(elm) {
5081
- const vm = getAssociatedVM(elm);
5082
- runConnectedCallback(vm);
5083
- hydrateVM(vm);
5084
- }
5085
4850
  function disconnectRootElement(elm) {
5086
4851
  const vm = getAssociatedVM(elm);
5087
4852
  resetComponentStateWhenRemoved(vm);
5088
4853
  }
5089
4854
  function appendVM(vm) {
5090
4855
  rehydrate(vm);
5091
- }
5092
- function hydrateVM(vm) {
5093
- if (shared.isTrue(vm.isDirty)) {
5094
- // manually diffing/patching here.
5095
- // This routine is:
5096
- // patchShadowRoot(vm, children);
5097
- // -> addVnodes.
5098
- const children = renderComponent(vm);
5099
- vm.children = children;
5100
- const vmChildren = vm.renderMode === 0
5101
- /* Light */
5102
- ? getChildNodes(vm.elm) : getChildNodes(vm.elm.shadowRoot);
5103
- hydrateChildren(vmChildren, children, vm);
5104
- runRenderedCallback(vm);
5105
- }
5106
4856
  } // just in case the component comes back, with this we guarantee re-rendering it
5107
4857
  // while preventing any attempt to rehydration until after reinsertion.
5108
4858
 
@@ -5407,7 +5157,6 @@ function runRenderedCallback(vm) {
5407
5157
  , vm);
5408
5158
  }
5409
5159
  }
5410
-
5411
5160
  let rehydrateQueue = [];
5412
5161
 
5413
5162
  function flushRehydrationQueue() {
@@ -6064,6 +5813,298 @@ function readonly(obj) {
6064
5813
  return reactiveMembrane.getReadOnlyProxy(obj);
6065
5814
  }
6066
5815
 
5816
+ /*
5817
+ * Copyright (c) 2022, salesforce.com, inc.
5818
+ * All rights reserved.
5819
+ * SPDX-License-Identifier: MIT
5820
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5821
+ */
5822
+ // flag indicating if the hydration recovered from the DOM mismatch
5823
+ let hasMismatch = false;
5824
+ function hydrateRoot(vm) {
5825
+ hasMismatch = false;
5826
+ runConnectedCallback(vm);
5827
+ hydrateVM(vm);
5828
+ if (hasMismatch) {
5829
+ logError('Hydration completed with errors.', vm);
5830
+ }
5831
+ }
5832
+ function hydrateVM(vm) {
5833
+ const children = renderComponent(vm);
5834
+ vm.children = children;
5835
+ const parentNode = vm.renderRoot;
5836
+ hydrateChildren(getFirstChild(parentNode), children, parentNode, vm);
5837
+ runRenderedCallback(vm);
5838
+ }
5839
+ function hydrateNode(node, vnode) {
5840
+ let hydratedNode;
5841
+ switch (vnode.type) {
5842
+ case 0 /* Text */:
5843
+ hydratedNode = hydrateText(node, vnode);
5844
+ break;
5845
+ case 1 /* Comment */:
5846
+ hydratedNode = hydrateComment(node, vnode);
5847
+ break;
5848
+ case 2 /* Element */:
5849
+ hydratedNode = hydrateElement(node, vnode);
5850
+ break;
5851
+ case 3 /* CustomElement */:
5852
+ hydratedNode = hydrateCustomElement(node, vnode);
5853
+ break;
5854
+ }
5855
+ return nextSibling(hydratedNode);
5856
+ }
5857
+ function hydrateText(node, vnode) {
5858
+ var _a;
5859
+ if (!hasCorrectNodeType(vnode, node, 3 /* TEXT */)) {
5860
+ return handleMismatch(node, vnode);
5861
+ }
5862
+ if (process.env.NODE_ENV !== 'production') {
5863
+ const nodeValue = getProperty(node, 'nodeValue');
5864
+ if (nodeValue !== vnode.text && !(nodeValue === '\u200D' && vnode.text === '')) {
5865
+ logWarn('Hydration mismatch: text values do not match, will recover from the difference', vnode.owner);
5866
+ }
5867
+ }
5868
+ setText(node, (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
5869
+ vnode.elm = node;
5870
+ return node;
5871
+ }
5872
+ function hydrateComment(node, vnode) {
5873
+ var _a;
5874
+ if (!hasCorrectNodeType(vnode, node, 8 /* COMMENT */)) {
5875
+ return handleMismatch(node, vnode);
5876
+ }
5877
+ if (process.env.NODE_ENV !== 'production') {
5878
+ const nodeValue = getProperty(node, 'nodeValue');
5879
+ if (nodeValue !== vnode.text) {
5880
+ logWarn('Hydration mismatch: comment values do not match, will recover from the difference', vnode.owner);
5881
+ }
5882
+ }
5883
+ setProperty(node, 'nodeValue', (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
5884
+ vnode.elm = node;
5885
+ return node;
5886
+ }
5887
+ function hydrateElement(elm, vnode) {
5888
+ if (!hasCorrectNodeType(vnode, elm, 1 /* ELEMENT */) ||
5889
+ !isMatchingElement(vnode, elm)) {
5890
+ return handleMismatch(elm, vnode);
5891
+ }
5892
+ vnode.elm = elm;
5893
+ const { context } = vnode.data;
5894
+ const isDomManual = Boolean(!shared.isUndefined(context) && !shared.isUndefined(context.lwc) && context.lwc.dom === "manual" /* Manual */);
5895
+ if (isDomManual) {
5896
+ // it may be that this element has lwc:inner-html, we need to diff and in case are the same,
5897
+ // remove the innerHTML from props so it reuses the existing dom elements.
5898
+ const { props } = vnode.data;
5899
+ if (!shared.isUndefined(props) && !shared.isUndefined(props.innerHTML)) {
5900
+ if (getProperty(elm, 'innerHTML') === props.innerHTML) {
5901
+ // Do a shallow clone since VNodeData may be shared across VNodes due to hoist optimization
5902
+ vnode.data = Object.assign(Object.assign({}, vnode.data), { props: cloneAndOmitKey(props, 'innerHTML') });
5903
+ }
5904
+ else {
5905
+ if (process.env.NODE_ENV !== 'production') {
5906
+ logWarn(`Mismatch hydrating element <${getProperty(elm, 'tagName').toLowerCase()}>: innerHTML values do not match for element, will recover from the difference`, vnode.owner);
5907
+ }
5908
+ }
5909
+ }
5910
+ }
5911
+ patchElementPropsAndAttrs(vnode);
5912
+ if (!isDomManual) {
5913
+ hydrateChildren(getFirstChild(elm), vnode.children, elm, vnode.owner);
5914
+ }
5915
+ return elm;
5916
+ }
5917
+ function hydrateCustomElement(elm, vnode) {
5918
+ if (!hasCorrectNodeType(vnode, elm, 1 /* ELEMENT */) ||
5919
+ !isMatchingElement(vnode, elm)) {
5920
+ return handleMismatch(elm, vnode);
5921
+ }
5922
+ const { sel, mode, ctor, owner } = vnode;
5923
+ const vm = createVM(elm, ctor, {
5924
+ mode,
5925
+ owner,
5926
+ tagName: sel,
5927
+ });
5928
+ vnode.elm = elm;
5929
+ vnode.vm = vm;
5930
+ allocateChildren(vnode, vm);
5931
+ patchElementPropsAndAttrs(vnode);
5932
+ // Insert hook section:
5933
+ if (process.env.NODE_ENV !== 'production') {
5934
+ shared.assert.isTrue(vm.state === 0 /* created */, `${vm} cannot be recycled.`);
5935
+ }
5936
+ runConnectedCallback(vm);
5937
+ if (vm.renderMode !== 0 /* Light */) {
5938
+ // VM is not rendering in Light DOM, we can proceed and hydrate the slotted content.
5939
+ // Note: for Light DOM, this is handled while hydrating the VM
5940
+ hydrateChildren(getFirstChild(elm), vnode.children, elm, vm);
5941
+ }
5942
+ hydrateVM(vm);
5943
+ return elm;
5944
+ }
5945
+ function hydrateChildren(node, children, parentNode, owner) {
5946
+ let hasWarned = false;
5947
+ let nextNode = node;
5948
+ let anchor = null;
5949
+ for (let i = 0; i < children.length; i++) {
5950
+ const childVnode = children[i];
5951
+ if (!shared.isNull(childVnode)) {
5952
+ if (nextNode) {
5953
+ nextNode = hydrateNode(nextNode, childVnode);
5954
+ anchor = childVnode.elm;
5955
+ }
5956
+ else {
5957
+ hasMismatch = true;
5958
+ if (process.env.NODE_ENV !== 'production') {
5959
+ if (!hasWarned) {
5960
+ hasWarned = true;
5961
+ logError(`Hydration mismatch: incorrect number of rendered nodes. Client produced more nodes than the server.`, owner);
5962
+ }
5963
+ }
5964
+ mount(childVnode, parentNode, anchor);
5965
+ anchor = childVnode.elm;
5966
+ }
5967
+ }
5968
+ }
5969
+ if (nextNode) {
5970
+ hasMismatch = true;
5971
+ if (process.env.NODE_ENV !== 'production') {
5972
+ if (!hasWarned) {
5973
+ logError(`Hydration mismatch: incorrect number of rendered nodes. Server rendered more nodes than the client.`, owner);
5974
+ }
5975
+ }
5976
+ do {
5977
+ const current = nextNode;
5978
+ nextNode = nextSibling(nextNode);
5979
+ removeNode(current, parentNode);
5980
+ } while (nextNode);
5981
+ }
5982
+ }
5983
+ function handleMismatch(node, vnode, msg) {
5984
+ hasMismatch = true;
5985
+ if (!shared.isUndefined(msg)) {
5986
+ if (process.env.NODE_ENV !== 'production') {
5987
+ logError(msg, vnode.owner);
5988
+ }
5989
+ }
5990
+ const parentNode = getProperty(node, 'parentNode');
5991
+ mount(vnode, parentNode, node);
5992
+ removeNode(node, parentNode);
5993
+ return vnode.elm;
5994
+ }
5995
+ function patchElementPropsAndAttrs(vnode) {
5996
+ applyEventListeners(vnode);
5997
+ patchProps(null, vnode);
5998
+ }
5999
+ function hasCorrectNodeType(vnode, node, nodeType) {
6000
+ if (getProperty(node, 'nodeType') !== nodeType) {
6001
+ if (process.env.NODE_ENV !== 'production') {
6002
+ logError('Hydration mismatch: incorrect node type received', vnode.owner);
6003
+ }
6004
+ return false;
6005
+ }
6006
+ return true;
6007
+ }
6008
+ function isMatchingElement(vnode, elm) {
6009
+ if (vnode.sel.toLowerCase() !== getProperty(elm, 'tagName').toLowerCase()) {
6010
+ if (process.env.NODE_ENV !== 'production') {
6011
+ logError(`Hydration mismatch: expecting element with tag "${vnode.sel.toLowerCase()}" but found "${getProperty(elm, 'tagName').toLowerCase()}".`, vnode.owner);
6012
+ }
6013
+ return false;
6014
+ }
6015
+ const hasIncompatibleAttrs = validateAttrs(vnode, elm);
6016
+ const hasIncompatibleClass = validateClassAttr(vnode, elm);
6017
+ const hasIncompatibleStyle = validateStyleAttr(vnode, elm);
6018
+ return hasIncompatibleAttrs && hasIncompatibleClass && hasIncompatibleStyle;
6019
+ }
6020
+ function validateAttrs(vnode, elm) {
6021
+ const { data: { attrs = {} }, } = vnode;
6022
+ let nodesAreCompatible = true;
6023
+ // Validate attributes, though we could always recovery from those by running the update mods.
6024
+ // Note: intentionally ONLY matching vnodes.attrs to elm.attrs, in case SSR is adding extra attributes.
6025
+ for (const [attrName, attrValue] of Object.entries(attrs)) {
6026
+ const elmAttrValue = getAttribute(elm, attrName);
6027
+ if (String(attrValue) !== elmAttrValue) {
6028
+ if (process.env.NODE_ENV !== 'production') {
6029
+ logError(`Mismatch hydrating element <${getProperty(elm, 'tagName').toLowerCase()}>: attribute "${attrName}" has different values, expected "${attrValue}" but found "${elmAttrValue}"`, vnode.owner);
6030
+ }
6031
+ nodesAreCompatible = false;
6032
+ }
6033
+ }
6034
+ return nodesAreCompatible;
6035
+ }
6036
+ function validateClassAttr(vnode, elm) {
6037
+ const { data: { className, classMap }, } = vnode;
6038
+ let nodesAreCompatible = true;
6039
+ let vnodeClassName;
6040
+ if (!shared.isUndefined(className) && String(className) !== getProperty(elm, 'className')) {
6041
+ // className is used when class is bound to an expr.
6042
+ nodesAreCompatible = false;
6043
+ vnodeClassName = className;
6044
+ }
6045
+ else if (!shared.isUndefined(classMap)) {
6046
+ // classMap is used when class is set to static value.
6047
+ const classList = getClassList(elm);
6048
+ let computedClassName = '';
6049
+ // all classes from the vnode should be in the element.classList
6050
+ for (const name in classMap) {
6051
+ computedClassName += ' ' + name;
6052
+ if (!classList.contains(name)) {
6053
+ nodesAreCompatible = false;
6054
+ }
6055
+ }
6056
+ vnodeClassName = computedClassName.trim();
6057
+ if (classList.length > shared.keys(classMap).length) {
6058
+ nodesAreCompatible = false;
6059
+ }
6060
+ }
6061
+ if (!nodesAreCompatible) {
6062
+ if (process.env.NODE_ENV !== 'production') {
6063
+ logError(`Mismatch hydrating element <${getProperty(elm, 'tagName').toLowerCase()}>: attribute "class" has different values, expected "${vnodeClassName}" but found "${getProperty(elm, 'className')}"`, vnode.owner);
6064
+ }
6065
+ }
6066
+ return nodesAreCompatible;
6067
+ }
6068
+ function validateStyleAttr(vnode, elm) {
6069
+ const { data: { style, styleDecls }, } = vnode;
6070
+ const elmStyle = getAttribute(elm, 'style') || '';
6071
+ let vnodeStyle;
6072
+ let nodesAreCompatible = true;
6073
+ if (!shared.isUndefined(style) && style !== elmStyle) {
6074
+ nodesAreCompatible = false;
6075
+ vnodeStyle = style;
6076
+ }
6077
+ else if (!shared.isUndefined(styleDecls)) {
6078
+ const parsedVnodeStyle = parseStyleText(elmStyle);
6079
+ const expectedStyle = [];
6080
+ // styleMap is used when style is set to static value.
6081
+ for (let i = 0, n = styleDecls.length; i < n; i++) {
6082
+ const [prop, value, important] = styleDecls[i];
6083
+ expectedStyle.push(`${prop}: ${value + (important ? ' important!' : '')}`);
6084
+ const parsedPropValue = parsedVnodeStyle[prop];
6085
+ if (shared.isUndefined(parsedPropValue)) {
6086
+ nodesAreCompatible = false;
6087
+ }
6088
+ else if (!parsedPropValue.startsWith(value)) {
6089
+ nodesAreCompatible = false;
6090
+ }
6091
+ else if (important && !parsedPropValue.endsWith('!important')) {
6092
+ nodesAreCompatible = false;
6093
+ }
6094
+ }
6095
+ if (shared.keys(parsedVnodeStyle).length > styleDecls.length) {
6096
+ nodesAreCompatible = false;
6097
+ }
6098
+ vnodeStyle = shared.ArrayJoin.call(expectedStyle, ';');
6099
+ }
6100
+ if (!nodesAreCompatible) {
6101
+ if (process.env.NODE_ENV !== 'production') {
6102
+ logError(`Mismatch hydrating element <${getProperty(elm, 'tagName').toLowerCase()}>: attribute "style" has different values, expected "${vnodeStyle}" but found "${elmStyle}".`, vnode.owner);
6103
+ }
6104
+ }
6105
+ return nodesAreCompatible;
6106
+ }
6107
+
6067
6108
  /*
6068
6109
  * Copyright (c) 2018, salesforce.com, inc.
6069
6110
  * All rights reserved.
@@ -6096,7 +6137,7 @@ exports.getAssociatedVMIfPresent = getAssociatedVMIfPresent;
6096
6137
  exports.getComponentDef = getComponentDef;
6097
6138
  exports.getComponentHtmlPrototype = getComponentHtmlPrototype;
6098
6139
  exports.getUpgradableConstructor = getUpgradableConstructor;
6099
- exports.hydrateRootElement = hydrateRootElement;
6140
+ exports.hydrateRoot = hydrateRoot;
6100
6141
  exports.isComponentConstructor = isComponentConstructor;
6101
6142
  exports.readonly = readonly;
6102
6143
  exports.register = register;
@@ -6151,4 +6192,4 @@ exports.swapTemplate = swapTemplate;
6151
6192
  exports.track = track;
6152
6193
  exports.unwrap = unwrap;
6153
6194
  exports.wire = wire;
6154
- /* version: 2.11.1 */
6195
+ /* version: 2.11.3 */
@@ -1,5 +1,5 @@
1
1
  /* proxy-compat-disable */
2
- import { seal, create, isFunction as isFunction$1, ArrayPush as ArrayPush$1, isUndefined as isUndefined$1, ArrayIndexOf, ArraySplice, StringToLowerCase, ArrayJoin, isNull, isFrozen, defineProperty, assign, forEach, keys, AriaPropNameToAttrNameMap, getPropertyDescriptor, defineProperties, getOwnPropertyNames as getOwnPropertyNames$1, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, isObject, assert, KEY__SYNTHETIC_MODE, toString as toString$1, isFalse, isTrue, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, freeze, htmlPropertyToAttribute, ArraySlice, hasOwnProperty as hasOwnProperty$1, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, isString, StringSlice, SVG_NAMESPACE, KEY__SHADOW_RESOLVER, isArray as isArray$1, isNumber, StringReplace, KEY__SCOPED_CSS, noop, ArrayUnshift, ArrayFilter } from '@lwc/shared';
2
+ import { seal, create, isFunction as isFunction$1, ArrayPush as ArrayPush$1, isUndefined as isUndefined$1, ArrayIndexOf, ArraySplice, StringToLowerCase, ArrayJoin, isNull, isFrozen, defineProperty, assign, forEach, keys, AriaPropNameToAttrNameMap, getPropertyDescriptor, defineProperties, getOwnPropertyNames as getOwnPropertyNames$1, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, isObject, assert, KEY__SYNTHETIC_MODE, toString as toString$1, isFalse, isTrue, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, freeze, htmlPropertyToAttribute, ArraySlice, hasOwnProperty as hasOwnProperty$1, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, isString, StringSlice, SVG_NAMESPACE, KEY__SHADOW_RESOLVER, isArray as isArray$1, isNumber, StringReplace, KEY__SCOPED_CSS, noop, ArrayUnshift } from '@lwc/shared';
3
3
  import { runtimeFlags } from '@lwc/features';
4
4
  export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
5
5
 
@@ -4799,236 +4799,6 @@ function invokeServiceHook(vm, cbs) {
4799
4799
  }
4800
4800
  }
4801
4801
 
4802
- /*
4803
- * Copyright (c) 2022, salesforce.com, inc.
4804
- * All rights reserved.
4805
- * SPDX-License-Identifier: MIT
4806
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4807
- */
4808
- function hydrate(vnode, node) {
4809
- switch (vnode.type) {
4810
- case 0 /* Text */:
4811
- hydrateText(vnode, node);
4812
- break;
4813
- case 1 /* Comment */:
4814
- hydrateComment(vnode, node);
4815
- break;
4816
- case 2 /* Element */:
4817
- hydrateElement(vnode, node);
4818
- break;
4819
- case 3 /* CustomElement */:
4820
- hydrateCustomElement(vnode, node);
4821
- break;
4822
- }
4823
- }
4824
- function hydrateText(vnode, node) {
4825
- var _a;
4826
- if (process.env.NODE_ENV !== 'production') {
4827
- validateNodeType(vnode, node, 3 /* TEXT */);
4828
- const nodeValue = getProperty(node, 'nodeValue');
4829
- if (nodeValue !== vnode.text && !(nodeValue === '\u200D' && vnode.text === '')) {
4830
- logWarn('Hydration mismatch: text values do not match, will recover from the difference', vnode.owner);
4831
- }
4832
- }
4833
- // always set the text value to the one from the vnode.
4834
- setText(node, (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
4835
- vnode.elm = node;
4836
- }
4837
- function hydrateComment(vnode, node) {
4838
- var _a;
4839
- if (process.env.NODE_ENV !== 'production') {
4840
- validateNodeType(vnode, node, 8 /* COMMENT */);
4841
- if (getProperty(node, 'nodeValue') !== vnode.text) {
4842
- logWarn('Hydration mismatch: comment values do not match, will recover from the difference', vnode.owner);
4843
- }
4844
- }
4845
- // always set the text value to the one from the vnode.
4846
- setProperty(node, 'nodeValue', (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
4847
- vnode.elm = node;
4848
- }
4849
- function hydrateElement(vnode, node) {
4850
- if (process.env.NODE_ENV !== 'production') {
4851
- validateNodeType(vnode, node, 1 /* ELEMENT */);
4852
- validateElement(vnode, node);
4853
- }
4854
- const elm = node;
4855
- vnode.elm = elm;
4856
- const { context } = vnode.data;
4857
- const isDomManual = Boolean(!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual" /* Manual */);
4858
- if (isDomManual) {
4859
- // it may be that this element has lwc:inner-html, we need to diff and in case are the same,
4860
- // remove the innerHTML from props so it reuses the existing dom elements.
4861
- const { props } = vnode.data;
4862
- if (!isUndefined$1(props) && !isUndefined$1(props.innerHTML)) {
4863
- if (getProperty(elm, 'innerHTML') === props.innerHTML) {
4864
- // Do a shallow clone since VNodeData may be shared across VNodes due to hoist optimization
4865
- vnode.data = Object.assign(Object.assign({}, vnode.data), { props: cloneAndOmitKey(props, 'innerHTML') });
4866
- }
4867
- else {
4868
- logWarn(`Mismatch hydrating element <${getProperty(elm, 'tagName').toLowerCase()}>: innerHTML values do not match for element, will recover from the difference`, vnode.owner);
4869
- }
4870
- }
4871
- }
4872
- patchElementPropsAndAttrs(vnode);
4873
- if (!isDomManual) {
4874
- hydrateChildren(getChildNodes(vnode.elm), vnode.children, vnode.owner);
4875
- }
4876
- }
4877
- function hydrateCustomElement(vnode, node) {
4878
- if (process.env.NODE_ENV !== 'production') {
4879
- validateNodeType(vnode, node, 1 /* ELEMENT */);
4880
- validateElement(vnode, node);
4881
- }
4882
- const elm = node;
4883
- const { sel, mode, ctor, owner } = vnode;
4884
- const vm = createVM(elm, ctor, {
4885
- mode,
4886
- owner,
4887
- tagName: sel,
4888
- });
4889
- vnode.elm = elm;
4890
- vnode.vm = vm;
4891
- allocateChildren(vnode, vm);
4892
- patchElementPropsAndAttrs(vnode);
4893
- // Insert hook section:
4894
- if (process.env.NODE_ENV !== 'production') {
4895
- assert.isTrue(vm.state === 0 /* created */, `${vm} cannot be recycled.`);
4896
- }
4897
- runConnectedCallback(vm);
4898
- if (vm.renderMode !== 0 /* Light */) {
4899
- // VM is not rendering in Light DOM, we can proceed and hydrate the slotted content.
4900
- // Note: for Light DOM, this is handled while hydrating the VM
4901
- hydrateChildren(getChildNodes(vnode.elm), vnode.children, vm);
4902
- }
4903
- hydrateVM(vm);
4904
- }
4905
- function hydrateChildren(elmChildren, children, vm) {
4906
- if (process.env.NODE_ENV !== 'production') {
4907
- const filteredVNodes = ArrayFilter.call(children, (vnode) => !!vnode);
4908
- if (elmChildren.length !== filteredVNodes.length) {
4909
- logError(`Hydration mismatch: incorrect number of rendered nodes, expected ${filteredVNodes.length} but found ${elmChildren.length}.`, vm);
4910
- throwHydrationError();
4911
- }
4912
- }
4913
- let childNodeIndex = 0;
4914
- for (let i = 0; i < children.length; i++) {
4915
- const childVnode = children[i];
4916
- if (!isNull(childVnode)) {
4917
- const childNode = elmChildren[childNodeIndex];
4918
- hydrate(childVnode, childNode);
4919
- childNodeIndex++;
4920
- }
4921
- }
4922
- }
4923
- function patchElementPropsAndAttrs(vnode) {
4924
- applyEventListeners(vnode);
4925
- patchProps(null, vnode);
4926
- }
4927
- function throwHydrationError() {
4928
- assert.fail('Server rendered elements do not match client side generated elements');
4929
- }
4930
- function validateNodeType(vnode, node, nodeType) {
4931
- if (getProperty(node, 'nodeType') !== nodeType) {
4932
- logError('Hydration mismatch: incorrect node type received', vnode.owner);
4933
- assert.fail('Hydration mismatch: incorrect node type received.');
4934
- }
4935
- }
4936
- function validateElement(vnode, elm) {
4937
- if (vnode.sel.toLowerCase() !== getProperty(elm, 'tagName').toLowerCase()) {
4938
- logError(`Hydration mismatch: expecting element with tag "${vnode.sel.toLowerCase()}" but found "${getProperty(elm, 'tagName').toLowerCase()}".`, vnode.owner);
4939
- throwHydrationError();
4940
- }
4941
- const hasIncompatibleAttrs = validateAttrs(vnode, elm);
4942
- const hasIncompatibleClass = validateClassAttr(vnode, elm);
4943
- const hasIncompatibleStyle = validateStyleAttr(vnode, elm);
4944
- const isVNodeAndElementCompatible = hasIncompatibleAttrs && hasIncompatibleClass && hasIncompatibleStyle;
4945
- if (!isVNodeAndElementCompatible) {
4946
- throwHydrationError();
4947
- }
4948
- }
4949
- function validateAttrs(vnode, elm) {
4950
- const { data: { attrs = {} }, } = vnode;
4951
- let nodesAreCompatible = true;
4952
- // Validate attributes, though we could always recovery from those by running the update mods.
4953
- // Note: intentionally ONLY matching vnodes.attrs to elm.attrs, in case SSR is adding extra attributes.
4954
- for (const [attrName, attrValue] of Object.entries(attrs)) {
4955
- const elmAttrValue = getAttribute(elm, attrName);
4956
- if (String(attrValue) !== elmAttrValue) {
4957
- logError(`Mismatch hydrating element <${getProperty(elm, 'tagName').toLowerCase()}>: attribute "${attrName}" has different values, expected "${attrValue}" but found "${elmAttrValue}"`, vnode.owner);
4958
- nodesAreCompatible = false;
4959
- }
4960
- }
4961
- return nodesAreCompatible;
4962
- }
4963
- function validateClassAttr(vnode, elm) {
4964
- const { data: { className, classMap }, } = vnode;
4965
- let nodesAreCompatible = true;
4966
- let vnodeClassName;
4967
- if (!isUndefined$1(className) && String(className) !== getProperty(elm, 'className')) {
4968
- // className is used when class is bound to an expr.
4969
- nodesAreCompatible = false;
4970
- vnodeClassName = className;
4971
- }
4972
- else if (!isUndefined$1(classMap)) {
4973
- // classMap is used when class is set to static value.
4974
- const classList = getClassList(elm);
4975
- let computedClassName = '';
4976
- // all classes from the vnode should be in the element.classList
4977
- for (const name in classMap) {
4978
- computedClassName += ' ' + name;
4979
- if (!classList.contains(name)) {
4980
- nodesAreCompatible = false;
4981
- }
4982
- }
4983
- vnodeClassName = computedClassName.trim();
4984
- if (classList.length > keys(classMap).length) {
4985
- nodesAreCompatible = false;
4986
- }
4987
- }
4988
- if (!nodesAreCompatible) {
4989
- logError(`Mismatch hydrating element <${getProperty(elm, 'tagName').toLowerCase()}>: attribute "class" has different values, expected "${vnodeClassName}" but found "${getProperty(elm, 'className')}"`, vnode.owner);
4990
- }
4991
- return nodesAreCompatible;
4992
- }
4993
- function validateStyleAttr(vnode, elm) {
4994
- const { data: { style, styleDecls }, } = vnode;
4995
- const elmStyle = getAttribute(elm, 'style') || '';
4996
- let vnodeStyle;
4997
- let nodesAreCompatible = true;
4998
- if (!isUndefined$1(style) && style !== elmStyle) {
4999
- nodesAreCompatible = false;
5000
- vnodeStyle = style;
5001
- }
5002
- else if (!isUndefined$1(styleDecls)) {
5003
- const parsedVnodeStyle = parseStyleText(elmStyle);
5004
- const expectedStyle = [];
5005
- // styleMap is used when style is set to static value.
5006
- for (let i = 0, n = styleDecls.length; i < n; i++) {
5007
- const [prop, value, important] = styleDecls[i];
5008
- expectedStyle.push(`${prop}: ${value + (important ? ' important!' : '')}`);
5009
- const parsedPropValue = parsedVnodeStyle[prop];
5010
- if (isUndefined$1(parsedPropValue)) {
5011
- nodesAreCompatible = false;
5012
- }
5013
- else if (!parsedPropValue.startsWith(value)) {
5014
- nodesAreCompatible = false;
5015
- }
5016
- else if (important && !parsedPropValue.endsWith('!important')) {
5017
- nodesAreCompatible = false;
5018
- }
5019
- }
5020
- if (keys(parsedVnodeStyle).length > styleDecls.length) {
5021
- nodesAreCompatible = false;
5022
- }
5023
- vnodeStyle = ArrayJoin.call(expectedStyle, ';');
5024
- }
5025
- if (!nodesAreCompatible) {
5026
- // style is used when class is bound to an expr.
5027
- logError(`Mismatch hydrating element <${getProperty(elm, 'tagName').toLowerCase()}>: attribute "style" has different values, expected "${vnodeStyle}" but found "${elmStyle}".`, vnode.owner);
5028
- }
5029
- return nodesAreCompatible;
5030
- }
5031
-
5032
4802
  /*
5033
4803
  * Copyright (c) 2018, salesforce.com, inc.
5034
4804
  * All rights reserved.
@@ -5074,32 +4844,12 @@ function connectRootElement(elm) {
5074
4844
  /* GlobalHydrate */
5075
4845
  , vm);
5076
4846
  }
5077
- function hydrateRootElement(elm) {
5078
- const vm = getAssociatedVM(elm);
5079
- runConnectedCallback(vm);
5080
- hydrateVM(vm);
5081
- }
5082
4847
  function disconnectRootElement(elm) {
5083
4848
  const vm = getAssociatedVM(elm);
5084
4849
  resetComponentStateWhenRemoved(vm);
5085
4850
  }
5086
4851
  function appendVM(vm) {
5087
4852
  rehydrate(vm);
5088
- }
5089
- function hydrateVM(vm) {
5090
- if (isTrue(vm.isDirty)) {
5091
- // manually diffing/patching here.
5092
- // This routine is:
5093
- // patchShadowRoot(vm, children);
5094
- // -> addVnodes.
5095
- const children = renderComponent(vm);
5096
- vm.children = children;
5097
- const vmChildren = vm.renderMode === 0
5098
- /* Light */
5099
- ? getChildNodes(vm.elm) : getChildNodes(vm.elm.shadowRoot);
5100
- hydrateChildren(vmChildren, children, vm);
5101
- runRenderedCallback(vm);
5102
- }
5103
4853
  } // just in case the component comes back, with this we guarantee re-rendering it
5104
4854
  // while preventing any attempt to rehydration until after reinsertion.
5105
4855
 
@@ -5404,7 +5154,6 @@ function runRenderedCallback(vm) {
5404
5154
  , vm);
5405
5155
  }
5406
5156
  }
5407
-
5408
5157
  let rehydrateQueue = [];
5409
5158
 
5410
5159
  function flushRehydrationQueue() {
@@ -6061,6 +5810,298 @@ function readonly(obj) {
6061
5810
  return reactiveMembrane.getReadOnlyProxy(obj);
6062
5811
  }
6063
5812
 
5813
+ /*
5814
+ * Copyright (c) 2022, salesforce.com, inc.
5815
+ * All rights reserved.
5816
+ * SPDX-License-Identifier: MIT
5817
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5818
+ */
5819
+ // flag indicating if the hydration recovered from the DOM mismatch
5820
+ let hasMismatch = false;
5821
+ function hydrateRoot(vm) {
5822
+ hasMismatch = false;
5823
+ runConnectedCallback(vm);
5824
+ hydrateVM(vm);
5825
+ if (hasMismatch) {
5826
+ logError('Hydration completed with errors.', vm);
5827
+ }
5828
+ }
5829
+ function hydrateVM(vm) {
5830
+ const children = renderComponent(vm);
5831
+ vm.children = children;
5832
+ const parentNode = vm.renderRoot;
5833
+ hydrateChildren(getFirstChild(parentNode), children, parentNode, vm);
5834
+ runRenderedCallback(vm);
5835
+ }
5836
+ function hydrateNode(node, vnode) {
5837
+ let hydratedNode;
5838
+ switch (vnode.type) {
5839
+ case 0 /* Text */:
5840
+ hydratedNode = hydrateText(node, vnode);
5841
+ break;
5842
+ case 1 /* Comment */:
5843
+ hydratedNode = hydrateComment(node, vnode);
5844
+ break;
5845
+ case 2 /* Element */:
5846
+ hydratedNode = hydrateElement(node, vnode);
5847
+ break;
5848
+ case 3 /* CustomElement */:
5849
+ hydratedNode = hydrateCustomElement(node, vnode);
5850
+ break;
5851
+ }
5852
+ return nextSibling(hydratedNode);
5853
+ }
5854
+ function hydrateText(node, vnode) {
5855
+ var _a;
5856
+ if (!hasCorrectNodeType(vnode, node, 3 /* TEXT */)) {
5857
+ return handleMismatch(node, vnode);
5858
+ }
5859
+ if (process.env.NODE_ENV !== 'production') {
5860
+ const nodeValue = getProperty(node, 'nodeValue');
5861
+ if (nodeValue !== vnode.text && !(nodeValue === '\u200D' && vnode.text === '')) {
5862
+ logWarn('Hydration mismatch: text values do not match, will recover from the difference', vnode.owner);
5863
+ }
5864
+ }
5865
+ setText(node, (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
5866
+ vnode.elm = node;
5867
+ return node;
5868
+ }
5869
+ function hydrateComment(node, vnode) {
5870
+ var _a;
5871
+ if (!hasCorrectNodeType(vnode, node, 8 /* COMMENT */)) {
5872
+ return handleMismatch(node, vnode);
5873
+ }
5874
+ if (process.env.NODE_ENV !== 'production') {
5875
+ const nodeValue = getProperty(node, 'nodeValue');
5876
+ if (nodeValue !== vnode.text) {
5877
+ logWarn('Hydration mismatch: comment values do not match, will recover from the difference', vnode.owner);
5878
+ }
5879
+ }
5880
+ setProperty(node, 'nodeValue', (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
5881
+ vnode.elm = node;
5882
+ return node;
5883
+ }
5884
+ function hydrateElement(elm, vnode) {
5885
+ if (!hasCorrectNodeType(vnode, elm, 1 /* ELEMENT */) ||
5886
+ !isMatchingElement(vnode, elm)) {
5887
+ return handleMismatch(elm, vnode);
5888
+ }
5889
+ vnode.elm = elm;
5890
+ const { context } = vnode.data;
5891
+ const isDomManual = Boolean(!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual" /* Manual */);
5892
+ if (isDomManual) {
5893
+ // it may be that this element has lwc:inner-html, we need to diff and in case are the same,
5894
+ // remove the innerHTML from props so it reuses the existing dom elements.
5895
+ const { props } = vnode.data;
5896
+ if (!isUndefined$1(props) && !isUndefined$1(props.innerHTML)) {
5897
+ if (getProperty(elm, 'innerHTML') === props.innerHTML) {
5898
+ // Do a shallow clone since VNodeData may be shared across VNodes due to hoist optimization
5899
+ vnode.data = Object.assign(Object.assign({}, vnode.data), { props: cloneAndOmitKey(props, 'innerHTML') });
5900
+ }
5901
+ else {
5902
+ if (process.env.NODE_ENV !== 'production') {
5903
+ logWarn(`Mismatch hydrating element <${getProperty(elm, 'tagName').toLowerCase()}>: innerHTML values do not match for element, will recover from the difference`, vnode.owner);
5904
+ }
5905
+ }
5906
+ }
5907
+ }
5908
+ patchElementPropsAndAttrs(vnode);
5909
+ if (!isDomManual) {
5910
+ hydrateChildren(getFirstChild(elm), vnode.children, elm, vnode.owner);
5911
+ }
5912
+ return elm;
5913
+ }
5914
+ function hydrateCustomElement(elm, vnode) {
5915
+ if (!hasCorrectNodeType(vnode, elm, 1 /* ELEMENT */) ||
5916
+ !isMatchingElement(vnode, elm)) {
5917
+ return handleMismatch(elm, vnode);
5918
+ }
5919
+ const { sel, mode, ctor, owner } = vnode;
5920
+ const vm = createVM(elm, ctor, {
5921
+ mode,
5922
+ owner,
5923
+ tagName: sel,
5924
+ });
5925
+ vnode.elm = elm;
5926
+ vnode.vm = vm;
5927
+ allocateChildren(vnode, vm);
5928
+ patchElementPropsAndAttrs(vnode);
5929
+ // Insert hook section:
5930
+ if (process.env.NODE_ENV !== 'production') {
5931
+ assert.isTrue(vm.state === 0 /* created */, `${vm} cannot be recycled.`);
5932
+ }
5933
+ runConnectedCallback(vm);
5934
+ if (vm.renderMode !== 0 /* Light */) {
5935
+ // VM is not rendering in Light DOM, we can proceed and hydrate the slotted content.
5936
+ // Note: for Light DOM, this is handled while hydrating the VM
5937
+ hydrateChildren(getFirstChild(elm), vnode.children, elm, vm);
5938
+ }
5939
+ hydrateVM(vm);
5940
+ return elm;
5941
+ }
5942
+ function hydrateChildren(node, children, parentNode, owner) {
5943
+ let hasWarned = false;
5944
+ let nextNode = node;
5945
+ let anchor = null;
5946
+ for (let i = 0; i < children.length; i++) {
5947
+ const childVnode = children[i];
5948
+ if (!isNull(childVnode)) {
5949
+ if (nextNode) {
5950
+ nextNode = hydrateNode(nextNode, childVnode);
5951
+ anchor = childVnode.elm;
5952
+ }
5953
+ else {
5954
+ hasMismatch = true;
5955
+ if (process.env.NODE_ENV !== 'production') {
5956
+ if (!hasWarned) {
5957
+ hasWarned = true;
5958
+ logError(`Hydration mismatch: incorrect number of rendered nodes. Client produced more nodes than the server.`, owner);
5959
+ }
5960
+ }
5961
+ mount(childVnode, parentNode, anchor);
5962
+ anchor = childVnode.elm;
5963
+ }
5964
+ }
5965
+ }
5966
+ if (nextNode) {
5967
+ hasMismatch = true;
5968
+ if (process.env.NODE_ENV !== 'production') {
5969
+ if (!hasWarned) {
5970
+ logError(`Hydration mismatch: incorrect number of rendered nodes. Server rendered more nodes than the client.`, owner);
5971
+ }
5972
+ }
5973
+ do {
5974
+ const current = nextNode;
5975
+ nextNode = nextSibling(nextNode);
5976
+ removeNode(current, parentNode);
5977
+ } while (nextNode);
5978
+ }
5979
+ }
5980
+ function handleMismatch(node, vnode, msg) {
5981
+ hasMismatch = true;
5982
+ if (!isUndefined$1(msg)) {
5983
+ if (process.env.NODE_ENV !== 'production') {
5984
+ logError(msg, vnode.owner);
5985
+ }
5986
+ }
5987
+ const parentNode = getProperty(node, 'parentNode');
5988
+ mount(vnode, parentNode, node);
5989
+ removeNode(node, parentNode);
5990
+ return vnode.elm;
5991
+ }
5992
+ function patchElementPropsAndAttrs(vnode) {
5993
+ applyEventListeners(vnode);
5994
+ patchProps(null, vnode);
5995
+ }
5996
+ function hasCorrectNodeType(vnode, node, nodeType) {
5997
+ if (getProperty(node, 'nodeType') !== nodeType) {
5998
+ if (process.env.NODE_ENV !== 'production') {
5999
+ logError('Hydration mismatch: incorrect node type received', vnode.owner);
6000
+ }
6001
+ return false;
6002
+ }
6003
+ return true;
6004
+ }
6005
+ function isMatchingElement(vnode, elm) {
6006
+ if (vnode.sel.toLowerCase() !== getProperty(elm, 'tagName').toLowerCase()) {
6007
+ if (process.env.NODE_ENV !== 'production') {
6008
+ logError(`Hydration mismatch: expecting element with tag "${vnode.sel.toLowerCase()}" but found "${getProperty(elm, 'tagName').toLowerCase()}".`, vnode.owner);
6009
+ }
6010
+ return false;
6011
+ }
6012
+ const hasIncompatibleAttrs = validateAttrs(vnode, elm);
6013
+ const hasIncompatibleClass = validateClassAttr(vnode, elm);
6014
+ const hasIncompatibleStyle = validateStyleAttr(vnode, elm);
6015
+ return hasIncompatibleAttrs && hasIncompatibleClass && hasIncompatibleStyle;
6016
+ }
6017
+ function validateAttrs(vnode, elm) {
6018
+ const { data: { attrs = {} }, } = vnode;
6019
+ let nodesAreCompatible = true;
6020
+ // Validate attributes, though we could always recovery from those by running the update mods.
6021
+ // Note: intentionally ONLY matching vnodes.attrs to elm.attrs, in case SSR is adding extra attributes.
6022
+ for (const [attrName, attrValue] of Object.entries(attrs)) {
6023
+ const elmAttrValue = getAttribute(elm, attrName);
6024
+ if (String(attrValue) !== elmAttrValue) {
6025
+ if (process.env.NODE_ENV !== 'production') {
6026
+ logError(`Mismatch hydrating element <${getProperty(elm, 'tagName').toLowerCase()}>: attribute "${attrName}" has different values, expected "${attrValue}" but found "${elmAttrValue}"`, vnode.owner);
6027
+ }
6028
+ nodesAreCompatible = false;
6029
+ }
6030
+ }
6031
+ return nodesAreCompatible;
6032
+ }
6033
+ function validateClassAttr(vnode, elm) {
6034
+ const { data: { className, classMap }, } = vnode;
6035
+ let nodesAreCompatible = true;
6036
+ let vnodeClassName;
6037
+ if (!isUndefined$1(className) && String(className) !== getProperty(elm, 'className')) {
6038
+ // className is used when class is bound to an expr.
6039
+ nodesAreCompatible = false;
6040
+ vnodeClassName = className;
6041
+ }
6042
+ else if (!isUndefined$1(classMap)) {
6043
+ // classMap is used when class is set to static value.
6044
+ const classList = getClassList(elm);
6045
+ let computedClassName = '';
6046
+ // all classes from the vnode should be in the element.classList
6047
+ for (const name in classMap) {
6048
+ computedClassName += ' ' + name;
6049
+ if (!classList.contains(name)) {
6050
+ nodesAreCompatible = false;
6051
+ }
6052
+ }
6053
+ vnodeClassName = computedClassName.trim();
6054
+ if (classList.length > keys(classMap).length) {
6055
+ nodesAreCompatible = false;
6056
+ }
6057
+ }
6058
+ if (!nodesAreCompatible) {
6059
+ if (process.env.NODE_ENV !== 'production') {
6060
+ logError(`Mismatch hydrating element <${getProperty(elm, 'tagName').toLowerCase()}>: attribute "class" has different values, expected "${vnodeClassName}" but found "${getProperty(elm, 'className')}"`, vnode.owner);
6061
+ }
6062
+ }
6063
+ return nodesAreCompatible;
6064
+ }
6065
+ function validateStyleAttr(vnode, elm) {
6066
+ const { data: { style, styleDecls }, } = vnode;
6067
+ const elmStyle = getAttribute(elm, 'style') || '';
6068
+ let vnodeStyle;
6069
+ let nodesAreCompatible = true;
6070
+ if (!isUndefined$1(style) && style !== elmStyle) {
6071
+ nodesAreCompatible = false;
6072
+ vnodeStyle = style;
6073
+ }
6074
+ else if (!isUndefined$1(styleDecls)) {
6075
+ const parsedVnodeStyle = parseStyleText(elmStyle);
6076
+ const expectedStyle = [];
6077
+ // styleMap is used when style is set to static value.
6078
+ for (let i = 0, n = styleDecls.length; i < n; i++) {
6079
+ const [prop, value, important] = styleDecls[i];
6080
+ expectedStyle.push(`${prop}: ${value + (important ? ' important!' : '')}`);
6081
+ const parsedPropValue = parsedVnodeStyle[prop];
6082
+ if (isUndefined$1(parsedPropValue)) {
6083
+ nodesAreCompatible = false;
6084
+ }
6085
+ else if (!parsedPropValue.startsWith(value)) {
6086
+ nodesAreCompatible = false;
6087
+ }
6088
+ else if (important && !parsedPropValue.endsWith('!important')) {
6089
+ nodesAreCompatible = false;
6090
+ }
6091
+ }
6092
+ if (keys(parsedVnodeStyle).length > styleDecls.length) {
6093
+ nodesAreCompatible = false;
6094
+ }
6095
+ vnodeStyle = ArrayJoin.call(expectedStyle, ';');
6096
+ }
6097
+ if (!nodesAreCompatible) {
6098
+ if (process.env.NODE_ENV !== 'production') {
6099
+ logError(`Mismatch hydrating element <${getProperty(elm, 'tagName').toLowerCase()}>: attribute "style" has different values, expected "${vnodeStyle}" but found "${elmStyle}".`, vnode.owner);
6100
+ }
6101
+ }
6102
+ return nodesAreCompatible;
6103
+ }
6104
+
6064
6105
  /*
6065
6106
  * Copyright (c) 2018, salesforce.com, inc.
6066
6107
  * All rights reserved.
@@ -6074,5 +6115,5 @@ function setHooks(hooks) {
6074
6115
  setSanitizeHtmlContentHook(hooks.sanitizeHtmlContent);
6075
6116
  }
6076
6117
 
6077
- export { LightningElement, profilerControl as __unstable__ProfilerControl, api$1 as api, connectRootElement, createContextProvider, createVM, disconnectRootElement, getAssociatedVMIfPresent, getComponentDef, getComponentHtmlPrototype, getUpgradableConstructor, hydrateRootElement, isComponentConstructor, readonly, register, registerComponent, registerDecorators, registerTemplate, sanitizeAttribute, setAddEventListener, setAssertInstanceOfHTMLElement, setAttachShadow, setCreateComment, setCreateElement, setCreateText, setDefineCustomElement, setDispatchEvent, setGetAttribute, setGetBoundingClientRect, setGetChildNodes, setGetChildren, setGetClassList, setGetCustomElement, setGetElementsByClassName, setGetElementsByTagName, setGetFirstChild, setGetFirstElementChild, setGetLastChild, setGetLastElementChild, setGetProperty, setHTMLElement, setHooks, setInsert, setInsertGlobalStylesheet, setInsertStylesheet, setIsConnected, setIsHydrating, setIsNativeShadowDefined, setIsSyntheticShadowDefined, setNextSibling, setQuerySelector, setQuerySelectorAll, setRemove, setRemoveAttribute, setRemoveEventListener, setSetAttribute, setSetCSSStyleProperty, setSetProperty, setSetText, setSsr, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
6078
- /* version: 2.11.1 */
6118
+ export { LightningElement, profilerControl as __unstable__ProfilerControl, api$1 as api, connectRootElement, createContextProvider, createVM, disconnectRootElement, getAssociatedVMIfPresent, getComponentDef, getComponentHtmlPrototype, getUpgradableConstructor, hydrateRoot, isComponentConstructor, readonly, register, registerComponent, registerDecorators, registerTemplate, sanitizeAttribute, setAddEventListener, setAssertInstanceOfHTMLElement, setAttachShadow, setCreateComment, setCreateElement, setCreateText, setDefineCustomElement, setDispatchEvent, setGetAttribute, setGetBoundingClientRect, setGetChildNodes, setGetChildren, setGetClassList, setGetCustomElement, setGetElementsByClassName, setGetElementsByTagName, setGetFirstChild, setGetFirstElementChild, setGetLastChild, setGetLastElementChild, setGetProperty, setHTMLElement, setHooks, setInsert, setInsertGlobalStylesheet, setInsertStylesheet, setIsConnected, setIsHydrating, setIsNativeShadowDefined, setIsSyntheticShadowDefined, setNextSibling, setQuerySelector, setQuerySelectorAll, setRemove, setRemoveAttribute, setRemoveEventListener, setSetAttribute, setSetCSSStyleProperty, setSetProperty, setSetText, setSsr, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
6119
+ /* version: 2.11.3 */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lwc/engine-core",
3
- "version": "2.11.1",
3
+ "version": "2.11.3",
4
4
  "description": "Core LWC engine APIs.",
5
5
  "homepage": "https://lwc.dev/",
6
6
  "repository": {
@@ -24,14 +24,13 @@
24
24
  "types/"
25
25
  ],
26
26
  "dependencies": {
27
- "@lwc/features": "2.11.1",
28
- "@lwc/shared": "2.11.1"
27
+ "@lwc/features": "2.11.3",
28
+ "@lwc/shared": "2.11.3"
29
29
  },
30
30
  "devDependencies": {
31
31
  "observable-membrane": "2.0.0"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public"
35
- },
36
- "gitHead": "94040389ab8fc717b8753e503f659489480a327d"
35
+ }
37
36
  }
@@ -1,3 +1,2 @@
1
1
  import { VM } from './vm';
2
- import { VNodes } from './vnodes';
3
- export declare function hydrateChildren(elmChildren: NodeList, children: VNodes, vm: VM): void;
2
+ export declare function hydrateRoot(vm: VM): void;
@@ -7,7 +7,8 @@ export { default as wire } from './decorators/wire';
7
7
  export { readonly } from './readonly';
8
8
  export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
9
9
  export { getComponentHtmlPrototype } from './def';
10
- export { createVM, connectRootElement, disconnectRootElement, getAssociatedVMIfPresent, hydrateRootElement, } from './vm';
10
+ export { createVM, connectRootElement, disconnectRootElement, getAssociatedVMIfPresent, } from './vm';
11
+ export { hydrateRoot } from './hydration';
11
12
  export { registerComponent } from './component';
12
13
  export { registerTemplate } from './secure-template';
13
14
  export { registerDecorators } from './decorators/register';
@@ -1,5 +1,7 @@
1
1
  import { VM } from './vm';
2
- import { VNodes, VCustomElement } from './vnodes';
2
+ import { VNode, VNodes, VCustomElement } from './vnodes';
3
3
  export declare function patchChildren(c1: VNodes, c2: VNodes, parent: ParentNode): void;
4
+ export declare function mount(node: VNode, parent: ParentNode, anchor: Node | null): void;
5
+ export declare function removeNode(node: Node, parent: ParentNode): void;
4
6
  export declare function allocateChildren(vnode: VCustomElement, vm: VM): void;
5
7
  export declare function markAsDynamicChildren(children: VNodes): void;
@@ -123,10 +123,8 @@ export interface VM<N = HostNode, E = HostElement> {
123
123
  declare type VMAssociable = HostNode | LightningElement;
124
124
  export declare function rerenderVM(vm: VM): void;
125
125
  export declare function connectRootElement(elm: any): void;
126
- export declare function hydrateRootElement(elm: any): void;
127
126
  export declare function disconnectRootElement(elm: any): void;
128
127
  export declare function appendVM(vm: VM): void;
129
- export declare function hydrateVM(vm: VM): void;
130
128
  export declare function removeVM(vm: VM): void;
131
129
  export declare function createVM<HostNode, HostElement>(elm: HostElement, ctor: LightningElementConstructor, options: {
132
130
  mode: ShadowRootMode;
@@ -136,6 +134,7 @@ export declare function createVM<HostNode, HostElement>(elm: HostElement, ctor:
136
134
  export declare function associateVM(obj: VMAssociable, vm: VM): void;
137
135
  export declare function getAssociatedVM(obj: VMAssociable): VM;
138
136
  export declare function getAssociatedVMIfPresent(obj: VMAssociable): VM | undefined;
137
+ export declare function runRenderedCallback(vm: VM): void;
139
138
  export declare function runConnectedCallback(vm: VM): void;
140
139
  export declare function resetComponentRoot(vm: VM): void;
141
140
  export declare function scheduleRehydration(vm: VM): void;