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
@@ -104,6 +104,10 @@ function isFalse(obj) {
104
104
  return obj === false;
105
105
  }
106
106
 
107
+ function isBoolean(obj) {
108
+ return typeof obj === 'boolean';
109
+ }
110
+
107
111
  function isFunction$1(obj) {
108
112
  return typeof obj === 'function';
109
113
  }
@@ -246,6 +250,7 @@ const KEY__IS_NATIVE_SHADOW_ROOT_DEFINED = '$isNativeShadowRootDefined$';
246
250
  const KEY__SHADOW_RESOLVER = '$shadowResolver$';
247
251
  const KEY__SHADOW_TOKEN = '$shadowToken$';
248
252
  const KEY__SYNTHETIC_MODE = '$$lwc-synthetic-mode';
253
+ const KEY__SCOPED_CSS = '$scoped$';
249
254
  /**
250
255
  * Map composed of properties to attributes not following the HTML property to attribute mapping
251
256
  * convention.
@@ -294,7 +299,7 @@ function htmlPropertyToAttribute(propName) {
294
299
  CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName);
295
300
  return attributeName;
296
301
  }
297
- /** version: 2.3.3 */
302
+ /** version: 2.5.0 */
298
303
 
299
304
  /*
300
305
  * Copyright (c) 2018, salesforce.com, inc.
@@ -399,19 +404,33 @@ for (let i = 0, len = ElementPrototypeAriaPropertyNames.length; i < len; i += 1)
399
404
  */
400
405
 
401
406
 
407
+ const features = {
408
+ ENABLE_REACTIVE_SETTER: null,
409
+ ENABLE_HMR: null,
410
+ ENABLE_INNER_OUTER_TEXT_PATCH: null,
411
+ ENABLE_ELEMENT_PATCH: null,
412
+ ENABLE_NODE_LIST_PATCH: null,
413
+ ENABLE_HTML_COLLECTIONS_PATCH: null,
414
+ ENABLE_NODE_PATCH: null,
415
+ ENABLE_NON_COMPOSED_EVENTS_LEAKAGE: null,
416
+ ENABLE_MIXED_SHADOW_MODE: null,
417
+ ENABLE_WIRE_SYNC_EMIT: null
418
+ };
419
+
402
420
  if (!_globalThis.lwcRuntimeFlags) {
403
421
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', {
404
422
  value: create(null)
405
423
  });
406
424
  }
407
425
 
408
- const runtimeFlags = _globalThis.lwcRuntimeFlags; // This function is not supported for use within components and is meant for
409
- // configuring runtime feature flags during app initialization.
426
+ const runtimeFlags = _globalThis.lwcRuntimeFlags;
427
+ /**
428
+ * Set the value at runtime of a given feature flag. This method only be invoked once per feature
429
+ * flag. It is meant to be used during the app initialization.
430
+ */
410
431
 
