lwc 2.3.3 → 2.5.0

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 (41) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +360 -198
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +360 -198
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +2 -2
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +361 -168
  5. package/dist/engine-dom/iife/es5/engine-dom.js +371 -218
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +2 -2
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +370 -186
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +360 -198
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +2 -2
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +361 -168
  11. package/dist/engine-dom/umd/es5/engine-dom.js +371 -218
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +2 -2
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +370 -186
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +304 -205
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +2 -2
  16. package/dist/engine-server/esm/es2017/engine-server.js +304 -205
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +29 -16
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +29 -16
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js +2 -2
  20. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +29 -16
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +31 -16
  22. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.min.js +2 -2
  23. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +31 -16
  24. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +29 -16
  25. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js +2 -2
  26. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +29 -16
  27. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +31 -16
  28. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.min.js +2 -2
  29. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +31 -16
  30. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  31. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/iife/es5/wire-service.js +3 -3
  34. package/dist/wire-service/iife/es5/wire-service.min.js +1 -1
  35. package/dist/wire-service/iife/es5/wire-service_debug.js +3 -3
  36. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  37. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  38. package/dist/wire-service/umd/es5/wire-service.js +3 -3
  39. package/dist/wire-service/umd/es5/wire-service.min.js +1 -1
  40. package/dist/wire-service/umd/es5/wire-service_debug.js +3 -3
  41. package/package.json +8 -8
