lwc 2.5.7 → 2.5.8

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.
Files changed (35) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +490 -68
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +490 -67
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +2 -2
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +306 -60
  5. package/dist/engine-dom/iife/es5/engine-dom.js +566 -129
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +2 -2
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +363 -113
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +490 -67
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +2 -2
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +306 -60
  11. package/dist/engine-dom/umd/es5/engine-dom.js +566 -129
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +2 -2
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +363 -113
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +361 -11
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +2 -2
  16. package/dist/engine-server/esm/es2017/engine-server.js +361 -11
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +3 -3
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +3 -3
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +3 -3
  20. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +3 -3
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +3 -3
  22. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +3 -3
  23. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +3 -3
  24. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +3 -3
  25. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +3 -3
  26. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  27. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  28. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  29. package/dist/wire-service/iife/es5/wire-service.js +2 -2
  30. package/dist/wire-service/iife/es5/wire-service_debug.js +2 -2
  31. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/umd/es5/wire-service.js +2 -2
  34. package/dist/wire-service/umd/es5/wire-service_debug.js +2 -2
  35. package/package.json +8 -8
@@ -301,7 +301,7 @@
301
301
  CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName);
302
302
  return attributeName;
303
303
  }
304
- /** version: 2.5.7 */
304
+ /** version: 2.5.8 */
305
305
 
306
306
  /*
307
307
  * Copyright (c) 2018, salesforce.com, inc.
@@ -473,7 +473,7 @@
473
473
 
474
474
  function setFeatureFlagForTest(name, value) {
475
475
  }
476
- /** version: 2.5.7 */
476
+ /** version: 2.5.8 */
477
477
 
478
478
  /* proxy-compat-disable */
479
479
 
@@ -515,7 +515,7 @@
515
515
  }
516
516
 
517
517
  return s4() + s4() + '-' + s4() + '-' + s4() + '-' + s4() + '-' + s4() + s4() + s4();
518
- }
518
+ } // Borrowed from Vue template compiler.
519
519
  /*
520
520
  * Copyright (c) 2019, salesforce.com, inc.
521
521
  * All rights reserved.
@@ -663,6 +663,20 @@
663
663
  return `<${StringToLowerCase.call(vm.tagName)}>`;
664
664
  } // TODO [#1695]: Unify getComponentStack and getErrorComponentStack
665
665
 
666
+
667
+ function getComponentStack(vm) {
668
+ const stack = [];
669
+ let prefix = '';
670
+
671
+ while (!isNull(vm.owner)) {
672
+ ArrayPush$1.call(stack, prefix + getComponentTag(vm));
673
+ vm = vm.owner;
674
+ prefix += '\t';
675
+ }
676
+
677
+ return ArrayJoin.call(stack, '\n');
678
+ }
679
+
666
680
  function getErrorComponentStack(vm) {
667
681
  const wcStack = [];
668
682
  let currentVm = vm;
@@ -682,6 +696,32 @@
682
696
  */
683
697
 
684
698
 