411
432
  function setFeatureFlag(name, value) {
412
- const isBoolean = isTrue(value) || isFalse(value);
413
-
414
- if (!isBoolean) {
433
+ if (!isBoolean(value)) {
415
434
  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.`;
416
435
 
417
436
  if (process.env.NODE_ENV !== 'production') {
@@ -423,9 +442,10 @@ function setFeatureFlag(name, value) {
423
442
  }
424
443
  }
425
444
 
426
- if (isUndefined$1(featureFlagLookup[name])) {
427
- // eslint-disable-next-line no-console
428
- 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.`);
445
+ if (isUndefined$1(features[name])) {
446
+ const availableFlags = keys(features).map(name => `"${name}"`).join(', '); // eslint-disable-next-line no-console
447
+
448
+ console.warn(`Failed to set the value "${value}" for the runtime feature flag "${name}" because it is undefined. Available flags: ${availableFlags}.`);
429
449
  return;
430
450
  }
431
451
 
@@ -442,37 +462,23 @@ function setFeatureFlag(name, value) {
442
462
  return;
443
463
  }
444
464
 
445
- Object.defineProperty(runtimeFlags, name, {
465
+ defineProperty(runtimeFlags, name, {
446
466
  value
447
467
  });
448
468
  }
449
- } // This function is exposed to components to facilitate testing so we add a
450
- // check to make sure it is not invoked in production.
469
+ }
470
+ /**
471
+ * Set the value at runtime of a given feature flag. This method should only be used for testing
472
+ * purposes. It is a no-op when invoked in production mode.
473
+ */
451
474
 
452
475
 
453
476
  function setFeatureFlagForTest(name, value) {
454
477
  if (process.env.NODE_ENV !== 'production') {
455
- return setFeatureFlag(name, value);
478
+ setFeatureFlag(name, value);
456
479
  }
457
480
  }
458
-
459
- const featureFlagLookup = {
460
- ENABLE_REACTIVE_SETTER: null,
461
- ENABLE_HMR: null,
462
- // Flag to toggle on/off the enforcement of innerText/outerText shadow dom semantic in elements when using synthetic shadow.
463
- // Note: Once active, elements outside the lwc boundary are controlled by the ENABLE_ELEMENT_PATCH flag.
464
- ENABLE_INNER_OUTER_TEXT_PATCH: null,
465
- // Flags to toggle on/off the enforcement of shadow dom semantic in element/node outside lwc boundary when using synthetic shadow.
466
- ENABLE_ELEMENT_PATCH: null,
467
- ENABLE_NODE_LIST_PATCH: null,
468
- ENABLE_HTML_COLLECTIONS_PATCH: null,
469
- ENABLE_NODE_PATCH: null,
470
- // Disables the fix for #2121 where non-composed events are visible outside of their shadow root.
471
- ENABLE_NON_COMPOSED_EVENTS_LEAKAGE: null,
472
- ENABLE_LIGHT_DOM_COMPONENTS: null,
473
- ENABLE_MIXED_SHADOW_MODE: null
474
- };
475
- /** version: 2.3.3 */
481
+ /** version: 2.5.0 */
476
482
 
477
483
  /* proxy-compat-disable */
478
484
 
@@ -483,6 +489,7 @@ const featureFlagLookup = {
483
489
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
484
490
  */
485
491
 
492
+
486
493
  let nextTickCallbackQueue = [];
487
494
  const SPACE_CHAR = 32;
488
495
  const EmptyObject = seal(create(null));
@@ -2803,12 +2810,6 @@ const LightningElement = function () {
2803
2810
  associateVM(component, vm);
2804
2811
  associateVM(elm, vm);
2805
2812
 
2806
- if (!runtimeFlags.ENABLE_LIGHT_DOM_COMPONENTS) {
2807
- assert.isTrue(def.renderMode !== 0
2808
- /* Light */
2809
- , `${def.name || 'Anonymous class'} is an invalid LWC component. Light DOM components are not available in this environment.`);
2810
- }
2811
-
2812
2813
  if (vm.renderMode === 1
2813
2814
  /* Shadow */
2814
2815
  ) {
@@ -2847,6 +2848,12 @@ function attachShadow(vm) {
2847
2848
  if (process.env.NODE_ENV !== 'production') {
2848
2849
  patchShadowRootWithRestrictions(cmpRoot);
2849
2850
  }
2851
+ }
2852
+
2853
+ function warnIfInvokedDuringConstruction(vm, methodName) {
2854
+ if (isBeingConstructed(vm)) {
2855
+ 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.`);
2856
+ }
2850
2857
  } // @ts-ignore
2851
2858
 
2852
2859
 
@@ -3005,7 +3012,7 @@ LightningElement.prototype = {
3005
3012
  } = vm;
3006
3013
 
3007
3014
  if (process.env.NODE_ENV !== 'production') {
3008
- 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.`);
3015
+ warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect');
3009
3016
  }
3010
3017
 
3011
3018
  return getBoundingClientRect(elm);
@@ -3021,7 +3028,7 @@ LightningElement.prototype = {
3021
3028
  } = vm;
3022
3029
 
3023
3030
  if (process.env.NODE_ENV !== 'production') {
3024
- 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.`);
3031
+ warnIfInvokedDuringConstruction(vm, 'querySelector');
3025
3032
  }
3026
3033
 
3027
3034
  return querySelector(elm, selectors);
@@ -3037,7 +3044,7 @@ LightningElement.prototype = {
3037
3044
  } = vm;
3038
3045
 
3039
3046
  if (process.env.NODE_ENV !== 'production') {
3040
- 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.`);
3047
+ warnIfInvokedDuringConstruction(vm, 'querySelectorAll');
3041
3048
  }
3042
3049
 
3043
3050
  return querySelectorAll(elm, selectors);
@@ -3053,7 +3060,7 @@ LightningElement.prototype = {
3053
3060
  } = vm;
3054
3061
 
3055
3062
  if (process.env.NODE_ENV !== 'production') {
3056
- 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.`);
3063
+ warnIfInvokedDuringConstruction(vm, 'getElementsByTagName');
3057
3064
  }
3058
3065
 
3059
3066
  return getElementsByTagName(elm, tagNameOrWildCard);
@@ -3069,7 +3076,7 @@ LightningElement.prototype = {
3069
3076
  } = vm;
3070
3077
 
3071
3078
  if (process.env.NODE_ENV !== 'production') {
3072
- 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.`);
3079
+ warnIfInvokedDuringConstruction(vm, 'getElementsByClassName');
3073
3080
  }
3074
3081
 
3075
3082
  return getElementsByClassName(elm, names);
@@ -4479,6 +4486,19 @@ function observeElementChildNodes(elm) {
4479
4486
 
4480
4487
  function setElementShadowToken(elm, token) {
4481
4488
  elm.$shadowToken$ = token;
4489
+ } // Set the scope token class for *.scoped.css styles
4490
+
4491
+
4492
+ function setScopeTokenClassIfNecessary(elm, owner) {
4493
+ const {
4494
+ cmpTemplate,
4495
+ context
4496
+ } = owner;
4497
+ const token = cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken;
4498
+
4499
+ if (!isUndefined$1(token) && context.hasScopedStyles) {
4500
+ owner.renderer.getClassList(elm).add(token);
4501
+ }
4482
4502
  }
4483
4503
 
4484
4504
  function updateNodeHook(oldVnode, vnode) {
@@ -4552,6 +4572,7 @@ function fallbackElmHook(elm, vnode) {
4552
4572
  const {
4553
4573
  owner
4554
4574
  } = vnode;
4575
+ setScopeTokenClassIfNecessary(elm, owner);
4555
4576
 
4556
4577
  if (owner.shadowMode === 1
4557
4578
  /* Synthetic */
@@ -4562,7 +4583,7 @@ function fallbackElmHook(elm, vnode) {
4562
4583
  }
4563
4584
  } = vnode;
4564
4585
  const {
4565
- shadowAttribute
4586
+ stylesheetToken
4566
4587
  } = owner.context;
4567
4588
 
4568
4589
  if (!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
@@ -4574,7 +4595,7 @@ function fallbackElmHook(elm, vnode) {
4574
4595
  // into each element from the template, so they can be styled accordingly.
4575
4596
 
4576
4597
 
4577
- setElementShadowToken(elm, shadowAttribute);
4598
+ setElementShadowToken(elm, stylesheetToken);
4578
4599
  }
4579
4600
 
4580
4601
  if (process.env.NODE_ENV !== 'production') {
@@ -4663,16 +4684,17 @@ function createViewModelHook(elm, vnode) {
4663
4684
  ctor,
4664
4685
  owner
4665
4686
  } = vnode;
4687
+ setScopeTokenClassIfNecessary(elm, owner);
4666
4688
 
4667
4689
  if (owner.shadowMode === 1
4668
4690
  /* Synthetic */
4669
4691
  ) {
4670
4692
  const {
4671
- shadowAttribute
4693
+ stylesheetToken
4672
4694
  } = owner.context; // when running in synthetic shadow mode, we need to set the shadowToken value
4673
4695
  // into each element from the template, so they can be styled accordingly.
4674
4696
 
4675
- setElementShadowToken(elm, shadowAttribute);
4697
+ setElementShadowToken(elm, stylesheetToken);
4676
4698
  }
4677
4699
 
4678
4700
  const def = getComponentInternalDef(ctor);
@@ -4972,13 +4994,19 @@ const CustomElementHook = {
4972
4994
 
4973
4995
  function linkNodeToShadow(elm, owner) {
4974
4996
  const {
4997
+ renderer,
4998
+ renderMode,
4975
4999
  shadowMode
4976
5000
  } = owner; // TODO [#1164]: this should eventually be done by the polyfill directly
4977
5001
 
4978
- if (shadowMode === 1
4979
- /* Synthetic */
4980
- ) {
4981
- elm[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
5002
+ if (renderer.isSyntheticShadowDefined) {
5003
+ if (shadowMode === 1
5004
+ /* Synthetic */
5005
+ || renderMode === 0
5006
+ /* Light */
5007
+ ) {
5008
+ elm[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
5009
+ }
4982
5010
  }
4983
5011
  }
4984
5012
 
@@ -5324,14 +5352,11 @@ function gid(id) {
5324
5352
 
5325
5353
  const {
5326
5354
  idx,
5327
- renderMode,
5328
5355
  shadowMode
5329
5356
  } = vmBeingRendered;
5330
5357
 
5331
5358
  if (shadowMode === 1
5332
5359
  /* Synthetic */
5333
- && renderMode === 1
5334
- /* Shadow */
5335
5360
  ) {
5336
5361
  return StringReplace.call(id, /\S+/g, id => `${id}-${idx}`);
5337
5362
  }
@@ -5360,14 +5385,11 @@ function fid(url) {
5360
5385
 
5361
5386
  const {
5362
5387
  idx,
5363
- renderMode,
5364
5388
  shadowMode
5365
5389
  } = vmBeingRendered; // Apply transformation only for fragment-only-urls, and only in shadow DOM
5366
5390
 
5367
5391
  if (shadowMode === 1
5368
5392
  /* Synthetic */
5369
- && renderMode === 1
5370
- /* Shadow */
5371
5393
  && /^#/.test(url)) {
5372
5394
  return `${url}-${idx}`;
5373
5395
  }
@@ -5468,6 +5490,10 @@ var api = /*#__PURE__*/Object.freeze({
5468
5490
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5469
5491
  */
5470
5492
 
5493
+ function makeHostToken(token) {
5494
+ return `${token}-host`;
5495
+ }
5496
+
5471
5497
  function createInlineStyleVNode(content) {
5472
5498
  return h('style', {
5473
5499
  key: 'style',
@@ -5477,59 +5503,100 @@ function createInlineStyleVNode(content) {
5477
5503
  }, [t(content)]);
5478
5504
  }
5479
5505
 
5480
- function updateSyntheticShadowAttributes(vm, template) {
5506
+ function updateStylesheetToken(vm, template) {
5481
5507
  const {
5482
5508
  elm,
5483
5509
  context,
5484
5510
  renderer,
5485
- renderMode
5511
+ renderMode,
5512
+ shadowMode
5486
5513
  } = vm;
5487
5514
  const {
5488
5515
  stylesheets: newStylesheets,
5489
- stylesheetTokens: newStylesheetTokens
5516
+ stylesheetToken: newStylesheetToken
5490
5517
  } = template;
5491
- let newTokens; // Reset the styling token applied to the host element.
5518
+ const isSyntheticShadow = renderMode === 1
5519
+ /* Shadow */
5520
+ && shadowMode === 1
5521
+ /* Synthetic */
5522
+ ;
5523
+ const {
5524
+ hasScopedStyles
5525
+ } = context;
5526
+ let newToken;
5527
+ let newHasTokenInClass;
5528
+ let newHasTokenInAttribute; // Reset the styling token applied to the host element.
5529
+
5530
+ const {
5531
+ stylesheetToken: oldToken,
5532
+ hasTokenInClass: oldHasTokenInClass,
5533
+ hasTokenInAttribute: oldHasTokenInAttribute
5534
+ } = context;
5492
5535
 
5493
- const oldHostAttribute = context.hostAttribute;
5536
+ if (oldHasTokenInClass) {
5537
+ renderer.getClassList(elm).remove(makeHostToken(oldToken));
5538
+ }
5494
5539
 
5495
- if (!isUndefined$1(oldHostAttribute)) {
5496
- renderer.removeAttribute(elm, oldHostAttribute);
5540
+ if (oldHasTokenInAttribute) {
5541
+ renderer.removeAttribute(elm, makeHostToken(oldToken));
5497
5542
  } // Apply the new template styling token to the host element, if the new template has any
5498
- // associated stylesheets.
5543
+ // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
5499
5544
 
5500
5545
 
5501
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0 && renderMode === 1
5502
- /* Shadow */
5503
- ) {
5504
- newTokens = newStylesheetTokens;
5505
- }
5546
+ if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
5547
+ newToken = newStylesheetToken;
5548
+ } // Set the new styling token on the host element
5549
+
5506
5550
 
5507
- if (!isUndefined$1(newTokens)) {
5508
- renderer.setAttribute(elm, newTokens.hostAttribute, '');
5551
+ if (!isUndefined$1(newToken)) {
5552
+ if (hasScopedStyles) {
5553
+ renderer.getClassList(elm).add(makeHostToken(newToken));
5554
+ newHasTokenInClass = true;
5555
+ }
5556
+
5557
+ if (isSyntheticShadow) {
5558
+ renderer.setAttribute(elm, makeHostToken(newToken), '');
5559
+ newHasTokenInAttribute = true;
5560
+ }
5509
5561
  } // Update the styling tokens present on the context object.
5510
5562
 
5511
5563
 
5512
- context.hostAttribute = newTokens === null || newTokens === void 0 ? void 0 : newTokens.hostAttribute;
5513
- context.shadowAttribute = newTokens === null || newTokens === void 0 ? void 0 : newTokens.shadowAttribute;
5564
+ context.stylesheetToken = newToken;
5565
+ context.hasTokenInClass = newHasTokenInClass;
5566
+ context.hasTokenInAttribute = newHasTokenInAttribute;
5514
5567
  }
5515
5568
 
5516
- function evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, nativeShadow) {
5569
+ function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
5517
5570
  const content = [];
5518
5571
 
5519
5572
  for (let i = 0; i < stylesheets.length; i++) {
5520
5573
  let stylesheet = stylesheets[i];
5521
5574
 
5522
5575
  if (isArray$1(stylesheet)) {
5523
- ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, hostSelector, shadowSelector, nativeShadow));
5576
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
5524
5577
  } else {
5525
5578
  if (process.env.NODE_ENV !== 'production') {
5526
5579
  // in dev-mode, we support hot swapping of stylesheet, which means that
5527
5580
  // the component instance might be attempting to use an old version of
5528
5581
  // the stylesheet, while internally, we have a replacement for it.
5529
5582
  stylesheet = getStyleOrSwappedStyle(stylesheet);
5530
- }
5583
+ } // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
5584
+ // native shadow DOM. Synthetic shadow DOM never uses `:host`.
5585
+
5586
+
5587
+ const isScopedCss = stylesheet[KEY__SCOPED_CSS];
5588
+ const useActualHostSelector = vm.renderMode === 0
5589
+ /* Light */
5590
+ ? !isScopedCss : vm.shadowMode === 0
5591
+ /* Native */
5592
+ ; // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
5531
5593
 
5532
- ArrayPush$1.call(content, stylesheet(hostSelector, shadowSelector, nativeShadow));
5594
+ const scopeToken = isScopedCss || vm.shadowMode === 1
5595
+ /* Synthetic */
5596
+ && vm.renderMode === 1
5597
+ /* Shadow */
5598
+ ? stylesheetToken : undefined;
5599
+ ArrayPush$1.call(content, stylesheet(useActualHostSelector, scopeToken));
5533
5600
  }
5534
5601
  }
5535
5602
 
@@ -5539,37 +5606,36 @@ function evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, n
5539
5606
  function getStylesheetsContent(vm, template) {
5540
5607
  const {
5541
5608
  stylesheets,
5542
- stylesheetTokens
5609
+ stylesheetToken
5543
5610
  } = template;
5544
- const {
5545
- renderMode,
5546
- shadowMode
5547
- } = vm;
5548
5611
  let content = [];
5549
5612
 
5550
5613
  if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
5551
- let hostSelector;
5552
- let shadowSelector; // Scoping with the tokens is only necessary for synthetic shadow. For both
5553
- // light DOM elements and native shadow, we just render the CSS as-is.
5614
+ content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
5615
+ }
5616
+
5617
+ return content;
5618
+ } // It might be worth caching this to avoid doing the lookup repeatedly, but
5619
+ // perf testing has not shown it to be a huge improvement yet:
5620
+ // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
5554
5621
 
5555
- if (renderMode === 1
5622
+
5623
+ function getNearestNativeShadowComponent(vm) {
5624
+ let owner = vm;
5625
+
5626
+ while (!isNull(owner)) {
5627
+ if (owner.renderMode === 1
5556
5628
  /* Shadow */
5557
- && shadowMode === 1
5558
- /* Synthetic */
5559
- && !isUndefined$1(stylesheetTokens)) {
5560
- hostSelector = `[${stylesheetTokens.hostAttribute}]`;
5561
- shadowSelector = `[${stylesheetTokens.shadowAttribute}]`;
5562
- } else {
5563
- hostSelector = '';
5564
- shadowSelector = '';
5629
+ && owner.shadowMode === 0
5630
+ /* Native */
5631
+ ) {
5632
+ return owner;
5565
5633
  }
5566
5634
 
5567
- content = evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, shadowMode === 0
5568
- /* Native */
5569
- );
5635
+ owner = owner.owner;
5570
5636
  }
5571
5637
 
5572
- return content;
5638
+ return owner;
5573
5639
  }
5574
5640
 
5575
5641
  function createStylesheet(vm, stylesheets) {
@@ -5587,13 +5653,26 @@ function createStylesheet(vm, stylesheets) {
5587
5653
  for (let i = 0; i < stylesheets.length; i++) {
5588
5654
  renderer.insertGlobalStylesheet(stylesheets[i]);
5589
5655
  }
5590
-
5591
- return null;
5592
- } else {
5593
- // native shadow or light DOM
5656
+ } else if (renderer.ssr) {
5657
+ // native shadow or light DOM, SSR
5594
5658
  const combinedStylesheetContent = ArrayJoin.call(stylesheets, '\n');
5595
5659
  return createInlineStyleVNode(combinedStylesheetContent);
5660
+ } else {
5661
+ // native shadow or light DOM, DOM renderer
5662
+ const root = getNearestNativeShadowComponent(vm);
5663
+ const isGlobal = isNull(root);
5664
+
5665
+ for (let i = 0; i < stylesheets.length; i++) {
5666
+ if (isGlobal) {
5667
+ renderer.insertGlobalStylesheet(stylesheets[i]);
5668
+ } else {
5669
+ // local level
5670
+ renderer.insertStylesheet(stylesheets[i], root.cmpRoot);
5671
+ }
5672
+ }
5596
5673
  }
5674
+
5675
+ return null;
5597
5676
  }
5598
5677
  /*
5599
5678
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5799,8 +5878,7 @@ function evaluateTemplate(vm, html) {
5799
5878
  context,
5800
5879
  cmpSlots,
5801
5880
  cmpTemplate,
5802
- tro,
5803
- shadowMode
5881
+ tro
5804
5882
  } = vm;
5805
5883
  tro.observe(() => {
5806
5884
  // Reset the cache memoizer for template when needed.
@@ -5825,15 +5903,12 @@ function evaluateTemplate(vm, html) {
5825
5903
 
5826
5904
  vm.cmpTemplate = html; // Create a brand new template cache for the swapped templated.
5827
5905
 
5828
- context.tplCache = create(null); // Update the synthetic shadow attributes on the host element if necessary.
5906
+ context.tplCache = create(null); // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
5829
5907
 
5830
- if (shadowMode === 1
5831
- /* Synthetic */
5832
- ) {
5833
- updateSyntheticShadowAttributes(vm, html);
5834
- } // Evaluate, create stylesheet and cache the produced VNode for future
5835
- // re-rendering.
5908
+ context.hasScopedStyles = computeHasScopedStyles(html); // Update the scoping token on the host element.
5836
5909
 
5910
+ updateStylesheetToken(vm, html); // Evaluate, create stylesheet and cache the produced VNode for future
5911
+ // re-rendering.
5837
5912
 
5838
5913
  const stylesheetsContent = getStylesheetsContent(vm, html);
5839
5914
  context.styleVNode = stylesheetsContent.length === 0 ? null : createStylesheet(vm, stylesheetsContent);
@@ -5875,6 +5950,22 @@ function evaluateTemplate(vm, html) {
5875
5950
 
5876
5951
  return vnodes;
5877
5952
  }
5953
+
5954
+ function computeHasScopedStyles(template) {
5955
+ const {
5956
+ stylesheets
5957
+ } = template;
5958
+
5959
+ if (!isUndefined$1(stylesheets)) {
5960
+ for (let i = 0; i < stylesheets.length; i++) {
5961
+ if (isTrue(stylesheets[i][KEY__SCOPED_CSS])) {
5962
+ return true;
5963
+ }
5964
+ }
5965
+ }
5966
+
5967
+ return false;
5968
+ }
5878
5969
  /*
5879
5970
  * Copyright (c) 2018, salesforce.com, inc.
5880
5971
  * All rights reserved.
@@ -5915,12 +6006,9 @@ function invokeComponentCallback(vm, fn, args) {
5915
6006
  callHook,
5916
6007
  owner
5917
6008
  } = vm;
5918
- let result;
5919
6009
  runWithBoundaryProtection(vm, owner, noop, () => {
5920
- // job
5921
- result = callHook(component, fn, args);
6010
+ callHook(component, fn, args);
5922
6011
  }, noop);
5923
- return result;
5924
6012
  }
5925
6013
 
5926
6014
  function invokeComponentConstructor(vm, Ctor) {
@@ -5994,33 +6082,6 @@ function invokeComponentRenderMethod(vm) {
5994
6082
  return renderInvocationSuccessful ? evaluateTemplate(vm, html) : [];
5995
6083
  }
5996
6084
 
5997
- function invokeComponentRenderedCallback(vm) {
5998
- const {
5999
- def: {
6000
- renderedCallback
6001
- },
6002
- component,
6003
- callHook,
6004
- owner
6005
- } = vm;
6006
-
6007
- if (!isUndefined$1(renderedCallback)) {
6008
- runWithBoundaryProtection(vm, owner, () => {
6009
- logOperationStart(4
6010
- /* RenderedCallback */
6011
- , vm);
6012
- }, () => {
6013
- // job
6014
- callHook(component, renderedCallback);
6015
- }, () => {
6016
- // post
6017
- logOperationEnd(4
6018
- /* RenderedCallback */
6019
- , vm);
6020
- });
6021
- }
6022
- }
6023
-
6024
6085
  function invokeEventListener(vm, fn, thisValue, event) {
6025
6086
  const {
6026
6087
  callHook,
@@ -6176,7 +6237,6 @@ function invokeServiceHook(vm, cbs) {
6176
6237
  */
6177
6238
 
6178
6239
 
6179
- const isNativeShadowRootDefined = _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED];
6180
6240
  let idx = 0;
6181
6241
  /** The internal slot used to associate different objects the engine manipulates with the VM */
6182
6242
 
@@ -6285,29 +6345,6 @@ function getNearestShadowAncestor(vm) {
6285
6345
  return ancestor;
6286
6346
  }
6287
6347
 
6288
- function assertNotSyntheticComposedWithinNative(vm) {
6289
- const isSynthetic = vm.renderMode === 1
6290
- /* Shadow */
6291
- && vm.shadowMode === 1
6292
- /* Synthetic */
6293
- ;
6294
-
6295
- if (!isSynthetic) {
6296
- return;
6297
- }
6298
-
6299
- const ancestor = getNearestShadowAncestor(vm);
6300
-
6301
- if (!isNull(ancestor)) {
6302
- // Any native shadow component being an ancestor of a synthetic shadow component is disallowed.
6303
- assert.isFalse(ancestor.renderMode === 1
6304
- /* Shadow */
6305
- && ancestor.shadowMode === 0
6306
- /* Native */
6307
- , `${getComponentTag(vm)} (synthetic shadow DOM) cannot be composed inside of ${getComponentTag(ancestor)} (native shadow DOM), because synthetic-within-native composition is disallowed`);
6308
- }
6309
- }
6310
-
6311
6348
  function createVM(elm, def, options) {
6312
6349
  const {
6313
6350
  mode,
@@ -6315,22 +6352,6 @@ function createVM(elm, def, options) {
6315
6352
  renderer,
6316
6353
  tagName
6317
6354
  } = options;
6318
- let shadowMode;
6319
-
6320
- if (renderer.syntheticShadow) {
6321
- shadowMode = def.shadowSupportMode === "any"
6322
- /* Any */
6323
- && isNativeShadowRootDefined ? 0
6324
- /* Native */
6325
- : 1
6326
- /* Synthetic */
6327
- ;
6328
- } else {
6329
- shadowMode = 0
6330
- /* Native */
6331
- ;
6332
- }
6333
-
6334
6355
  const vm = {
6335
6356
  elm,
6336
6357
  def,
@@ -6353,10 +6374,12 @@ function createVM(elm, def, options) {
6353
6374
  oar: create(null),
6354
6375
  cmpTemplate: null,
6355
6376
  renderMode: def.renderMode,
6356
- shadowMode,
6377
+ shadowMode: null,
6357
6378
  context: {
6358
- hostAttribute: undefined,
6359
- shadowAttribute: undefined,
6379
+ stylesheetToken: undefined,
6380
+ hasTokenInClass: undefined,
6381
+ hasTokenInAttribute: undefined,
6382
+ hasScopedStyles: undefined,
6360
6383
  styleVNode: null,
6361
6384
  tplCache: EmptyObject,
6362
6385
  wiredConnecting: EmptyArray,
@@ -6369,26 +6392,87 @@ function createVM(elm, def, options) {
6369
6392
  setHook,
6370
6393
  getHook
6371
6394
  };
6395
+ vm.shadowMode = computeShadowMode(vm);
6372
6396
  vm.tro = getTemplateReactiveObserver(vm);
6373
6397
 
6374
6398
  if (process.env.NODE_ENV !== 'production') {
6375
6399
  vm.toString = () => {
6376
6400
  return `[object:vm ${def.name} (${vm.idx})]`;
6377
6401
  };
6378
-
6379
- assertNotSyntheticComposedWithinNative(vm);
6380
6402
  } // Create component instance associated to the vm and the element.
6381
6403
 
6382
6404
 
6383
6405
  invokeComponentConstructor(vm, def.ctor); // Initializing the wire decorator per instance only when really needed
6384
6406
 
6385
- if (isFalse(renderer.ssr) && hasWireAdapters(vm)) {
6407
+ if (hasWireAdapters(vm)) {
6386
6408
  installWireAdapters(vm);
6387
6409
  }
6388
6410
 
6389
6411
  return vm;
6390
6412
  }
6391
6413
 
6414
+ function computeShadowMode(vm) {
6415
+ const {
6416
+ def,
6417
+ renderer
6418
+ } = vm;
6419
+ const {
6420
+ isNativeShadowDefined,
6421
+ isSyntheticShadowDefined
6422
+ } = renderer;
6423
+ let shadowMode;
6424
+
6425
+ if (isSyntheticShadowDefined) {
6426
+ if (def.renderMode === 0
6427
+ /* Light */
6428
+ ) {
6429
+ // ShadowMode.Native implies "not synthetic shadow" which is consistent with how
6430
+ // everything defaults to native when the synthetic shadow polyfill is unavailable.
6431
+ shadowMode = 0
6432
+ /* Native */
6433
+ ;
6434
+ } else if (isNativeShadowDefined) {
6435
+ if (def.shadowSupportMode === "any"
6436
+ /* Any */
6437
+ ) {
6438
+ shadowMode = 0
6439
+ /* Native */
6440
+ ;
6441
+ } else {
6442
+ const shadowAncestor = getNearestShadowAncestor(vm);
6443
+
6444
+ if (!isNull(shadowAncestor) && shadowAncestor.shadowMode === 0
6445
+ /* Native */
6446
+ ) {
6447
+ // Transitive support for native Shadow DOM. A component in native mode
6448
+ // transitively opts all of its descendants into native.
6449
+ shadowMode = 0
6450
+ /* Native */
6451
+ ;
6452
+ } else {
6453
+ // Synthetic if neither this component nor any of its ancestors are configured
6454
+ // to be native.
6455
+ shadowMode = 1
6456
+ /* Synthetic */
6457
+ ;
6458
+ }
6459
+ }
6460
+ } else {
6461
+ // Synthetic if there is no native Shadow DOM support.
6462
+ shadowMode = 1
6463
+ /* Synthetic */
6464
+ ;
6465
+ }
6466
+ } else {
6467
+ // Native if the synthetic shadow polyfill is unavailable.
6468
+ shadowMode = 0
6469
+ /* Native */
6470
+ ;
6471
+ }
6472
+
6473
+ return shadowMode;
6474
+ }
6475
+
6392
6476
  function assertIsVM(obj) {
6393
6477
  if (isNull(obj) || !isObject(obj) || !('cmpRoot' in obj)) {
6394
6478
  throw new TypeError(`${obj} is not a VM.`);
@@ -6470,7 +6554,14 @@ function patchShadowRoot(vm, newCh) {
6470
6554
  }
6471
6555
 
6472
6556
  function runRenderedCallback(vm) {
6473
- if (isTrue(vm.renderer.ssr)) {
6557
+ const {
6558
+ renderer,
6559
+ def: {
6560
+ renderedCallback
6561
+ }
6562
+ } = vm;
6563
+
6564
+ if (isTrue(renderer.ssr)) {
6474
6565
  return;
6475
6566
  }
6476
6567
 
@@ -6482,7 +6573,15 @@ function runRenderedCallback(vm) {
6482
6573
  invokeServiceHook(vm, rendered);
6483
6574
  }
6484
6575
 
6485
- invokeComponentRenderedCallback(vm);
6576
+ if (!isUndefined$1(renderedCallback)) {
6577
+ logOperationStart(4
6578
+ /* RenderedCallback */
6579
+ , vm);
6580
+ invokeComponentCallback(vm, renderedCallback);
6581
+ logOperationEnd(4
6582
+ /* RenderedCallback */
6583
+ , vm);
6584
+ }
6486
6585
  }
6487
6586
 
6488
6587
  let rehydrateQueue = [];
@@ -7115,11 +7214,14 @@ function installWireAdapters(vm) {
7115
7214
  ArrayPush$1.call(wiredConnecting, () => {
7116
7215
  connector.connect();
7117
7216
 
7118
- if (hasDynamicParams) {
7119
- Promise.resolve().then(computeConfigAndUpdate);
7120
- } else {
7121
- computeConfigAndUpdate();
7217
+ if (!runtimeFlags.ENABLE_WIRE_SYNC_EMIT) {
7218
+ if (hasDynamicParams) {
7219
+ Promise.resolve().then(computeConfigAndUpdate);
7220
+ return;
7221
+ }
7122
7222
  }
7223
+
7224
+ computeConfigAndUpdate();
7123
7225
  });
7124
7226
  ArrayPush$1.call(wiredDisconnecting, () => {
7125
7227
  connector.disconnect();
@@ -7226,7 +7328,7 @@ function readonly(obj) {
7226
7328
 
7227
7329
  return reactiveMembrane.getReadOnlyProxy(obj);
7228
7330
  }
7229
- /* version: 2.3.3 */
7331
+ /* version: 2.5.0 */
7230
7332
 
7231
7333
  /*
7232
7334
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7248,6 +7350,10 @@ if (process.env.NODE_ENV === 'development') {
7248
7350
  }
7249
7351
 
7250
7352
  const globalStylesheetsParentElement = document.head || document.body || document;
7353
+ const supportsConstructableStyleSheets = isFunction$1(CSSStyleSheet.prototype.replaceSync);
7354
+ const styleElements = create(null);
7355
+ const styleSheets = create(null);
7356
+ const nodesToStyleSheets = new WeakMap();
7251
7357
  let getCustomElement, defineCustomElement, HTMLElementConstructor;
7252
7358
 
7253
7359
  function isCustomElementRegistryAvailable() {
@@ -7274,6 +7380,52 @@ function isCustomElementRegistryAvailable() {
7274
7380
  }
7275
7381
  }
7276
7382
 
7383
+ function insertConstructableStyleSheet(content, target) {
7384
+ // It's important for CSSStyleSheets to be unique based on their content, so that
7385
+ // `shadowRoot.adoptedStyleSheets.includes(sheet)` works.
7386
+ let styleSheet = styleSheets[content];
7387
+
7388
+ if (isUndefined$1(styleSheet)) {
7389
+ styleSheet = new CSSStyleSheet();
7390
+ styleSheet.replaceSync(content);
7391
+ styleSheets[content] = styleSheet;
7392
+ }
7393
+
7394
+ if (!target.adoptedStyleSheets.includes(styleSheet)) {
7395
+ target.adoptedStyleSheets = [...target.adoptedStyleSheets, styleSheet];
7396
+ }
7397
+ }
7398
+
7399
+ function insertStyleElement(content, target) {
7400
+ // Avoid inserting duplicate `<style>`s
7401
+ let sheets = nodesToStyleSheets.get(target);
7402
+
7403
+ if (isUndefined$1(sheets)) {
7404
+ sheets = create(null);
7405
+ nodesToStyleSheets.set(target, sheets);
7406
+ }
7407
+
7408
+ if (sheets[content]) {
7409
+ return;
7410
+ }
7411
+
7412
+ sheets[content] = true; // This `<style>` may be repeated multiple times in the DOM, so cache it. It's a bit
7413
+ // faster to call `cloneNode()` on an existing node than to recreate it every time.
7414
+
7415
+ let elm = styleElements[content];
7416
+
7417
+ if (isUndefined$1(elm)) {
7418
+ elm = document.createElement('style');
7419
+ elm.type = 'text/css';
7420
+ elm.textContent = content;
7421
+ styleElements[content] = elm;
7422
+ } else {
7423
+ elm = elm.cloneNode(true);
7424
+ }
7425
+
7426
+ target.appendChild(elm);
7427
+ }
7428
+
7277
7429
  if (isCustomElementRegistryAvailable()) {
7278
7430
  getCustomElement = customElements.get.bind(customElements);
7279
7431
  defineCustomElement = customElements.define.bind(customElements);
@@ -7319,7 +7471,8 @@ if (isCustomElementRegistryAvailable()) {
7319
7471
 
7320
7472
  const renderer = {
7321
7473
  ssr: false,
7322
- syntheticShadow: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
7474
+ isNativeShadowDefined: _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED],
7475
+ isSyntheticShadowDefined: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
7323
7476
 
7324
7477
  createElement(tagName, namespace) {
7325
7478
  return isUndefined$1(namespace) ? document.createElement(tagName) : document.createElementNS(namespace, tagName);
@@ -7442,6 +7595,15 @@ const renderer = {
7442
7595
  globalStylesheetsParentElement.appendChild(elm);
7443
7596
  },
7444
7597
 
7598
+ insertStylesheet(content, target) {
7599
+ if (supportsConstructableStyleSheets) {
7600
+ insertConstructableStyleSheet(content, target);
7601
+ } else {
7602
+ // Fall back to <style> element
7603
+ insertStyleElement(content, target);
7604
+ }
7605
+ },
7606
+
7445
7607
  assertInstanceOfHTMLElement(elm, msg) {
7446
7608
  assert.invariant(elm instanceof HTMLElement, msg);
7447
7609
  },
@@ -7671,7 +7833,7 @@ function isNodeFromTemplate(node) {
7671
7833
  return false;
7672
7834
  }
7673
7835
 
7674
- if (renderer.syntheticShadow) {
7836
+ if (renderer.isSyntheticShadowDefined) {
7675
7837
  // TODO [#1252]: old behavior that is still used by some pieces of the platform,
7676
7838
  // specifically, nodes inserted manually on places where `lwc:dom="manual"` directive is not
7677
7839
  // used, will be considered global elements.
@@ -7724,6 +7886,6 @@ defineProperty(LightningElement, 'CustomElementConstructor', {
7724
7886
  });
7725
7887
  freeze(LightningElement);
7726
7888
  seal(LightningElement.prototype);
7727
- /* version: 2.3.3 */
7889
+ /* version: 2.5.0 */
7728
7890
 
7729
7891
  export { LightningElement, profilerControl as __unstable__ProfilerControl, api$1 as api, deprecatedBuildCustomElementConstructor as buildCustomElementConstructor, createContextProvider, createElement, getComponentConstructor, getComponentDef, isComponentConstructor, isNodeFromTemplate, readonly, register, registerComponent, registerDecorators, registerTemplate, sanitizeAttribute, setFeatureFlag, setFeatureFlagForTest, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };