lwc 2.20.0 → 2.20.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.
Files changed (35) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +235 -202
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +235 -202
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +225 -192
  5. package/dist/engine-dom/iife/es5/engine-dom.js +320 -285
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +310 -274
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +235 -202
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +225 -192
  11. package/dist/engine-dom/umd/es5/engine-dom.js +320 -285
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +310 -274
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +177 -169
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +177 -169
  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 +7 -7
@@ -302,9 +302,9 @@ var LWC = (function (exports) {
302
302
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
303
303
  */
304
304
  // Increment whenever the LWC template compiler changes
305
- const LWC_VERSION = "2.20.0";
305
+ const LWC_VERSION = "2.20.3";
306
306
  const LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/;
307
- /** version: 2.20.0 */
307
+ /** version: 2.20.3 */
308
308
 
309
309
  /*
310
310
  * Copyright (c) 2018, salesforce.com, inc.
@@ -458,7 +458,7 @@ var LWC = (function (exports) {
458
458
  setFeatureFlag(name, value);
459
459
  }
460
460
  }
461
- /** version: 2.20.0 */
461
+ /** version: 2.20.3 */
462
462
 
463
463
  /*
464
464
  * Copyright (c) 2018, salesforce.com, inc.
@@ -3359,6 +3359,175 @@ var LWC = (function (exports) {
3359
3359
  };
3360
3360
  }
3361
3361
 
3362
+ /*
3363
+ * Copyright (c) 2018, salesforce.com, inc.
3364
+ * All rights reserved.
3365
+ * SPDX-License-Identifier: MIT
3366
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3367
+ */
3368
+ function makeHostToken(token) {
3369
+ return `${token}-host`;
3370
+ }
3371
+ function createInlineStyleVNode(content) {
3372
+ return api.h('style', {
3373
+ key: 'style',
3374
+ attrs: {
3375
+ type: 'text/css',
3376
+ },
3377
+ }, [api.t(content)]);
3378
+ }
3379
+ function updateStylesheetToken(vm, template) {
3380
+ const { elm, context, renderMode, shadowMode, renderer: { getClassList, removeAttribute, setAttribute }, } = vm;
3381
+ const { stylesheets: newStylesheets, stylesheetToken: newStylesheetToken } = template;
3382
+ const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
3383
+ const { hasScopedStyles } = context;
3384
+ let newToken;
3385
+ let newHasTokenInClass;
3386
+ let newHasTokenInAttribute;
3387
+ // Reset the styling token applied to the host element.
3388
+ const { stylesheetToken: oldToken, hasTokenInClass: oldHasTokenInClass, hasTokenInAttribute: oldHasTokenInAttribute, } = context;
3389
+ if (!isUndefined$1(oldToken)) {
3390
+ if (oldHasTokenInClass) {
3391
+ getClassList(elm).remove(makeHostToken(oldToken));
3392
+ }
3393
+ if (oldHasTokenInAttribute) {
3394
+ removeAttribute(elm, makeHostToken(oldToken));
3395
+ }
3396
+ }
3397
+ // Apply the new template styling token to the host element, if the new template has any
3398
+ // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
3399
+ if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
3400
+ newToken = newStylesheetToken;
3401
+ }
3402
+ // Set the new styling token on the host element
3403
+ if (!isUndefined$1(newToken)) {
3404
+ if (hasScopedStyles) {
3405
+ getClassList(elm).add(makeHostToken(newToken));
3406
+ newHasTokenInClass = true;
3407
+ }
3408
+ if (isSyntheticShadow) {
3409
+ setAttribute(elm, makeHostToken(newToken), '');
3410
+ newHasTokenInAttribute = true;
3411
+ }
3412
+ }
3413
+ // Update the styling tokens present on the context object.
3414
+ context.stylesheetToken = newToken;
3415
+ context.hasTokenInClass = newHasTokenInClass;
3416
+ context.hasTokenInAttribute = newHasTokenInAttribute;
3417
+ }
3418
+ function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
3419
+ const content = [];
3420
+ let root;
3421
+ for (let i = 0; i < stylesheets.length; i++) {
3422
+ let stylesheet = stylesheets[i];
3423
+ if (isArray$1(stylesheet)) {
3424
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
3425
+ }
3426
+ else {
3427
+ if (process.env.NODE_ENV !== 'production') {
3428
+ // Check for compiler version mismatch in dev mode only
3429
+ checkVersionMismatch(stylesheet, 'stylesheet');
3430
+ // in dev-mode, we support hot swapping of stylesheet, which means that
3431
+ // the component instance might be attempting to use an old version of
3432
+ // the stylesheet, while internally, we have a replacement for it.
3433
+ stylesheet = getStyleOrSwappedStyle(stylesheet);
3434
+ }
3435
+ const isScopedCss = stylesheet[KEY__SCOPED_CSS];
3436
+ // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
3437
+ const scopeToken = isScopedCss ||
3438
+ (vm.shadowMode === 1 /* ShadowMode.Synthetic */ && vm.renderMode === 1 /* RenderMode.Shadow */)
3439
+ ? stylesheetToken
3440
+ : undefined;
3441
+ // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
3442
+ // native shadow DOM. Synthetic shadow DOM never uses `:host`.
3443
+ const useActualHostSelector = vm.renderMode === 0 /* RenderMode.Light */
3444
+ ? !isScopedCss
3445
+ : vm.shadowMode === 0 /* ShadowMode.Native */;
3446
+ // Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
3447
+ // we use an attribute selector on the host to simulate :dir().
3448
+ let useNativeDirPseudoclass;
3449
+ if (vm.renderMode === 1 /* RenderMode.Shadow */) {
3450
+ useNativeDirPseudoclass = vm.shadowMode === 0 /* ShadowMode.Native */;
3451
+ }
3452
+ else {
3453
+ // Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
3454
+ // At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
3455
+ if (isUndefined$1(root)) {
3456
+ // Only calculate the root once as necessary
3457
+ root = getNearestShadowComponent(vm);
3458
+ }
3459
+ useNativeDirPseudoclass = isNull(root) || root.shadowMode === 0 /* ShadowMode.Native */;
3460
+ }
3461
+ ArrayPush$1.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
3462
+ }
3463
+ }
3464
+ return content;
3465
+ }
3466
+ function getStylesheetsContent(vm, template) {
3467
+ const { stylesheets, stylesheetToken } = template;
3468
+ let content = [];
3469
+ if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
3470
+ content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
3471
+ }
3472
+ return content;
3473
+ }
3474
+ // It might be worth caching this to avoid doing the lookup repeatedly, but
3475
+ // perf testing has not shown it to be a huge improvement yet:
3476
+ // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
3477
+ function getNearestShadowComponent(vm) {
3478
+ let owner = vm;
3479
+ while (!isNull(owner)) {
3480
+ if (owner.renderMode === 1 /* RenderMode.Shadow */) {
3481
+ return owner;
3482
+ }
3483
+ owner = owner.owner;
3484
+ }
3485
+ return owner;
3486
+ }
3487
+ /**
3488
+ * If the component that is currently being rendered uses scoped styles,
3489
+ * this returns the unique token for that scoped stylesheet. Otherwise
3490
+ * it returns null.
3491
+ */
3492
+ function getScopeTokenClass(owner) {
3493
+ const { cmpTemplate, context } = owner;
3494
+ return (context.hasScopedStyles && (cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken)) || null;
3495
+ }
3496
+ function getNearestNativeShadowComponent(vm) {
3497
+ const owner = getNearestShadowComponent(vm);
3498
+ if (!isNull(owner) && owner.shadowMode === 1 /* ShadowMode.Synthetic */) {
3499
+ // Synthetic-within-native is impossible. So if the nearest shadow component is
3500
+ // synthetic, we know we won't find a native component if we go any further.
3501
+ return null;
3502
+ }
3503
+ return owner;
3504
+ }
3505
+ function createStylesheet(vm, stylesheets) {
3506
+ const { renderMode, shadowMode, renderer: { ssr, insertStylesheet }, } = vm;
3507
+ if (renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */) {
3508
+ for (let i = 0; i < stylesheets.length; i++) {
3509
+ insertStylesheet(stylesheets[i]);
3510
+ }
3511
+ }
3512
+ else if (ssr || vm.hydrated) {
3513
+ // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
3514
+ // This works in the client, because the stylesheets are created, and cached in the VM
3515
+ // the first time the VM renders.
3516
+ // native shadow or light DOM, SSR
3517
+ return ArrayMap.call(stylesheets, createInlineStyleVNode);
3518
+ }
3519
+ else {
3520
+ // native shadow or light DOM, DOM renderer
3521
+ const root = getNearestNativeShadowComponent(vm);
3522
+ // null root means a global style
3523
+ const target = isNull(root) ? undefined : root.shadowRoot;
3524
+ for (let i = 0; i < stylesheets.length; i++) {
3525
+ insertStylesheet(stylesheets[i], target);
3526
+ }
3527
+ }
3528
+ return null;
3529
+ }
3530
+
3362
3531
  /*
3363
3532
  * Copyright (c) 2020, salesforce.com, inc.
3364
3533
  * All rights reserved.
@@ -3870,10 +4039,9 @@ var LWC = (function (exports) {
3870
4039
  }
3871
4040
  // Set the scope token class for *.scoped.css styles
3872
4041
  function setScopeTokenClassIfNecessary(elm, owner, renderer) {
3873
- const { cmpTemplate, context } = owner;
3874
- const { getClassList } = renderer;
3875
- const token = cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken;
3876
- if (!isUndefined$1(token) && context.hasScopedStyles) {
4042
+ const token = getScopeTokenClass(owner);
4043
+ if (!isNull(token)) {
4044
+ const { getClassList } = renderer;
3877
4045
  // TODO [#2762]: this dot notation with add is probably problematic
3878
4046
  // probably we should have a renderer api for just the add operation
3879
4047
  getClassList(elm).add(token);
@@ -4636,166 +4804,6 @@ var LWC = (function (exports) {
4636
4804
  shc,
4637
4805
  });
4638
4806
 
4639
- /*
4640
- * Copyright (c) 2018, salesforce.com, inc.
4641
- * All rights reserved.
4642
- * SPDX-License-Identifier: MIT
4643
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4644
- */
4645
- function makeHostToken(token) {
4646
- return `${token}-host`;
4647
- }
4648
- function createInlineStyleVNode(content) {
4649
- return api.h('style', {
4650
- key: 'style',
4651
- attrs: {
4652
- type: 'text/css',
4653
- },
4654
- }, [api.t(content)]);
4655
- }
4656
- function updateStylesheetToken(vm, template) {
4657
- const { elm, context, renderMode, shadowMode, renderer: { getClassList, removeAttribute, setAttribute }, } = vm;
4658
- const { stylesheets: newStylesheets, stylesheetToken: newStylesheetToken } = template;
4659
- const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
4660
- const { hasScopedStyles } = context;
4661
- let newToken;
4662
- let newHasTokenInClass;
4663
- let newHasTokenInAttribute;
4664
- // Reset the styling token applied to the host element.
4665
- const { stylesheetToken: oldToken, hasTokenInClass: oldHasTokenInClass, hasTokenInAttribute: oldHasTokenInAttribute, } = context;
4666
- if (!isUndefined$1(oldToken)) {
4667
- if (oldHasTokenInClass) {
4668
- getClassList(elm).remove(makeHostToken(oldToken));
4669
- }
4670
- if (oldHasTokenInAttribute) {
4671
- removeAttribute(elm, makeHostToken(oldToken));
4672
- }
4673
- }
4674
- // Apply the new template styling token to the host element, if the new template has any
4675
- // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
4676
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
4677
- newToken = newStylesheetToken;
4678
- }
4679
- // Set the new styling token on the host element
4680
- if (!isUndefined$1(newToken)) {
4681
- if (hasScopedStyles) {
4682
- getClassList(elm).add(makeHostToken(newToken));
4683
- newHasTokenInClass = true;
4684
- }
4685
- if (isSyntheticShadow) {
4686
- setAttribute(elm, makeHostToken(newToken), '');
4687
- newHasTokenInAttribute = true;
4688
- }
4689
- }
4690
- // Update the styling tokens present on the context object.
4691
- context.stylesheetToken = newToken;
4692
- context.hasTokenInClass = newHasTokenInClass;
4693
- context.hasTokenInAttribute = newHasTokenInAttribute;
4694
- }
4695
- function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
4696
- const content = [];
4697
- let root;
4698
- for (let i = 0; i < stylesheets.length; i++) {
4699
- let stylesheet = stylesheets[i];
4700
- if (isArray$1(stylesheet)) {
4701
- ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
4702
- }
4703
- else {
4704
- if (process.env.NODE_ENV !== 'production') {
4705
- // Check for compiler version mismatch in dev mode only
4706
- checkVersionMismatch(stylesheet, 'stylesheet');
4707
- // in dev-mode, we support hot swapping of stylesheet, which means that
4708
- // the component instance might be attempting to use an old version of
4709
- // the stylesheet, while internally, we have a replacement for it.
4710
- stylesheet = getStyleOrSwappedStyle(stylesheet);
4711
- }
4712
- const isScopedCss = stylesheet[KEY__SCOPED_CSS];
4713
- // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
4714
- const scopeToken = isScopedCss ||
4715
- (vm.shadowMode === 1 /* ShadowMode.Synthetic */ && vm.renderMode === 1 /* RenderMode.Shadow */)
4716
- ? stylesheetToken
4717
- : undefined;
4718
- // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
4719
- // native shadow DOM. Synthetic shadow DOM never uses `:host`.
4720
- const useActualHostSelector = vm.renderMode === 0 /* RenderMode.Light */
4721
- ? !isScopedCss
4722
- : vm.shadowMode === 0 /* ShadowMode.Native */;
4723
- // Use the native :dir() pseudoclass only in native shadow DOM. Otherwise, in synthetic shadow,
4724
- // we use an attribute selector on the host to simulate :dir().
4725
- let useNativeDirPseudoclass;
4726
- if (vm.renderMode === 1 /* RenderMode.Shadow */) {
4727
- useNativeDirPseudoclass = vm.shadowMode === 0 /* ShadowMode.Native */;
4728
- }
4729
- else {
4730
- // Light DOM components should only render `[dir]` if they're inside of a synthetic shadow root.
4731
- // At the top level (root is null) or inside of a native shadow root, they should use `:dir()`.
4732
- if (isUndefined$1(root)) {
4733
- // Only calculate the root once as necessary
4734
- root = getNearestShadowComponent(vm);
4735
- }
4736
- useNativeDirPseudoclass = isNull(root) || root.shadowMode === 0 /* ShadowMode.Native */;
4737
- }
4738
- ArrayPush$1.call(content, stylesheet(scopeToken, useActualHostSelector, useNativeDirPseudoclass));
4739
- }
4740
- }
4741
- return content;
4742
- }
4743
- function getStylesheetsContent(vm, template) {
4744
- const { stylesheets, stylesheetToken } = template;
4745
- let content = [];
4746
- if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
4747
- content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
4748
- }
4749
- return content;
4750
- }
4751
- // It might be worth caching this to avoid doing the lookup repeatedly, but
4752
- // perf testing has not shown it to be a huge improvement yet:
4753
- // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
4754
- function getNearestShadowComponent(vm) {
4755
- let owner = vm;
4756
- while (!isNull(owner)) {
4757
- if (owner.renderMode === 1 /* RenderMode.Shadow */) {
4758
- return owner;
4759
- }
4760
- owner = owner.owner;
4761
- }
4762
- return owner;
4763
- }
4764
- function getNearestNativeShadowComponent(vm) {
4765
- const owner = getNearestShadowComponent(vm);
4766
- if (!isNull(owner) && owner.shadowMode === 1 /* ShadowMode.Synthetic */) {
4767
- // Synthetic-within-native is impossible. So if the nearest shadow component is
4768
- // synthetic, we know we won't find a native component if we go any further.
4769
- return null;
4770
- }
4771
- return owner;
4772
- }
4773
- function createStylesheet(vm, stylesheets) {
4774
- const { renderMode, shadowMode, renderer: { ssr, insertStylesheet }, } = vm;
4775
- if (renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */) {
4776
- for (let i = 0; i < stylesheets.length; i++) {
4777
- insertStylesheet(stylesheets[i]);
4778
- }
4779
- }
4780
- else if (ssr || vm.hydrated) {
4781
- // Note: We need to ensure that during hydration, the stylesheets method is the same as those in ssr.
4782
- // This works in the client, because the stylesheets are created, and cached in the VM
4783
- // the first time the VM renders.
4784
- // native shadow or light DOM, SSR
4785
- return ArrayMap.call(stylesheets, createInlineStyleVNode);
4786
- }
4787
- else {
4788
- // native shadow or light DOM, DOM renderer
4789
- const root = getNearestNativeShadowComponent(vm);
4790
- // null root means a global style
4791
- const target = isNull(root) ? undefined : root.shadowRoot;
4792
- for (let i = 0; i < stylesheets.length; i++) {
4793
- insertStylesheet(stylesheets[i], target);
4794
- }
4795
- }
4796
- return null;
4797
- }
4798
-
4799
4807
  /*
4800
4808
  * Copyright (c) 2018, salesforce.com, inc.
4801
4809
  * All rights reserved.
@@ -6573,8 +6581,24 @@ var LWC = (function (exports) {
6573
6581
  return nodesAreCompatible;
6574
6582
  }
6575
6583
  function validateClassAttr(vnode, elm, renderer) {
6576
- const { data: { className, classMap }, } = vnode;
6584
+ const { data, owner } = vnode;
6585
+ let { className, classMap } = data;
6577
6586
  const { getProperty, getClassList } = renderer;
6587
+ const scopedToken = getScopeTokenClass(owner);
6588
+ // Classnames for scoped CSS are added directly to the DOM during rendering,
6589
+ // or to the VDOM on the server in the case of SSR. As such, these classnames
6590
+ // are never present in VDOM nodes in the browser.
6591
+ //
6592
+ // Consequently, hydration mismatches will occur if scoped CSS token classnames
6593
+ // are rendered during SSR. This needs to be accounted for when validating.
6594
+ if (scopedToken) {
6595
+ if (!isUndefined$1(className)) {
6596
+ className = `${scopedToken} ${className}`;
6597
+ }
6598
+ else if (!isUndefined$1(classMap)) {
6599
+ classMap = Object.assign(Object.assign({}, classMap), { [scopedToken]: true });
6600
+ }
6601
+ }
6578
6602
  let nodesAreCompatible = true;
6579
6603
  let vnodeClassName;
6580
6604
  if (!isUndefined$1(className) && String(className) !== getProperty(elm, 'className')) {
@@ -6814,7 +6838,7 @@ var LWC = (function (exports) {
6814
6838
  }
6815
6839
  return ctor;
6816
6840
  }
6817
- /* version: 2.20.0 */
6841
+ /* version: 2.20.3 */
6818
6842
 
6819
6843
  /*
6820
6844
  * Copyright (c) 2018, salesforce.com, inc.
@@ -6847,9 +6871,6 @@ var LWC = (function (exports) {
6847
6871
  stylesheetCache.clear();
6848
6872
  };
6849
6873
  }
6850
- function isDocument(target) {
6851
- return !isUndefined$1(target.head);
6852
- }
6853
6874
  function createFreshStyleElement(content) {
6854
6875
  const elm = document.createElement('style');
6855
6876
  elm.type = 'text/css';
@@ -6857,10 +6878,10 @@ var LWC = (function (exports) {
6857
6878
  return elm;
6858
6879
  }
6859
6880
  function createStyleElement(content, cacheData) {
6860
- const { stylesheet, used } = cacheData;
6881
+ const { element, usedElement } = cacheData;
6861
6882
  // If the <style> was already used, then we should clone it. We cannot insert
6862
6883
  // the same <style> in two places in the DOM.
6863
- if (used) {
6884
+ if (usedElement) {
6864
6885
  // For a mysterious reason, IE11 doesn't like the way we clone <style> nodes
6865
6886
  // and will render the incorrect styles if we do things that way. It's just
6866
6887
  // a perf optimization, so we can skip it for IE11.
@@ -6869,11 +6890,11 @@ var LWC = (function (exports) {
6869
6890
  }
6870
6891
  // This `<style>` may be repeated multiple times in the DOM, so cache it. It's a bit
6871
6892
  // faster to call `cloneNode()` on an existing node than to recreate it every time.
6872
- return stylesheet.cloneNode(true);
6893
+ return element.cloneNode(true);
6873
6894
  }
6874
6895
  // We don't clone every time, because that would be a perf tax on the first time
6875
- cacheData.used = true;
6876
- return stylesheet;
6896
+ cacheData.usedElement = true;
6897
+ return element;
6877
6898
  }
6878
6899
  function createConstructableStylesheet(content) {
6879
6900
  const stylesheet = new CSSStyleSheet();
@@ -6894,47 +6915,42 @@ var LWC = (function (exports) {
6894
6915
  }
6895
6916
  function insertStyleElement(content, target, cacheData) {
6896
6917
  const elm = createStyleElement(content, cacheData);
6897
- const targetAnchorPoint = isDocument(target) ? target.head : target;
6898
- targetAnchorPoint.appendChild(elm);
6899
- }
6900
- function doInsertStylesheet(content, target, cacheData) {
6901
- // Constructable stylesheets are only supported in certain browsers:
6902
- // https://caniuse.com/mdn-api_document_adoptedstylesheets
6903
- // The reason we use it is for perf: https://github.com/salesforce/lwc/pull/2460
6904
- if (supportsConstructableStylesheets) {
6905
- insertConstructableStylesheet(content, target, cacheData);
6906
- }
6907
- else {
6908
- // Fall back to <style> element
6909
- insertStyleElement(content, target, cacheData);
6910
- }
6918
+ target.appendChild(elm);
6911
6919
  }
6912
- function getCacheData(content) {
6920
+ function getCacheData(content, useConstructableStylesheet) {
6913
6921
  let cacheData = stylesheetCache.get(content);
6914
6922
  if (isUndefined$1(cacheData)) {
6915
6923
  cacheData = {
6916
- stylesheet: supportsConstructableStylesheets
6917
- ? createConstructableStylesheet(content)
6918
- : createFreshStyleElement(content),
6924
+ stylesheet: undefined,
6925
+ element: undefined,
6919
6926
  roots: undefined,
6920
6927
  global: false,
6921
- used: false,
6928
+ usedElement: false,
6922
6929
  };
6923
6930
  stylesheetCache.set(content, cacheData);
6924
6931
  }
6932
+ // Create <style> elements or CSSStyleSheets on-demand, as needed
6933
+ if (useConstructableStylesheet && isUndefined$1(cacheData.stylesheet)) {
6934
+ cacheData.stylesheet = createConstructableStylesheet(content);
6935
+ }
6936
+ else if (!useConstructableStylesheet && isUndefined$1(cacheData.element)) {
6937
+ cacheData.element = createFreshStyleElement(content);
6938
+ }
6925
6939
  return cacheData;
6926
6940
  }
6927
6941
  function insertGlobalStylesheet(content) {
6928
- const cacheData = getCacheData(content);
6942
+ // Force a <style> element for global stylesheets. See comment below.
6943
+ const cacheData = getCacheData(content, false);
6929
6944
  if (cacheData.global) {
6930
6945
  // already inserted
6931
6946
  return;
6932
6947
  }
6933
6948
  cacheData.global = true; // mark inserted
6934
- doInsertStylesheet(content, document, cacheData);
6949
+ // TODO [#2922]: use document.adoptedStyleSheets in supported browsers. Currently we can't, due to backwards compat.
6950
+ insertStyleElement(content, document.head, cacheData);
6935
6951
  }
6936
6952
  function insertLocalStylesheet(content, target) {
6937
- const cacheData = getCacheData(content);
6953
+ const cacheData = getCacheData(content, supportsConstructableStylesheets);
6938
6954
  let { roots } = cacheData;
6939
6955
  if (isUndefined$1(roots)) {
6940
6956
  roots = cacheData.roots = new WeakSet(); // lazily initialize (not needed for global styles)
@@ -6944,7 +6960,16 @@ var LWC = (function (exports) {
6944
6960
  return;
6945
6961
  }
6946
6962
  roots.add(target); // mark inserted
6947
- doInsertStylesheet(content, target, cacheData);
6963
+ // Constructable stylesheets are only supported in certain browsers:
6964
+ // https://caniuse.com/mdn-api_document_adoptedstylesheets
6965
+ // The reason we use it is for perf: https://github.com/salesforce/lwc/pull/2460
6966
+ if (supportsConstructableStylesheets) {
6967
+ insertConstructableStylesheet(content, target, cacheData);
6968
+ }
6969
+ else {
6970
+ // Fall back to <style> element
6971
+ insertStyleElement(content, target, cacheData);
6972
+ }
6948
6973
  }
6949
6974
  function insertStylesheet(content, target) {
6950
6975
  if (isUndefined$1(target)) {
@@ -7059,7 +7084,15 @@ var LWC = (function (exports) {
7059
7084
  return node.nextSibling;
7060
7085
  }
7061
7086
  function attachShadow(element, options) {
7062
- if (hydrating) {
7087
+ // `hydrating` will be true in two cases:
7088
+ // 1. upon initial load with an SSR-generated DOM, while in Shadow render mode
7089
+ // 2. when a webapp author places <c-app> in their static HTML and mounts their
7090
+ // root component with customeElement.define('c-app', Ctor)
7091
+ //
7092
+ // The second case can be treated as a failed hydration with nominal impact
7093
+ // to performance. However, because <c-app> won't have a <template shadowroot>
7094
+ // declarative child, `element.shadowRoot` is `null`.
7095
+ if (hydrating && element.shadowRoot) {
7063
7096
  return element.shadowRoot;
7064
7097
  }
7065
7098
  return element.attachShadow(options);
@@ -7493,7 +7526,7 @@ var LWC = (function (exports) {
7493
7526
  });
7494
7527
  freeze(LightningElement);
7495
7528
  seal(LightningElement.prototype);
7496
- /* version: 2.20.0 */
7529
+ /* version: 2.20.3 */
7497
7530
 
7498
7531
  exports.LightningElement = LightningElement;
7499
7532
  exports.__unstable__ProfilerControl = profilerControl;