699
+ function log(method, message, vm) {
700
+ let msg = `[LWC ${method}]: ${message}`;
701
+
702
+ if (!isUndefined$1(vm)) {
703
+ msg = `${msg}\n${getComponentStack(vm)}`;
704
+ }
705
+
706
+ try {
707
+ throw new Error(msg);
708
+ } catch (e) {
709
+ /* eslint-disable-next-line no-console */
710
+ console[method](e);
711
+ }
712
+ }
713
+
714
+ function logWarn(message, vm) {
715
+ log('warn', message, vm);
716
+ }
717
+ /*
718
+ * Copyright (c) 2018, salesforce.com, inc.
719
+ * All rights reserved.
720
+ * SPDX-License-Identifier: MIT
721
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
722
+ */
723
+
724
+
685
725
  function handleEvent(event, vnode) {
686
726
  const {
687
727
  type
@@ -3434,6 +3474,17 @@
3434
3474
  modComputedStyle.create(vnode);
3435
3475
  }
3436
3476
 
3477
+ function hydrateElmHook(vnode) {
3478
+ modEvents.create(vnode); // Attrs are already on the element.
3479
+ // modAttrs.create(vnode);
3480
+
3481
+ modProps.create(vnode); // Already set.
3482
+ // modStaticClassName.create(vnode);
3483
+ // modStaticStyle.create(vnode);
3484
+ // modComputedClassName.create(vnode);
3485
+ // modComputedStyle.create(vnode);
3486
+ }
3487
+
3437
3488
  function fallbackElmHook(elm, vnode) {
3438
3489
  const {
3439
3490
  owner
@@ -3583,6 +3634,22 @@
3583
3634
  }
3584
3635
  }
3585
3636
 
3637
+ function hydrateChildrenHook(elmChildren, children, vm) {
3638
+
3639
+ let elmCurrentChildIdx = 0;
3640
+
3641
+ for (let j = 0, n = children.length; j < n; j++) {
3642
+ const ch = children[j];
3643
+
3644
+ if (ch != null) {
3645
+ const childNode = elmChildren[elmCurrentChildIdx];
3646
+
3647
+ ch.hook.hydrate(ch, childNode);
3648
+ elmCurrentChildIdx++;
3649
+ }
3650
+ }
3651
+ }
3652
+
3586
3653
  function updateCustomElmHook(oldVnode, vnode) {
3587
3654
  // Attrs need to be applied to element before props
3588
3655
  // IE11 will wipe out value on radio inputs if value
@@ -3684,7 +3751,14 @@
3684
3751
  update: updateNodeHook,
3685
3752
  insert: insertNodeHook,
3686
3753
  move: insertNodeHook,
3687
- remove: removeNodeHook
3754
+ remove: removeNodeHook,
3755
+ hydrate: (vNode, node) => {
3756
+ var _a;
3757
+
3758
+
3759
+ node.nodeValue = (_a = vNode.text) !== null && _a !== void 0 ? _a : null;
3760
+ vNode.elm = node;
3761
+ }
3688
3762
  };
3689
3763
  const CommentHook = {
3690
3764
  create: vnode => {
@@ -3702,7 +3776,14 @@
3702
3776
  update: updateNodeHook,
3703
3777
  insert: insertNodeHook,
3704
3778
  move: insertNodeHook,
3705
- remove: removeNodeHook
3779
+ remove: removeNodeHook,
3780
+ hydrate: (vNode, node) => {
3781
+ var _a;
3782
+
3783
+
3784
+ node.nodeValue = (_a = vNode.text) !== null && _a !== void 0 ? _a : null;
3785
+ vNode.elm = node;
3786
+ }
3706
3787
  }; // insert is called after update, which is used somewhere else (via a module)
3707
3788
  // to mark the vm as inserted, that means we cannot use update as the main channel
3708
3789
  // to rehydrate when dirty, because sometimes the element is not inserted just yet,
@@ -3742,6 +3823,38 @@
3742
3823
  remove: (vnode, parentNode) => {
3743
3824
  removeNodeHook(vnode, parentNode);
3744
3825
  removeElmHook(vnode);
3826
+ },
3827
+ hydrate: (vnode, node) => {
3828
+ const elm = node;
3829
+ vnode.elm = elm;
3830
+ const {
3831
+ context
3832
+ } = vnode.data;
3833
+ const isDomManual = Boolean(!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
3834
+ /* manual */
3835
+ );
3836
+
3837
+ if (isDomManual) {
3838
+ // it may be that this element has lwc:inner-html, we need to diff and in case are the same,
3839
+ // remove the innerHTML from props so it reuses the existing dom elements.
3840
+ const {
3841
+ props
3842
+ } = vnode.data;
3843
+
3844
+ if (!isUndefined$1(props) && !isUndefined$1(props.innerHTML)) {
3845
+ if (elm.innerHTML === props.innerHTML) {
3846
+ delete props.innerHTML;
3847
+ } else {
3848
+ logWarn(`Mismatch hydrating element <${elm.tagName.toLowerCase()}>: innerHTML values do not match for element, will recover from the difference`, vnode.owner);
3849
+ }
3850
+ }
3851
+ }
3852
+
3853
+ hydrateElmHook(vnode);
3854
+
3855
+ if (!isDomManual) {
3856
+ hydrateChildrenHook(vnode.elm.childNodes, vnode.children, vnode.owner);
3857
+ }
3745
3858
  }
3746
3859
  };
3747
3860
  const CustomElementHook = {
@@ -3825,6 +3938,38 @@
3825
3938
  // will take care of disconnecting any child VM attached to its shadow as well.
3826
3939
  removeVM(vm);
3827
3940
  }
3941
+ },
3942
+ hydrate: (vnode, elm) => {
3943
+ // the element is created, but the vm is not
3944
+ const {
3945
+ sel,
3946
+ mode,
3947
+ ctor,
3948
+ owner
3949
+ } = vnode;
3950
+ const def = getComponentInternalDef(ctor);
3951
+ createVM(elm, def, {
3952
+ mode,
3953
+ owner,
3954
+ tagName: sel,
3955
+ renderer: owner.renderer
3956
+ });
3957
+ vnode.elm = elm;
3958
+ const vm = getAssociatedVM(elm);
3959
+ allocateChildrenHook(vnode, vm);
3960
+ hydrateElmHook(vnode); // Insert hook section:
3961
+
3962
+ runConnectedCallback(vm);
3963
+
3964
+ if (vm.renderMode !== 0
3965
+ /* Light */
3966
+ ) {
3967
+ // VM is not rendering in Light DOM, we can proceed and hydrate the slotted content.
3968
+ // Note: for Light DOM, this is handled while hydrating the VM
3969
+ hydrateChildrenHook(vnode.elm.childNodes, vnode.children);
3970
+ }
3971
+
3972
+ hydrateVM(vm);
3828
3973
  }