@@ -107,6 +107,10 @@ var LWC = (function (exports) {
107
107
  return obj === false;
108
108
  }
109
109
 
110
+ function isBoolean(obj) {
111
+ return typeof obj === 'boolean';
112
+ }
113
+
110
114
  function isFunction$1(obj) {
111
115
  return typeof obj === 'function';
112
116
  }
@@ -249,6 +253,7 @@ var LWC = (function (exports) {
249
253
  const KEY__SHADOW_RESOLVER = '$shadowResolver$';
250
254
  const KEY__SHADOW_TOKEN = '$shadowToken$';
251
255
  const KEY__SYNTHETIC_MODE = '$$lwc-synthetic-mode';
256
+ const KEY__SCOPED_CSS = '$scoped$';
252
257
  /**
253
258
  * Map composed of properties to attributes not following the HTML property to attribute mapping
254
259
  * convention.
@@ -297,7 +302,7 @@ var LWC = (function (exports) {
297
302
  CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName);
298
303
  return attributeName;
299
304
  }
300
- /** version: 2.3.3 */
305
+ /** version: 2.5.0 */
301
306
 
302
307
  /*
303
308
  * Copyright (c) 2018, salesforce.com, inc.
@@ -402,19 +407,33 @@ var LWC = (function (exports) {
402
407
  */
403
408
 
404
409
 
410
+ const features = {
411
+ ENABLE_REACTIVE_SETTER: null,
412
+ ENABLE_HMR: null,
413
+ ENABLE_INNER_OUTER_TEXT_PATCH: null,
414
+ ENABLE_ELEMENT_PATCH: null,
415
+ ENABLE_NODE_LIST_PATCH: null,
416
+ ENABLE_HTML_COLLECTIONS_PATCH: null,
417
+ ENABLE_NODE_PATCH: null,
418
+ ENABLE_NON_COMPOSED_EVENTS_LEAKAGE: null,
419
+ ENABLE_MIXED_SHADOW_MODE: null,
420
+ ENABLE_WIRE_SYNC_EMIT: null
421
+ };
422
+
405
423
  if (!_globalThis.lwcRuntimeFlags) {
406
424
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', {
407
425
  value: create(null)
408
426
  });
409
427
  }
410
428
 
411
- const runtimeFlags = _globalThis.lwcRuntimeFlags; // This function is not supported for use within components and is meant for
412
- // configuring runtime feature flags during app initialization.
429
+ const runtimeFlags = _globalThis.lwcRuntimeFlags;
430
+ /**
431
+ * Set the value at runtime of a given feature flag. This method only be invoked once per feature
432
+ * flag. It is meant to be used during the app initialization.
433
+ */
413
434
 
414
435
  function setFeatureFlag(name, value) {
415
- const isBoolean = isTrue(value) || isFalse(value);
416
-
417
- if (!isBoolean) {
436
+ if (!isBoolean(value)) {
418
437
  const message = `Failed to set the value "${value}" for the runtime feature flag "${name}". Runtime feature flags can only be set to a boolean value.`;
419
438
 
420
439
  if (process.env.NODE_ENV !== 'production') {
@@ -426,9 +445,10 @@ var LWC = (function (exports) {
426
445
  }
427
446
  }
428
447
 
429
- if (isUndefined$1(featureFlagLookup[name])) {
430
- // eslint-disable-next-line no-console
431
- console.warn(`Failed to set the value "${value}" for the runtime feature flag "${name}" because it is undefined. Possible reasons are that 1) it was misspelled or 2) it was removed from the @lwc/features package.`);
448
+ if (isUndefined$1(features[name])) {
449
+ const availableFlags = keys(features).map(name => `"${name}"`).join(', '); // eslint-disable-next-line no-console
450
+
451
+ console.warn(`Failed to set the value "${value}" for the runtime feature flag "${name}" because it is undefined. Available flags: ${availableFlags}.`);
432
452
  return;
433
453
  }
434
454
 
@@ -445,37 +465,23 @@ var LWC = (function (exports) {
445
465
  return;
446
466
  }
447
467
 
448
- Object.defineProperty(runtimeFlags, name, {
468
+ defineProperty(runtimeFlags, name, {
449
469
  value
450
470
  });
451
471
  }
452
- } // This function is exposed to components to facilitate testing so we add a
453
- // check to make sure it is not invoked in production.
472
+ }
473
+ /**
474
+ * Set the value at runtime of a given feature flag. This method should only be used for testing
475
+ * purposes. It is a no-op when invoked in production mode.
476
+ */
454
477
 
455
478
 
456
479
  function setFeatureFlagForTest(name, value) {
457
480
  if (process.env.NODE_ENV !== 'production') {
458
- return setFeatureFlag(name, value);
481
+ setFeatureFlag(name, value);
459
482
  }
460
483
  }
461
-
462
- const featureFlagLookup = {
463
- ENABLE_REACTIVE_SETTER: null,
464
- ENABLE_HMR: null,
465
- // Flag to toggle on/off the enforcement of innerText/outerText shadow dom semantic in elements when using synthetic shadow.
466
- // Note: Once active, elements outside the lwc boundary are controlled by the ENABLE_ELEMENT_PATCH flag.
467
- ENABLE_INNER_OUTER_TEXT_PATCH: null,
468
- // Flags to toggle on/off the enforcement of shadow dom semantic in element/node outside lwc boundary when using synthetic shadow.
469
- ENABLE_ELEMENT_PATCH: null,
470
- ENABLE_NODE_LIST_PATCH: null,
471
- ENABLE_HTML_COLLECTIONS_PATCH: null,
472
- ENABLE_NODE_PATCH: null,
473
- // Disables the fix for #2121 where non-composed events are visible outside of their shadow root.
474
- ENABLE_NON_COMPOSED_EVENTS_LEAKAGE: null,
475
- ENABLE_LIGHT_DOM_COMPONENTS: null,
476
- ENABLE_MIXED_SHADOW_MODE: null
477
- };
478
- /** version: 2.3.3 */
484
+ /** version: 2.5.0 */
479
485
 
480
486
  /* proxy-compat-disable */
481
487
 
@@ -486,6 +492,7 @@ var LWC = (function (exports) {
486
492
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
487
493
  */
488
494
 
495
+
489
496
  let nextTickCallbackQueue = [];
490
497
  const SPACE_CHAR = 32;
491
498
  const EmptyObject = seal(create(null));
@@ -2806,12 +2813,6 @@ var LWC = (function (exports) {
2806
2813
  associateVM(component, vm);
2807
2814
  associateVM(elm, vm);
2808
2815
 
2809
- if (!runtimeFlags.ENABLE_LIGHT_DOM_COMPONENTS) {
2810
- assert.isTrue(def.renderMode !== 0
2811
- /* Light */
2812
- , `${def.name || 'Anonymous class'} is an invalid LWC component. Light DOM components are not available in this environment.`);
2813
- }
2814
-
2815
2816
  if (vm.renderMode === 1
2816
2817
  /* Shadow */
2817
2818
  ) {
@@ -2850,6 +2851,12 @@ var LWC = (function (exports) {
2850
2851
  if (process.env.NODE_ENV !== 'production') {
2851
2852
  patchShadowRootWithRestrictions(cmpRoot);
2852
2853
  }
2854
+ }
2855
+
2856
+ function warnIfInvokedDuringConstruction(vm, methodName) {
2857
+ if (isBeingConstructed(vm)) {
2858
+ logError(`this.${methodName}() should not be called during the construction of the custom element for ${getComponentTag(vm)} because the element is not yet in the DOM or has no children yet.`);
2859
+ }
2853
2860
  } // @ts-ignore
2854
2861
 
2855
2862
 
@@ -3008,7 +3015,7 @@ var LWC = (function (exports) {
3008
3015
  } = vm;
3009
3016
 
3010
3017
  if (process.env.NODE_ENV !== 'production') {
3011
- assert.isFalse(isBeingConstructed(vm), `this.getBoundingClientRect() should not be called during the construction of the custom element for ${getComponentTag(vm)} because the element is not yet in the DOM, instead, you can use it in one of the available life-cycle hooks.`);
3018
+ warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect');
3012
3019
  }
3013
3020
 
3014
3021
  return getBoundingClientRect(elm);
@@ -3024,7 +3031,7 @@ var LWC = (function (exports) {
3024
3031
  } = vm;
3025
3032
 
3026
3033
  if (process.env.NODE_ENV !== 'production') {
3027
- assert.isFalse(isBeingConstructed(vm), `this.querySelector() cannot be called during the construction of the custom element for ${getComponentTag(vm)} because no children has been added to this element yet.`);
3034
+ warnIfInvokedDuringConstruction(vm, 'querySelector');
3028
3035
  }
3029
3036
 
3030
3037
  return querySelector(elm, selectors);
@@ -3040,7 +3047,7 @@ var LWC = (function (exports) {
3040
3047
  } = vm;
3041
3048
 
3042
3049
  if (process.env.NODE_ENV !== 'production') {
3043
- assert.isFalse(isBeingConstructed(vm), `this.querySelectorAll() cannot be called during the construction of the custom element for ${getComponentTag(vm)} because no children has been added to this element yet.`);
3050
+ warnIfInvokedDuringConstruction(vm, 'querySelectorAll');
3044
3051
  }
3045
3052
 
3046
3053
  return querySelectorAll(elm, selectors);
@@ -3056,7 +3063,7 @@ var LWC = (function (exports) {
3056
3063
  } = vm;
3057
3064
 
3058
3065
  if (process.env.NODE_ENV !== 'production') {
3059
- assert.isFalse(isBeingConstructed(vm), `this.getElementsByTagName() cannot be called during the construction of the custom element for ${getComponentTag(vm)} because no children has been added to this element yet.`);
3066
+ warnIfInvokedDuringConstruction(vm, 'getElementsByTagName');
3060
3067
  }
3061
3068
 
3062
3069
  return getElementsByTagName(elm, tagNameOrWildCard);
@@ -3072,7 +3079,7 @@ var LWC = (function (exports) {
3072
3079
  } = vm;
3073
3080
 
3074
3081
  if (process.env.NODE_ENV !== 'production') {
3075
- assert.isFalse(isBeingConstructed(vm), `this.getElementsByClassName() cannot be called during the construction of the custom element for ${getComponentTag(vm)} because no children has been added to this element yet.`);
3082
+ warnIfInvokedDuringConstruction(vm, 'getElementsByClassName');
3076
3083
  }
3077
3084
 
3078
3085
  return getElementsByClassName(elm, names);
@@ -4482,6 +4489,19 @@ var LWC = (function (exports) {
4482
4489
 
4483
4490
  function setElementShadowToken(elm, token) {
4484
4491
  elm.$shadowToken$ = token;
4492
+ } // Set the scope token class for *.scoped.css styles
4493
+
4494
+
4495
+ function setScopeTokenClassIfNecessary(elm, owner) {
4496
+ const {
4497
+ cmpTemplate,
4498
+ context
4499
+ } = owner;
4500
+ const token = cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken;
4501
+
4502
+ if (!isUndefined$1(token) && context.hasScopedStyles) {
4503
+ owner.renderer.getClassList(elm).add(token);
4504
+ }
4485
4505
  }
4486
4506
 
4487
4507
  function updateNodeHook(oldVnode, vnode) {
@@ -4555,6 +4575,7 @@ var LWC = (function (exports) {
4555
4575
  const {
4556
4576
  owner
4557
4577
  } = vnode;
4578
+ setScopeTokenClassIfNecessary(elm, owner);
4558
4579
 
4559
4580
  if (owner.shadowMode === 1
4560
4581
  /* Synthetic */
@@ -4565,7 +4586,7 @@ var LWC = (function (exports) {
4565
4586
  }
4566
4587
  } = vnode;
4567
4588
  const {
4568
- shadowAttribute
4589
+ stylesheetToken
4569
4590
  } = owner.context;
4570
4591
 
4571
4592
  if (!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
@@ -4577,7 +4598,7 @@ var LWC = (function (exports) {
4577
4598
  // into each element from the template, so they can be styled accordingly.
4578
4599
 
4579
4600
 
4580
- setElementShadowToken(elm, shadowAttribute);
4601
+ setElementShadowToken(elm, stylesheetToken);
4581
4602
  }
4582
4603
 
4583
4604
  if (process.env.NODE_ENV !== 'production') {
@@ -4666,16 +4687,17 @@ var LWC = (function (exports) {
4666
4687
  ctor,
4667
4688
  owner
4668
4689
  } = vnode;
4690
+ setScopeTokenClassIfNecessary(elm, owner);
4669
4691
 
4670
4692
  if (owner.shadowMode === 1
4671
4693
  /* Synthetic */
4672
4694
  ) {
4673
4695
  const {
4674
- shadowAttribute
4696
+ stylesheetToken
4675
4697
  } = owner.context; // when running in synthetic shadow mode, we need to set the shadowToken value
4676
4698
  // into each element from the template, so they can be styled accordingly.
4677
4699
 
4678
- setElementShadowToken(elm, shadowAttribute);
4700
+ setElementShadowToken(elm, stylesheetToken);
4679
4701
  }
4680
4702
 
4681
4703
  const def = getComponentInternalDef(ctor);
@@ -4975,13 +4997,19 @@ var LWC = (function (exports) {
4975
4997
 
4976
4998
  function linkNodeToShadow(elm, owner) {
4977
4999
  const {
5000
+ renderer,
5001
+ renderMode,
4978
5002
  shadowMode
4979
5003
  } = owner; // TODO [#1164]: this should eventually be done by the polyfill directly
4980
5004
 
4981
- if (shadowMode === 1
4982
- /* Synthetic */
4983
- ) {
4984
- elm[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
5005
+ if (renderer.isSyntheticShadowDefined) {
5006
+ if (shadowMode === 1
5007
+ /* Synthetic */
5008
+ || renderMode === 0
5009
+ /* Light */
5010
+ ) {
5011
+ elm[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
5012
+ }
4985
5013
  }
4986
5014
  }
4987
5015
 
@@ -5327,14 +5355,11 @@ var LWC = (function (exports) {
5327
5355
 
5328
5356
  const {
5329
5357
  idx,
5330
- renderMode,
5331
5358
  shadowMode
5332
5359
  } = vmBeingRendered;
5333
5360
 
5334
5361
  if (shadowMode === 1
5335
5362
  /* Synthetic */
5336
- && renderMode === 1
5337
- /* Shadow */
5338
5363
  ) {
5339
5364
  return StringReplace.call(id, /\S+/g, id => `${id}-${idx}`);
5340
5365
  }
@@ -5363,14 +5388,11 @@ var LWC = (function (exports) {
5363
5388
 
5364
5389
  const {
5365
5390
  idx,
5366
- renderMode,
5367
5391
  shadowMode
5368
5392
  } = vmBeingRendered; // Apply transformation only for fragment-only-urls, and only in shadow DOM
5369
5393
 
5370
5394
  if (shadowMode === 1
5371
5395
  /* Synthetic */
5372
- && renderMode === 1
5373
- /* Shadow */
5374
5396
  && /^#/.test(url)) {
5375
5397
  return `${url}-${idx}`;
5376
5398
  }
@@ -5471,6 +5493,10 @@ var LWC = (function (exports) {
5471
5493
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5472
5494
  */
5473
5495
 
5496
+ function makeHostToken(token) {
5497
+ return `${token}-host`;
5498
+ }
5499
+
5474
5500
  function createInlineStyleVNode(content) {
5475
5501
  return h('style', {
5476
5502
  key: 'style',
@@ -5480,59 +5506,100 @@ var LWC = (function (exports) {
5480
5506
  }, [t(content)]);
5481
5507
  }
5482
5508
 
5483
- function updateSyntheticShadowAttributes(vm, template) {
5509
+ function updateStylesheetToken(vm, template) {
5484
5510
  const {
5485
5511
  elm,
5486
5512
  context,
5487
5513
  renderer,
5488
- renderMode
5514
+ renderMode,
5515
+ shadowMode
5489
5516
  } = vm;
5490
5517
  const {
5491
5518
  stylesheets: newStylesheets,
5492
- stylesheetTokens: newStylesheetTokens
5519
+ stylesheetToken: newStylesheetToken
5493
5520
  } = template;
5494
- let newTokens; // Reset the styling token applied to the host element.
5521
+ const isSyntheticShadow = renderMode === 1
5522
+ /* Shadow */
5523
+ && shadowMode === 1
5524
+ /* Synthetic */
5525
+ ;
5526
+ const {
5527
+ hasScopedStyles
5528
+ } = context;
5529
+ let newToken;
5530
+ let newHasTokenInClass;
5531
+ let newHasTokenInAttribute; // Reset the styling token applied to the host element.
5532
+
5533
+ const {
5534
+ stylesheetToken: oldToken,
5535
+ hasTokenInClass: oldHasTokenInClass,
5536
+ hasTokenInAttribute: oldHasTokenInAttribute
5537
+ } = context;
5495
5538
 
5496
- const oldHostAttribute = context.hostAttribute;
5539
+ if (oldHasTokenInClass) {
5540
+ renderer.getClassList(elm).remove(makeHostToken(oldToken));
5541
+ }
5497
5542
 
5498
- if (!isUndefined$1(oldHostAttribute)) {
5499
- renderer.removeAttribute(elm, oldHostAttribute);
5543
+ if (oldHasTokenInAttribute) {
5544
+ renderer.removeAttribute(elm, makeHostToken(oldToken));
5500
5545
  } // Apply the new template styling token to the host element, if the new template has any
5501
- // associated stylesheets.
5546
+ // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
5502
5547
 
5503
5548
 
5504
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0 && renderMode === 1
5505
- /* Shadow */
5506
- ) {
5507
- newTokens = newStylesheetTokens;
5508
- }
5549
+ if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
5550
+ newToken = newStylesheetToken;
5551
+ } // Set the new styling token on the host element
5552
+
5509
5553
 
5510
- if (!isUndefined$1(newTokens)) {
5511
- renderer.setAttribute(elm, newTokens.hostAttribute, '');
5554
+ if (!isUndefined$1(newToken)) {
5555
+ if (hasScopedStyles) {
5556
+ renderer.getClassList(elm).add(makeHostToken(newToken));
5557
+ newHasTokenInClass = true;
5558
+ }
5559
+
5560
+ if (isSyntheticShadow) {
5561
+ renderer.setAttribute(elm, makeHostToken(newToken), '');
5562
+ newHasTokenInAttribute = true;
5563
+ }
5512
5564
  } // Update the styling tokens present on the context object.
5513
5565
 
5514
5566
 
5515
- context.hostAttribute = newTokens === null || newTokens === void 0 ? void 0 : newTokens.hostAttribute;
5516
- context.shadowAttribute = newTokens === null || newTokens === void 0 ? void 0 : newTokens.shadowAttribute;
5567
+ context.stylesheetToken = newToken;
5568
+ context.hasTokenInClass = newHasTokenInClass;
5569
+ context.hasTokenInAttribute = newHasTokenInAttribute;
5517
5570
  }
5518
5571
 
5519
- function evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, nativeShadow) {
5572
+ function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
5520
5573
  const content = [];
5521
5574
 
5522
5575
  for (let i = 0; i < stylesheets.length; i++) {
5523
5576
  let stylesheet = stylesheets[i];
5524
5577
 
5525
5578
  if (isArray$1(stylesheet)) {
5526
- ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, hostSelector, shadowSelector, nativeShadow));
5579
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
5527
5580
  } else {
5528
5581
  if (process.env.NODE_ENV !== 'production') {
5529
5582
  // in dev-mode, we support hot swapping of stylesheet, which means that
5530
5583
  // the component instance might be attempting to use an old version of
5531
5584
  // the stylesheet, while internally, we have a replacement for it.
5532
5585
  stylesheet = getStyleOrSwappedStyle(stylesheet);
5533
- }
5586
+ } // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
5587
+ // native shadow DOM. Synthetic shadow DOM never uses `:host`.
5588
+
5589
+
5590
+ const isScopedCss = stylesheet[KEY__SCOPED_CSS];
5591
+ const useActualHostSelector = vm.renderMode === 0
5592
+ /* Light */
5593
+ ? !isScopedCss : vm.shadowMode === 0
5594
+ /* Native */
5595
+ ; // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
5534
5596
 
5535
- ArrayPush$1.call(content, stylesheet(hostSelector, shadowSelector, nativeShadow));
5597
+ const scopeToken = isScopedCss || vm.shadowMode === 1
5598
+ /* Synthetic */
5599
+ && vm.renderMode === 1
5600
+ /* Shadow */
5601
+ ? stylesheetToken : undefined;
5602
+ ArrayPush$1.call(content, stylesheet(useActualHostSelector, scopeToken));
5536
5603
  }
5537
5604
  }
5538
5605
 
@@ -5542,37 +5609,36 @@ var LWC = (function (exports) {
5542
5609
  function getStylesheetsContent(vm, template) {
5543
5610
  const {
5544
5611
  stylesheets,
5545
- stylesheetTokens
5612
+ stylesheetToken
5546
5613
  } = template;
5547
- const {
5548
- renderMode,
5549
- shadowMode
5550
- } = vm;
5551
5614
  let content = [];
5552
5615
 
5553
5616
  if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
5554
- let hostSelector;
5555
- let shadowSelector; // Scoping with the tokens is only necessary for synthetic shadow. For both
5556
- // light DOM elements and native shadow, we just render the CSS as-is.
5617
+ content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
5618
+ }
5619
+
5620
+ return content;
5621
+ } // It might be worth caching this to avoid doing the lookup repeatedly, but
5622
+ // perf testing has not shown it to be a huge improvement yet:
5623
+ // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
5557
5624
 
5558
- if (renderMode === 1
5625
+
5626
+ function getNearestNativeShadowComponent(vm) {
5627
+ let owner = vm;
5628
+
5629
+ while (!isNull(owner)) {
5630
+ if (owner.renderMode === 1
5559
5631
  /* Shadow */
5560
- && shadowMode === 1
5561
- /* Synthetic */
5562
- && !isUndefined$1(stylesheetTokens)) {
5563
- hostSelector = `[${stylesheetTokens.hostAttribute}]`;
5564
- shadowSelector = `[${stylesheetTokens.shadowAttribute}]`;
5565
- } else {
5566
- hostSelector = '';
5567
- shadowSelector = '';
5632
+ && owner.shadowMode === 0
5633
+ /* Native */
5634
+ ) {
5635
+ return owner;
5568
5636
  }
5569
5637
 
5570
- content = evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, shadowMode === 0
5571
- /* Native */
5572
- );
5638
+ owner = owner.owner;
5573
5639
  }
5574
5640
 
5575
- return content;
5641
+ return owner;
5576
5642
  }
5577
5643
 
5578
5644
  function createStylesheet(vm, stylesheets) {
@@ -5590,13 +5656,26 @@ var LWC = (function (exports) {
5590
5656
  for (let i = 0; i < stylesheets.length; i++) {
5591
5657
  renderer.insertGlobalStylesheet(stylesheets[i]);
5592
5658
  }
5593
-
5594
- return null;
5595
- } else {
5596
- // native shadow or light DOM
5659
+ } else if (renderer.ssr) {
5660
+ // native shadow or light DOM, SSR
5597
5661
  const combinedStylesheetContent = ArrayJoin.call(stylesheets, '\n');
5598
5662
  return createInlineStyleVNode(combinedStylesheetContent);
5663
+ } else {
5664
+ // native shadow or light DOM, DOM renderer
5665
+ const root = getNearestNativeShadowComponent(vm);
5666
+ const isGlobal = isNull(root);
5667
+
5668
+ for (let i = 0; i < stylesheets.length; i++) {
5669
+ if (isGlobal) {
5670
+ renderer.insertGlobalStylesheet(stylesheets[i]);
5671
+ } else {
5672
+ // local level
5673
+ renderer.insertStylesheet(stylesheets[i], root.cmpRoot);
5674
+ }
5675
+ }
5599
5676
  }
5677
+
5678
+ return null;
5600
5679
  }
5601
5680
  /*
5602
5681
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5802,8 +5881,7 @@ var LWC = (function (exports) {
5802
5881
  context,
5803
5882
  cmpSlots,
5804
5883
  cmpTemplate,
5805
- tro,
5806
- shadowMode
5884
+ tro
5807
5885
  } = vm;
5808
5886
  tro.observe(() => {
5809
5887
  // Reset the cache memoizer for template when needed.
@@ -5828,15 +5906,12 @@ var LWC = (function (exports) {
5828
5906
 
5829
5907
  vm.cmpTemplate = html; // Create a brand new template cache for the swapped templated.
5830
5908
 
5831
- context.tplCache = create(null); // Update the synthetic shadow attributes on the host element if necessary.
5909
+ context.tplCache = create(null); // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
5832
5910
 
5833
- if (shadowMode === 1
5834
- /* Synthetic */
5835
- ) {
5836
- updateSyntheticShadowAttributes(vm, html);
5837
- } // Evaluate, create stylesheet and cache the produced VNode for future
5838
- // re-rendering.
5911
+ context.hasScopedStyles = computeHasScopedStyles(html); // Update the scoping token on the host element.
5839
5912
 
5913
+ updateStylesheetToken(vm, html); // Evaluate, create stylesheet and cache the produced VNode for future
5914
+ // re-rendering.
5840
5915
 
5841
5916
  const stylesheetsContent = getStylesheetsContent(vm, html);
5842
5917
  context.styleVNode = stylesheetsContent.length === 0 ? null : createStylesheet(vm, stylesheetsContent);
@@ -5878,6 +5953,22 @@ var LWC = (function (exports) {
5878
5953
 
5879
5954
  return vnodes;
5880
5955
  }
5956
+
5957
+ function computeHasScopedStyles(template) {
5958
+ const {
5959
+ stylesheets
5960
+ } = template;
5961
+
5962
+ if (!isUndefined$1(stylesheets)) {
5963
+ for (let i = 0; i < stylesheets.length; i++) {
5964
+ if (isTrue(stylesheets[i][KEY__SCOPED_CSS])) {
5965
+ return true;
5966
+ }
5967
+ }
5968
+ }
5969
+
5970
+ return false;
5971
+ }
5881
5972
  /*
5882
5973
  * Copyright (c) 2018, salesforce.com, inc.
5883
5974
  * All rights reserved.
@@ -5918,12 +6009,9 @@ var LWC = (function (exports) {
5918
6009
  callHook,
5919
6010
  owner
5920
6011
  } = vm;
5921
- let result;
5922
6012
  runWithBoundaryProtection(vm, owner, noop, () => {
5923
- // job
5924
- result = callHook(component, fn, args);
6013
+ callHook(component, fn, args);
5925
6014
  }, noop);
5926
- return result;
5927
6015
  }
5928
6016
 
5929
6017
  function invokeComponentConstructor(vm, Ctor) {
@@ -5997,33 +6085,6 @@ var LWC = (function (exports) {
5997
6085
  return renderInvocationSuccessful ? evaluateTemplate(vm, html) : [];
5998
6086
  }
5999
6087
 
6000
- function invokeComponentRenderedCallback(vm) {
6001
- const {
6002
- def: {
6003
- renderedCallback
6004
- },
6005
- component,
6006
- callHook,
6007
- owner
6008
- } = vm;
6009
-
6010
- if (!isUndefined$1(renderedCallback)) {
6011
- runWithBoundaryProtection(vm, owner, () => {
6012
- logOperationStart(4
6013
- /* RenderedCallback */
6014
- , vm);
6015
- }, () => {
6016
- // job
6017
- callHook(component, renderedCallback);
6018
- }, () => {
6019
- // post
6020
- logOperationEnd(4
6021
- /* RenderedCallback */
6022
- , vm);
6023
- });
6024
- }
6025
- }
6026
-
6027
6088
  function invokeEventListener(vm, fn, thisValue, event) {
6028
6089
  const {
6029
6090
  callHook,
@@ -6179,7 +6240,6 @@ var LWC = (function (exports) {
6179
6240
  */
6180
6241
 
6181
6242
 
6182
- const isNativeShadowRootDefined = _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED];
6183
6243
  let idx = 0;
6184
6244
  /** The internal slot used to associate different objects the engine manipulates with the VM */
6185
6245
 
@@ -6288,29 +6348,6 @@ var LWC = (function (exports) {
6288
6348
  return ancestor;
6289
6349
  }
6290
6350
 
6291
- function assertNotSyntheticComposedWithinNative(vm) {
6292
- const isSynthetic = vm.renderMode === 1
6293
- /* Shadow */
6294
- && vm.shadowMode === 1
6295
- /* Synthetic */
6296
- ;
6297
-
6298
- if (!isSynthetic) {
6299
- return;
6300
- }
6301
-
6302
- const ancestor = getNearestShadowAncestor(vm);
6303
-
6304
- if (!isNull(ancestor)) {
6305
- // Any native shadow component being an ancestor of a synthetic shadow component is disallowed.
6306
- assert.isFalse(ancestor.renderMode === 1
6307
- /* Shadow */
6308
- && ancestor.shadowMode === 0
6309
- /* Native */
6310
- , `${getComponentTag(vm)} (synthetic shadow DOM) cannot be composed inside of ${getComponentTag(ancestor)} (native shadow DOM), because synthetic-within-native composition is disallowed`);
6311
- }
6312
- }
6313
-
6314
6351
  function createVM(elm, def, options) {
6315
6352
  const {
6316
6353
  mode,
@@ -6318,22 +6355,6 @@ var LWC = (function (exports) {
6318
6355
  renderer,
6319
6356
  tagName
6320
6357
  } = options;
6321
- let shadowMode;
6322
-
6323
- if (renderer.syntheticShadow) {
6324
- shadowMode = def.shadowSupportMode === "any"
6325
- /* Any */
6326
- && isNativeShadowRootDefined ? 0
6327
- /* Native */
6328
- : 1
6329
- /* Synthetic */
6330
- ;
6331
- } else {
6332
- shadowMode = 0
6333
- /* Native */
6334
- ;
6335
- }
6336
-
6337
6358
  const vm = {
6338
6359
  elm,
6339
6360
  def,
@@ -6356,10 +6377,12 @@ var LWC = (function (exports) {
6356
6377
  oar: create(null),
6357
6378
  cmpTemplate: null,
6358
6379
  renderMode: def.renderMode,
6359
- shadowMode,
6380
+ shadowMode: null,
6360
6381
  context: {
6361
- hostAttribute: undefined,
6362
- shadowAttribute: undefined,
6382
+ stylesheetToken: undefined,
6383
+ hasTokenInClass: undefined,
6384
+ hasTokenInAttribute: undefined,
6385
+ hasScopedStyles: undefined,
6363
6386
  styleVNode: null,
6364
6387
  tplCache: EmptyObject,
6365
6388
  wiredConnecting: EmptyArray,
@@ -6372,26 +6395,87 @@ var LWC = (function (exports) {
6372
6395
  setHook,
6373
6396
  getHook
6374
6397
  };
6398
+ vm.shadowMode = computeShadowMode(vm);
6375
6399
  vm.tro = getTemplateReactiveObserver(vm);
6376
6400
 
6377
6401
  if (process.env.NODE_ENV !== 'production') {
6378
6402
  vm.toString = () => {
6379
6403
  return `[object:vm ${def.name} (${vm.idx})]`;
6380
6404
  };
6381
-
6382
- assertNotSyntheticComposedWithinNative(vm);
6383
6405
  } // Create component instance associated to the vm and the element.
6384
6406
 
6385
6407
 
6386
6408
  invokeComponentConstructor(vm, def.ctor); // Initializing the wire decorator per instance only when really needed
6387
6409
 
6388
- if (isFalse(renderer.ssr) && hasWireAdapters(vm)) {
6410
+ if (hasWireAdapters(vm)) {
6389
6411
  installWireAdapters(vm);
6390
6412
  }
6391
6413
 
6392
6414
  return vm;
6393
6415
  }
6394
6416
 
6417
+ function computeShadowMode(vm) {
6418
+ const {
6419
+ def,
6420
+ renderer
6421
+ } = vm;
6422
+ const {
6423
+ isNativeShadowDefined,
6424
+ isSyntheticShadowDefined
6425
+ } = renderer;
6426
+ let shadowMode;
6427
+
6428
+ if (isSyntheticShadowDefined) {
6429
+ if (def.renderMode === 0
6430
+ /* Light */
6431
+ ) {
6432
+ // ShadowMode.Native implies "not synthetic shadow" which is consistent with how
6433
+ // everything defaults to native when the synthetic shadow polyfill is unavailable.
6434
+ shadowMode = 0
6435
+ /* Native */
6436
+ ;
6437
+ } else if (isNativeShadowDefined) {
6438
+ if (def.shadowSupportMode === "any"
6439
+ /* Any */
6440
+ ) {
6441
+ shadowMode = 0
6442
+ /* Native */
6443
+ ;
6444
+ } else {
6445
+ const shadowAncestor = getNearestShadowAncestor(vm);
6446
+
6447
+ if (!isNull(shadowAncestor) && shadowAncestor.shadowMode === 0
6448
+ /* Native */
6449
+ ) {
6450
+ // Transitive support for native Shadow DOM. A component in native mode
6451
+ // transitively opts all of its descendants into native.
6452
+ shadowMode = 0
6453
+ /* Native */
6454
+ ;
6455
+ } else {
6456
+ // Synthetic if neither this component nor any of its ancestors are configured
6457
+ // to be native.
6458
+ shadowMode = 1
6459
+ /* Synthetic */
6460
+ ;
6461
+ }
6462
+ }
6463
+ } else {
6464
+ // Synthetic if there is no native Shadow DOM support.
6465
+ shadowMode = 1
6466
+ /* Synthetic */
6467
+ ;
6468
+ }
6469
+ } else {
6470
+ // Native if the synthetic shadow polyfill is unavailable.
6471
+ shadowMode = 0
6472
+ /* Native */
6473
+ ;
6474
+ }
6475
+
6476
+ return shadowMode;
6477
+ }
6478
+
6395
6479
  function assertIsVM(obj) {
6396
6480
  if (isNull(obj) || !isObject(obj) || !('cmpRoot' in obj)) {
6397
6481
  throw new TypeError(`${obj} is not a VM.`);
@@ -6473,7 +6557,14 @@ var LWC = (function (exports) {
6473
6557
  }
6474
6558
 
6475
6559
  function runRenderedCallback(vm) {
6476
- if (isTrue(vm.renderer.ssr)) {
6560
+ const {
6561
+ renderer,
6562
+ def: {
6563
+ renderedCallback
6564
+ }
6565
+ } = vm;
6566
+
6567
+ if (isTrue(renderer.ssr)) {
6477
6568
  return;
6478
6569
  }
6479
6570
 
@@ -6485,7 +6576,15 @@ var LWC = (function (exports) {
6485
6576
  invokeServiceHook(vm, rendered);
6486
6577
  }
6487
6578
 
6488
- invokeComponentRenderedCallback(vm);
6579
+ if (!isUndefined$1(renderedCallback)) {
6580
+ logOperationStart(4
6581
+ /* RenderedCallback */
6582
+ , vm);
6583
+ invokeComponentCallback(vm, renderedCallback);
6584
+ logOperationEnd(4
6585
+ /* RenderedCallback */
6586
+ , vm);
6587
+ }
6489
6588
  }
6490
6589
 
6491
6590
  let rehydrateQueue = [];
@@ -7118,11 +7217,14 @@ var LWC = (function (exports) {
7118
7217
  ArrayPush$1.call(wiredConnecting, () => {
7119
7218
  connector.connect();
7120
7219
 
7121
- if (hasDynamicParams) {
7122
- Promise.resolve().then(computeConfigAndUpdate);
7123
- } else {
7124
- computeConfigAndUpdate();
7220
+ if (!runtimeFlags.ENABLE_WIRE_SYNC_EMIT) {
7221
+ if (hasDynamicParams) {
7222
+ Promise.resolve().then(computeConfigAndUpdate);
7223
+ return;
7224
+ }
7125
7225
  }
7226
+
7227
+ computeConfigAndUpdate();
7126
7228
  });
7127
7229
  ArrayPush$1.call(wiredDisconnecting, () => {
7128
7230
  connector.disconnect();
@@ -7229,7 +7331,7 @@ var LWC = (function (exports) {
7229
7331
 
7230
7332
  return reactiveMembrane.getReadOnlyProxy(obj);
7231
7333
  }
7232
- /* version: 2.3.3 */
7334
+ /* version: 2.5.0 */
7233
7335
 
7234
7336
  /*
7235
7337
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7251,6 +7353,10 @@ var LWC = (function (exports) {
7251
7353
  }
7252
7354
 
7253
7355
  const globalStylesheetsParentElement = document.head || document.body || document;
7356
+ const supportsConstructableStyleSheets = isFunction$1(CSSStyleSheet.prototype.replaceSync);
7357
+ const styleElements = create(null);
7358
+ const styleSheets = create(null);
7359
+ const nodesToStyleSheets = new WeakMap();
7254
7360
  let getCustomElement, defineCustomElement, HTMLElementConstructor;
7255
7361
 
7256
7362
  function isCustomElementRegistryAvailable() {
@@ -7277,6 +7383,52 @@ var LWC = (function (exports) {
7277
7383
  }
7278
7384
  }
7279
7385
 
7386
+ function insertConstructableStyleSheet(content, target) {
7387
+ // It's important for CSSStyleSheets to be unique based on their content, so that
7388
+ // `shadowRoot.adoptedStyleSheets.includes(sheet)` works.
7389
+ let styleSheet = styleSheets[content];
7390
+
7391
+ if (isUndefined$1(styleSheet)) {
7392
+ styleSheet = new CSSStyleSheet();
7393
+ styleSheet.replaceSync(content);
7394
+ styleSheets[content] = styleSheet;
7395
+ }
7396
+
7397
+ if (!target.adoptedStyleSheets.includes(styleSheet)) {
7398
+ target.adoptedStyleSheets = [...target.adoptedStyleSheets, styleSheet];
7399
+ }
7400
+ }
7401
+
7402
+ function insertStyleElement(content, target) {
7403
+ // Avoid inserting duplicate `<style>`s
7404
+ let sheets = nodesToStyleSheets.get(target);
7405
+
7406
+ if (isUndefined$1(sheets)) {
7407
+ sheets = create(null);
7408
+ nodesToStyleSheets.set(target, sheets);
7409
+ }
7410
+
7411
+ if (sheets[content]) {
7412
+ return;
7413
+ }
7414
+
7415
+ sheets[content] = true; // This `<style>` may be repeated multiple times in the DOM, so cache it. It's a bit
7416
+ // faster to call `cloneNode()` on an existing node than to recreate it every time.
7417
+
7418
+ let elm = styleElements[content];
7419
+
7420
+ if (isUndefined$1(elm)) {
7421
+ elm = document.createElement('style');
7422
+ elm.type = 'text/css';
7423
+ elm.textContent = content;
7424
+ styleElements[content] = elm;
7425
+ } else {
7426
+ elm = elm.cloneNode(true);
7427
+ }
7428
+
7429
+ target.appendChild(elm);
7430
+ }
7431
+
7280
7432
  if (isCustomElementRegistryAvailable()) {
7281
7433
  getCustomElement = customElements.get.bind(customElements);
7282
7434
  defineCustomElement = customElements.define.bind(customElements);
@@ -7322,7 +7474,8 @@ var LWC = (function (exports) {
7322
7474
 
7323
7475
  const renderer = {
7324
7476
  ssr: false,
7325
- syntheticShadow: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
7477
+ isNativeShadowDefined: _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED],
7478
+ isSyntheticShadowDefined: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
7326
7479
 
7327
7480
  createElement(tagName, namespace) {
7328
7481
  return isUndefined$1(namespace) ? document.createElement(tagName) : document.createElementNS(namespace, tagName);
@@ -7445,6 +7598,15 @@ var LWC = (function (exports) {
7445
7598
  globalStylesheetsParentElement.appendChild(elm);
7446
7599
  },
7447
7600
 
7601
+ insertStylesheet(content, target) {
7602
+ if (supportsConstructableStyleSheets) {
7603
+ insertConstructableStyleSheet(content, target);
7604
+ } else {
7605
+ // Fall back to <style> element
7606
+ insertStyleElement(content, target);
7607
+ }
7608
+ },
7609
+
7448
7610
  assertInstanceOfHTMLElement(elm, msg) {
7449
7611
  assert.invariant(elm instanceof HTMLElement, msg);
7450
7612
  },
@@ -7674,7 +7836,7 @@ var LWC = (function (exports) {
7674
7836
  return false;
7675
7837
  }
7676
7838
 
7677
- if (renderer.syntheticShadow) {
7839
+ if (renderer.isSyntheticShadowDefined) {
7678
7840
  // TODO [#1252]: old behavior that is still used by some pieces of the platform,
7679
7841
  // specifically, nodes inserted manually on places where `lwc:dom="manual"` directive is not
7680
7842
  // used, will be considered global elements.
@@ -7727,7 +7889,7 @@ var LWC = (function (exports) {
7727
7889
  });
7728
7890
  freeze(LightningElement);
7729
7891
  seal(LightningElement.prototype);
7730
- /* version: 2.3.3 */
7892
+ /* version: 2.5.0 */
7731
7893
 
7732
7894
  exports.LightningElement = LightningElement;
7733
7895
  exports.__unstable__ProfilerControl = profilerControl;