3829
3974
  };
3830
3975
 
@@ -4383,7 +4528,10 @@
4383
4528
  for (let i = 0; i < stylesheets.length; i++) {
4384
4529
  renderer.insertGlobalStylesheet(stylesheets[i]);
4385
4530
  }
4386
- } else if (renderer.ssr) {
4531
+ } else if (renderer.ssr || renderer.isHydrating) {
4532
+ // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
4533
+ // This works in the client, because the stylesheets are created, and cached in the VM
4534
+ // the first time the VM renders.
4387
4535
  // native shadow or light DOM, SSR
4388
4536
  const combinedStylesheetContent = ArrayJoin.call(stylesheets, '\n');
4389
4537
  return createInlineStyleVNode(combinedStylesheetContent);
@@ -4882,6 +5030,12 @@
4882
5030
  , vm);
4883
5031
  }
4884
5032
 
5033
+ function hydrateRootElement(elm) {
5034
+ const vm = getAssociatedVM(elm);
5035
+ runConnectedCallback(vm);
5036
+ hydrateVM(vm);
5037
+ }
5038
+
4885
5039
  function disconnectRootElement(elm) {
4886
5040
  const vm = getAssociatedVM(elm);
4887
5041
  resetComponentStateWhenRemoved(vm);
@@ -4889,6 +5043,10 @@
4889
5043
 
4890
5044
  function appendVM(vm) {
4891
5045
  rehydrate(vm);
5046
+ }
5047
+
5048
+ function hydrateVM(vm) {
5049
+ hydrate(vm);
4892
5050
  } // just in case the component comes back, with this we guarantee re-rendering it
4893
5051
  // while preventing any attempt to rehydration until after reinsertion.
4894
5052
 
@@ -5083,6 +5241,22 @@
5083
5241
  }
5084
5242
  }
5085
5243
 
5244
+ function hydrate(vm) {
5245
+ if (isTrue(vm.isDirty)) {
5246
+ // manually diffing/patching here.
5247
+ // This routine is:
5248
+ // patchShadowRoot(vm, children);
5249
+ // -> addVnodes.
5250
+ const children = renderComponent(vm);
5251
+ vm.children = children;
5252
+ const vmChildren = vm.renderMode === 0
5253
+ /* Light */
5254
+ ? vm.elm.childNodes : vm.elm.shadowRoot.childNodes;
5255
+ hydrateChildrenHook(vmChildren, children);
5256
+ runRenderedCallback(vm);
5257
+ }
5258
+ }
5259
+
5086
5260
  function patchShadowRoot(vm, newCh) {
5087
5261
  const {
5088
5262
  children: oldCh
@@ -5877,7 +6051,7 @@
5877
6051
  hooksAreSet = true;
5878
6052
  setSanitizeHtmlContentHook(hooks.sanitizeHtmlContent);
5879
6053
  }
5880
- /* version: 2.5.7 */
6054
+ /* version: 2.5.8 */
5881
6055
 
5882
6056
  /*
5883
6057
  * Copyright (c) 2018, salesforce.com, inc.
@@ -6012,8 +6186,19 @@
6012
6186
  HTMLElementConstructor.prototype = HTMLElement.prototype;
6013
6187
  }
6014
6188
 
6189
+ let isHydrating = false;
6190
+
6191
+ function setIsHydrating(v) {
6192
+ isHydrating = v;
6193
+ }
6194
+
6015
6195
  const renderer = {
6016
6196
  ssr: false,
6197
+
6198
+ get isHydrating() {
6199
+ return isHydrating;
6200
+ },
6201
+
6017
6202
  isNativeShadowDefined: _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED],
6018
6203
  isSyntheticShadowDefined: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
6019
6204
 
@@ -6042,6 +6227,10 @@
6042
6227
  },
6043
6228
 
6044
6229
  attachShadow(element, options) {
6230
+ if (isHydrating) {
6231
+ return element.shadowRoot;
6232
+ }
6233
+
6045
6234
  return element.attachShadow(options);
6046
6235
  },
6047
6236
 
@@ -6173,57 +6362,6 @@
6173
6362
  getCustomElement,
6174
6363
  HTMLElement: HTMLElementConstructor
6175
6364
  };
6176
- /*
6177
- * Copyright (c) 2018, salesforce.com, inc.
6178
- * All rights reserved.
6179
- * SPDX-License-Identifier: MIT
6180
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6181
- */
6182
-
6183
- /**
6184
- * This function builds a Web Component class from a LWC constructor so it can be
6185
- * registered as a new element via customElements.define() at any given time.
6186
- *
6187
- * @deprecated since version 1.3.11
6188
- *
6189
- * @example
6190
- * ```
6191
- * import { buildCustomElementConstructor } from 'lwc';
6192
- * import Foo from 'ns/foo';
6193
- * const WC = buildCustomElementConstructor(Foo);
6194
- * customElements.define('x-foo', WC);
6195
- * const elm = document.createElement('x-foo');
6196
- * ```
6197
- */
6198
-
6199
- function deprecatedBuildCustomElementConstructor(Ctor) {
6200
-
6201
- return Ctor.CustomElementConstructor;
6202
- }
6203
-
6204
- function buildCustomElementConstructor(Ctor) {
6205
- const def = getComponentInternalDef(Ctor);
6206
- return class extends def.bridge {
6207
- constructor() {
6208
- super();
6209
- createVM(this, def, {
6210
- mode: 'open',
6211
- owner: null,
6212
- tagName: this.tagName,
6213
- renderer
6214
- });
6215
- }
6216
-
6217
- connectedCallback() {
6218
- connectRootElement(this);
6219
- }
6220
-
6221
- disconnectedCallback() {
6222
- disconnectRootElement(this);
6223
- }
6224
-
6225
- };
6226
- }
6227
6365
  /*
6228
6366
  * Copyright (c) 2018, salesforce.com, inc.
6229
6367
  * All rights reserved.
@@ -6233,7 +6371,6 @@
6233
6371
  // TODO [#2472]: Remove this workaround when appropriate.
6234
6372
  // eslint-disable-next-line lwc-internal/no-global-node
6235
6373
 
6236
-
6237
6374
  const _Node$1 = Node;
6238
6375
  const ConnectingSlot = new WeakMap();
6239
6376
  const DisconnectingSlot = new WeakMap();
@@ -6341,6 +6478,114 @@
6341
6478
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6342
6479
  */
6343
6480
 
6481
+
6482
+ function hydrateComponent(element, Ctor, props = {}) {
6483
+ if (!isFunction$1(Ctor)) {
6484
+ throw new TypeError(`"hydrateComponent" expects a valid component constructor as the second parameter but instead received ${Ctor}.`);
6485
+ }
6486
+
6487
+ if (!isObject(props) || isNull(props)) {
6488
+ throw new TypeError(`"hydrateComponent" expects an object as the third parameter but instead received ${props}.`);
6489
+ }
6490
+
6491
+ const def = getComponentInternalDef(Ctor);
6492
+
6493
+ try {
6494
+ // Let the renderer know we are hydrating, so it does not replace the existing shadowRoot
6495
+ // and uses the same algo to create the stylesheets as in SSR.
6496
+ setIsHydrating(true);
6497
+ createVM(element, def, {
6498
+ mode: 'open',
6499
+ owner: null,
6500
+ renderer,
6501
+ tagName: element.tagName.toLowerCase()
6502
+ });
6503
+
6504
+ for (const [key, value] of Object.entries(props)) {
6505
+ element[key] = value;
6506
+ }
6507
+
6508
+ hydrateRootElement(element); // set it back since now we finished hydration.
6509
+
6510
+ setIsHydrating(false);
6511
+ } catch (e) {
6512
+ // Fallback: In case there's an error while hydrating, let's log the error, and replace the element with
6513
+ // the client generated DOM.
6514
+
6515
+ /* eslint-disable-next-line no-console */
6516
+ console.error('Recovering from error while hydrating: ', e);
6517
+ setIsHydrating(false);
6518
+ const newElem = createElement(element.tagName, {
6519
+ is: Ctor,
6520
+ mode: 'open'
6521
+ });
6522
+
6523
+ for (const [key, value] of Object.entries(props)) {
6524
+ newElem[key] = value;
6525
+ }
6526
+
6527
+ element.parentNode.replaceChild(newElem, element);
6528
+ }
6529
+ }
6530
+ /*
6531
+ * Copyright (c) 2018, salesforce.com, inc.
6532
+ * All rights reserved.
6533
+ * SPDX-License-Identifier: MIT
6534
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6535
+ */
6536
+
6537
+ /**
6538
+ * This function builds a Web Component class from a LWC constructor so it can be
6539
+ * registered as a new element via customElements.define() at any given time.
6540
+ *
6541
+ * @deprecated since version 1.3.11
6542
+ *
6543
+ * @example
6544
+ * ```
6545
+ * import { buildCustomElementConstructor } from 'lwc';
6546
+ * import Foo from 'ns/foo';
6547
+ * const WC = buildCustomElementConstructor(Foo);
6548
+ * customElements.define('x-foo', WC);
6549
+ * const elm = document.createElement('x-foo');
6550
+ * ```
6551
+ */
6552
+
6553
+
6554
+ function deprecatedBuildCustomElementConstructor(Ctor) {
6555
+
6556
+ return Ctor.CustomElementConstructor;
6557
+ }
6558
+
6559
+ function buildCustomElementConstructor(Ctor) {
6560
+ const def = getComponentInternalDef(Ctor);
6561
+ return class extends def.bridge {
6562
+ constructor() {
6563
+ super();
6564
+ createVM(this, def, {
6565
+ mode: 'open',
6566
+ owner: null,
6567
+ tagName: this.tagName,
6568
+ renderer
6569
+ });
6570
+ }
6571
+
6572
+ connectedCallback() {
6573
+ connectRootElement(this);
6574
+ }
6575
+
6576
+ disconnectedCallback() {
6577
+ disconnectRootElement(this);
6578
+ }
6579
+
6580
+ };
6581
+ }
6582
+ /*
6583
+ * Copyright (c) 2018, salesforce.com, inc.
6584
+ * All rights reserved.
6585
+ * SPDX-License-Identifier: MIT
6586
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
6587
+ */
6588
+
6344
6589
  /**
6345
6590
  * EXPERIMENTAL: This function provides access to the component constructor, given an HTMLElement.
6346
6591
  * This API is subject to change or being removed.
@@ -6440,7 +6685,7 @@
6440
6685
  });
6441
6686
  freeze(LightningElement);
6442
6687
  seal(LightningElement.prototype);
6443
- /* version: 2.5.7 */
6688
+ /* version: 2.5.8 */
6444
6689
 
6445
6690
  exports.LightningElement = LightningElement;
6446
6691
  exports.__unstable__ProfilerControl = profilerControl;
@@ -6450,6 +6695,7 @@
6450
6695
  exports.createElement = createElement;
6451
6696
  exports.getComponentConstructor = getComponentConstructor;
6452
6697
  exports.getComponentDef = getComponentDef;
6698
+ exports.hydrateComponent = hydrateComponent;
6453
6699
  exports.isComponentConstructor = isComponentConstructor;
6454
6700
  exports.isNodeFromTemplate = isNodeFromTemplate;
6455
6701
  exports.readonly = readonly;