lwc 2.3.4 → 2.5.1

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 +389 -174
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +389 -174
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +2 -2
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +359 -137
  5. package/dist/engine-dom/iife/es5/engine-dom.js +404 -198
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +2 -2
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +372 -159
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +389 -174
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +2 -2
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +359 -137
  11. package/dist/engine-dom/umd/es5/engine-dom.js +404 -198
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +2 -2
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +372 -159
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +333 -181
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +2 -2
  16. package/dist/engine-server/esm/es2017/engine-server.js +333 -181
  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
@@ -108,6 +108,10 @@ function isFalse(obj) {
108
108
  return obj === false;
109
109
  }
110
110
 
111
+ function isBoolean(obj) {
112
+ return typeof obj === 'boolean';
113
+ }
114
+
111
115
  function isFunction$1(obj) {
112
116
  return typeof obj === 'function';
113
117
  }
@@ -242,17 +246,10 @@ const _globalThis = /*@__PURE__*/function () {
242
246
 
243
247
  return _globalThis;
244
248
  }();
245
- /*
246
- * Copyright (c) 2018, salesforce.com, inc.
247
- * All rights reserved.
248
- * SPDX-License-Identifier: MIT
249
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
250
- */
251
-
252
249
 
253
- const KEY__IS_NATIVE_SHADOW_ROOT_DEFINED = '$isNativeShadowRootDefined$';
254
250
  const KEY__SHADOW_RESOLVER = '$shadowResolver$';
255
251
  const KEY__SYNTHETIC_MODE = '$$lwc-synthetic-mode';
252
+ const KEY__SCOPED_CSS = '$scoped$';
256
253
  /*
257
254
  * Copyright (c) 2020, salesforce.com, inc.
258
255
  * All rights reserved.
@@ -342,7 +339,7 @@ function htmlPropertyToAttribute(propName) {
342
339
  CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName);
343
340
  return attributeName;
344
341
  }
345
- /** version: 2.3.4 */
342
+ /** version: 2.5.1 */
346
343
 
347
344
  /*
348
345
  * Copyright (c) 2020, salesforce.com, inc.
@@ -388,19 +385,33 @@ if (typeof Event !== 'function' && typeof CustomEvent !== 'function') {
388
385
  */
389
386
 
390
387
 
388
+ const features = {
389
+ ENABLE_REACTIVE_SETTER: null,
390
+ ENABLE_HMR: null,
391
+ ENABLE_INNER_OUTER_TEXT_PATCH: null,
392
+ ENABLE_ELEMENT_PATCH: null,
393
+ ENABLE_NODE_LIST_PATCH: null,
394
+ ENABLE_HTML_COLLECTIONS_PATCH: null,
395
+ ENABLE_NODE_PATCH: null,
396
+ ENABLE_NON_COMPOSED_EVENTS_LEAKAGE: null,
397
+ ENABLE_MIXED_SHADOW_MODE: null,
398
+ ENABLE_WIRE_SYNC_EMIT: null
399
+ };
400
+
391
401
  if (!_globalThis.lwcRuntimeFlags) {
392
402
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', {
393
403
  value: create(null)
394
404
  });
395
405
  }
396
406
 
397
- const runtimeFlags = _globalThis.lwcRuntimeFlags; // This function is not supported for use within components and is meant for
398
- // configuring runtime feature flags during app initialization.
407
+ const runtimeFlags = _globalThis.lwcRuntimeFlags;
408
+ /**
409
+ * Set the value at runtime of a given feature flag. This method only be invoked once per feature
410
+ * flag. It is meant to be used during the app initialization.
411
+ */
399
412
 
400
413
  function setFeatureFlag(name, value) {
401
- const isBoolean = isTrue(value) || isFalse(value);
402
-
403
- if (!isBoolean) {
414
+ if (!isBoolean(value)) {
404
415
  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.`;
405
416
 
406
417
  if (process.env.NODE_ENV !== 'production') {
@@ -412,9 +423,10 @@ function setFeatureFlag(name, value) {
412
423
  }
413
424
  }
414
425
 
415
- if (isUndefined$1(featureFlagLookup[name])) {
416
- // eslint-disable-next-line no-console
417
- 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.`);
426
+ if (isUndefined$1(features[name])) {
427
+ const availableFlags = keys(features).map(name => `"${name}"`).join(', '); // eslint-disable-next-line no-console
428
+
429
+ console.warn(`Failed to set the value "${value}" for the runtime feature flag "${name}" because it is undefined. Available flags: ${availableFlags}.`);
418
430
  return;
419
431
  }
420
432
 
@@ -431,37 +443,23 @@ function setFeatureFlag(name, value) {
431
443
  return;
432
444
  }
433
445
 
434
- Object.defineProperty(runtimeFlags, name, {
446
+ defineProperty(runtimeFlags, name, {
435
447
  value
436
448
  });
437
449
  }
438
- } // This function is exposed to components to facilitate testing so we add a
439
- // check to make sure it is not invoked in production.
450
+ }
451
+ /**
452
+ * Set the value at runtime of a given feature flag. This method should only be used for testing
453
+ * purposes. It is a no-op when invoked in production mode.
454
+ */
440
455
 
441
456
 
442
457
  function setFeatureFlagForTest(name, value) {
443
458
  if (process.env.NODE_ENV !== 'production') {
444
- return setFeatureFlag(name, value);
459
+ setFeatureFlag(name, value);
445
460
  }
446
461
  }
447
-
448
- const featureFlagLookup = {
449
- ENABLE_REACTIVE_SETTER: null,
450
- ENABLE_HMR: null,
451
- // Flag to toggle on/off the enforcement of innerText/outerText shadow dom semantic in elements when using synthetic shadow.
452
- // Note: Once active, elements outside the lwc boundary are controlled by the ENABLE_ELEMENT_PATCH flag.
453
- ENABLE_INNER_OUTER_TEXT_PATCH: null,
454
- // Flags to toggle on/off the enforcement of shadow dom semantic in element/node outside lwc boundary when using synthetic shadow.
455
- ENABLE_ELEMENT_PATCH: null,
456
- ENABLE_NODE_LIST_PATCH: null,
457
- ENABLE_HTML_COLLECTIONS_PATCH: null,
458
- ENABLE_NODE_PATCH: null,
459
- // Disables the fix for #2121 where non-composed events are visible outside of their shadow root.
460
- ENABLE_NON_COMPOSED_EVENTS_LEAKAGE: null,
461
- ENABLE_LIGHT_DOM_COMPONENTS: null,
462
- ENABLE_MIXED_SHADOW_MODE: null
463
- };
464
- /** version: 2.3.4 */
462
+ /** version: 2.5.1 */
465
463
 
466
464
  /* proxy-compat-disable */
467
465
 
@@ -472,6 +470,7 @@ const featureFlagLookup = {
472
470
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
473
471
  */
474
472
 
473
+
475
474
  let nextTickCallbackQueue = [];
476
475
  const SPACE_CHAR = 32;
477
476
  const EmptyObject = seal(create(null));
@@ -2792,12 +2791,6 @@ const LightningElement = function () {
2792
2791
  associateVM(component, vm);
2793
2792
  associateVM(elm, vm);
2794
2793
 
2795
- if (!runtimeFlags.ENABLE_LIGHT_DOM_COMPONENTS) {
2796
- assert.isTrue(def.renderMode !== 0
2797
- /* Light */
2798
- , `${def.name || 'Anonymous class'} is an invalid LWC component. Light DOM components are not available in this environment.`);
2799
- }
2800
-
2801
2794
  if (vm.renderMode === 1
2802
2795
  /* Shadow */
2803
2796
  ) {
@@ -2836,6 +2829,12 @@ function attachShadow(vm) {
2836
2829
  if (process.env.NODE_ENV !== 'production') {
2837
2830
  patchShadowRootWithRestrictions(cmpRoot);
2838
2831
  }
2832
+ }
2833
+
2834
+ function warnIfInvokedDuringConstruction(vm, methodName) {
2835
+ if (isBeingConstructed(vm)) {
2836
+ 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.`);
2837
+ }
2839
2838
  } // @ts-ignore
2840
2839
 
2841
2840
 
@@ -2994,7 +2993,7 @@ LightningElement.prototype = {
2994
2993
  } = vm;
2995
2994
 
2996
2995
  if (process.env.NODE_ENV !== 'production') {
2997
- 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.`);
2996
+ warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect');
2998
2997
  }
2999
2998
 
3000
2999
  return getBoundingClientRect(elm);
@@ -3010,7 +3009,7 @@ LightningElement.prototype = {
3010
3009
  } = vm;
3011
3010
 
3012
3011
  if (process.env.NODE_ENV !== 'production') {
3013
- 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.`);
3012
+ warnIfInvokedDuringConstruction(vm, 'querySelector');
3014
3013
  }
3015
3014
 
3016
3015
  return querySelector(elm, selectors);
@@ -3026,7 +3025,7 @@ LightningElement.prototype = {
3026
3025
  } = vm;
3027
3026
 
3028
3027
  if (process.env.NODE_ENV !== 'production') {
3029
- 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.`);
3028
+ warnIfInvokedDuringConstruction(vm, 'querySelectorAll');
3030
3029
  }
3031
3030
 
3032
3031
  return querySelectorAll(elm, selectors);
@@ -3042,7 +3041,7 @@ LightningElement.prototype = {
3042
3041
  } = vm;
3043
3042
 
3044
3043
  if (process.env.NODE_ENV !== 'production') {
3045
- 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.`);
3044
+ warnIfInvokedDuringConstruction(vm, 'getElementsByTagName');
3046
3045
  }
3047
3046
 
3048
3047
  return getElementsByTagName(elm, tagNameOrWildCard);
@@ -3058,7 +3057,7 @@ LightningElement.prototype = {
3058
3057
  } = vm;
3059
3058
 
3060
3059
  if (process.env.NODE_ENV !== 'production') {
3061
- 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.`);
3060
+ warnIfInvokedDuringConstruction(vm, 'getElementsByClassName');
3062
3061
  }
3063
3062
 
3064
3063
  return getElementsByClassName(elm, names);
@@ -3431,18 +3430,33 @@ function createObservedFieldPropertyDescriptor(key) {
3431
3430
 
3432
3431
  function getClassDescriptorType(descriptor) {
3433
3432
  if (isFunction$1(descriptor.value)) {
3434
- return 'method';
3433
+ return "method"
3434
+ /* Method */
3435
+ ;
3435
3436
  } else if (isFunction$1(descriptor.set) || isFunction$1(descriptor.get)) {
3436
- return 'accessor';
3437
+ return "accessor"
3438
+ /* Accessor */
3439
+ ;
3437
3440
  } else {
3438
- return 'field';
3441
+ return "field"
3442
+ /* Field */
3443
+ ;
3439
3444
  }
3440
3445
  }
3441
3446
 
3442
3447
  function validateObservedField(Ctor, fieldName, descriptor) {
3443
3448
  if (!isUndefined$1(descriptor)) {
3444
3449
  const type = getClassDescriptorType(descriptor);
3445
- assert.fail(`Invalid observed ${fieldName} field. Found a duplicate ${type} with the same name.`);
3450
+ const message = `Invalid observed ${fieldName} field. Found a duplicate ${type} with the same name.`; // [W-9927596] Ideally we always throw an error when detecting duplicate observed field.
3451
+ // This branch is only here for backward compatibility reasons.
3452
+
3453
+ if (type === "accessor"
3454
+ /* Accessor */
3455
+ ) {
3456
+ logError(message);
3457
+ } else {
3458
+ assert.fail(message);
3459
+ }
3446
3460
  }
3447
3461
  }
3448
3462
 
@@ -3469,7 +3483,16 @@ function validateMethodDecoratedWithWire(Ctor, methodName, descriptor) {
3469
3483
  function validateFieldDecoratedWithApi(Ctor, fieldName, descriptor) {
3470
3484
  if (!isUndefined$1(descriptor)) {
3471
3485
  const type = getClassDescriptorType(descriptor);
3472
- assert.fail(`Invalid @api ${fieldName} field. Found a duplicate ${type} with the same name.`);
3486
+ const message = `Invalid @api ${fieldName} field. Found a duplicate ${type} with the same name.`; // [W-9927596] Ideally we always throw an error when detecting duplicate public properties.
3487
+ // This branch is only here for backward compatibility reasons.
3488
+
3489
+ if (type === "accessor"
3490
+ /* Accessor */
3491
+ ) {
3492
+ logError(message);
3493
+ } else {
3494
+ assert.fail(message);
3495
+ }
3473
3496
  }
3474
3497
  }
3475
3498
 
@@ -3532,9 +3555,16 @@ function registerDecorators(Ctor, meta) {
3532
3555
  // field declaration
3533
3556
  if (process.env.NODE_ENV !== 'production') {
3534
3557
  validateFieldDecoratedWithApi(Ctor, fieldName, descriptor);
3535
- }
3558
+ } // [W-9927596] If a component has both a public property and a private setter/getter
3559
+ // with the same name, the property is defined as a public accessor. This branch is
3560
+ // only here for backward compatibility reasons.
3536
3561
 
3537
- descriptor = createPublicPropertyDescriptor(fieldName);
3562
+
3563
+ if (!isUndefined$1(descriptor) && !isUndefined$1(descriptor.get)) {
3564
+ descriptor = createPublicAccessorDescriptor(fieldName, descriptor);
3565
+ } else {
3566
+ descriptor = createPublicPropertyDescriptor(fieldName);
3567
+ }
3538
3568
  }
3539
3569
 
3540
3570
  apiFields[fieldName] = descriptor;
@@ -3614,9 +3644,16 @@ function registerDecorators(Ctor, meta) {
3614
3644
 
3615
3645
  if (process.env.NODE_ENV !== 'production') {
3616
3646
  validateObservedField(Ctor, fieldName, descriptor);
3617
- }
3647
+ } // [W-9927596] Only mark a field as observed whenever it isn't a duplicated public nor
3648
+ // tracked property. This is only here for backward compatibility purposes.
3649
+
3618
3650
 
3619
- observedFields[fieldName] = createObservedFieldPropertyDescriptor(fieldName);
3651
+ const isDuplicatePublicProp = !isUndefined$1(publicProps) && fieldName in publicProps;
3652
+ const isDuplicateTrackedProp = !isUndefined$1(track) && fieldName in track;
3653
+
3654
+ if (!isDuplicatePublicProp && !isDuplicateTrackedProp) {
3655
+ observedFields[fieldName] = createObservedFieldPropertyDescriptor(fieldName);
3656
+ }
3620
3657
  }
3621
3658
  }
3622
3659
 
@@ -4348,6 +4385,19 @@ function observeElementChildNodes(elm) {
4348
4385
 
4349
4386
  function setElementShadowToken(elm, token) {
4350
4387
  elm.$shadowToken$ = token;
4388
+ } // Set the scope token class for *.scoped.css styles
4389
+
4390
+
4391
+ function setScopeTokenClassIfNecessary(elm, owner) {
4392
+ const {
4393
+ cmpTemplate,
4394
+ context
4395
+ } = owner;
4396
+ const token = cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken;
4397
+
4398
+ if (!isUndefined$1(token) && context.hasScopedStyles) {
4399
+ owner.renderer.getClassList(elm).add(token);
4400
+ }
4351
4401
  }
4352
4402
 
4353
4403
  function updateNodeHook(oldVnode, vnode) {
@@ -4421,6 +4471,7 @@ function fallbackElmHook(elm, vnode) {
4421
4471
  const {
4422
4472
  owner
4423
4473
  } = vnode;
4474
+ setScopeTokenClassIfNecessary(elm, owner);
4424
4475
 
4425
4476
  if (owner.shadowMode === 1
4426
4477
  /* Synthetic */
@@ -4431,7 +4482,7 @@ function fallbackElmHook(elm, vnode) {
4431
4482
  }
4432
4483
  } = vnode;
4433
4484
  const {
4434
- shadowAttribute
4485
+ stylesheetToken
4435
4486
  } = owner.context;
4436
4487
 
4437
4488
  if (!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
@@ -4443,7 +4494,7 @@ function fallbackElmHook(elm, vnode) {
4443
4494
  // into each element from the template, so they can be styled accordingly.
4444
4495
 
4445
4496
 
4446
- setElementShadowToken(elm, shadowAttribute);
4497
+ setElementShadowToken(elm, stylesheetToken);
4447
4498
  }
4448
4499
 
4449
4500
  if (process.env.NODE_ENV !== 'production') {
@@ -4532,16 +4583,17 @@ function createViewModelHook(elm, vnode) {
4532
4583
  ctor,
4533
4584
  owner
4534
4585
  } = vnode;
4586
+ setScopeTokenClassIfNecessary(elm, owner);
4535
4587
 
4536
4588
  if (owner.shadowMode === 1
4537
4589
  /* Synthetic */
4538
4590
  ) {
4539
4591
  const {
4540
- shadowAttribute
4592
+ stylesheetToken
4541
4593
  } = owner.context; // when running in synthetic shadow mode, we need to set the shadowToken value
4542
4594
  // into each element from the template, so they can be styled accordingly.
4543
4595
 
4544
- setElementShadowToken(elm, shadowAttribute);
4596
+ setElementShadowToken(elm, stylesheetToken);
4545
4597
  }
4546
4598
 
4547
4599
  const def = getComponentInternalDef(ctor);
@@ -4841,13 +4893,19 @@ const CustomElementHook = {
4841
4893
 
4842
4894
  function linkNodeToShadow(elm, owner) {
4843
4895
  const {
4896
+ renderer,
4897
+ renderMode,
4844
4898
  shadowMode
4845
4899
  } = owner; // TODO [#1164]: this should eventually be done by the polyfill directly
4846
4900
 
4847
- if (shadowMode === 1
4848
- /* Synthetic */
4849
- ) {
4850
- elm[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
4901
+ if (renderer.isSyntheticShadowDefined) {
4902
+ if (shadowMode === 1
4903
+ /* Synthetic */
4904
+ || renderMode === 0
4905
+ /* Light */
4906
+ ) {
4907
+ elm[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
4908
+ }
4851
4909
  }
4852
4910
  }
4853
4911
 
@@ -5193,14 +5251,11 @@ function gid(id) {
5193
5251
 
5194
5252
  const {
5195
5253
  idx,
5196
- renderMode,
5197
5254
  shadowMode
5198
5255
  } = vmBeingRendered;
5199
5256
 
5200
5257
  if (shadowMode === 1
5201
5258
  /* Synthetic */
5202
- && renderMode === 1
5203
- /* Shadow */
5204
5259
  ) {
5205
5260
  return StringReplace.call(id, /\S+/g, id => `${id}-${idx}`);
5206
5261
  }
@@ -5229,14 +5284,11 @@ function fid(url) {
5229
5284
 
5230
5285
  const {
5231
5286
  idx,
5232
- renderMode,
5233
5287
  shadowMode
5234
5288
  } = vmBeingRendered; // Apply transformation only for fragment-only-urls, and only in shadow DOM
5235
5289
 
5236
5290
  if (shadowMode === 1
5237
5291
  /* Synthetic */
5238
- && renderMode === 1
5239
- /* Shadow */
5240
5292
  && /^#/.test(url)) {
5241
5293
  return `${url}-${idx}`;
5242
5294
  }
@@ -5337,6 +5389,10 @@ var api = /*#__PURE__*/Object.freeze({
5337
5389
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5338
5390
  */
5339
5391
 
5392
+ function makeHostToken(token) {
5393
+ return `${token}-host`;
5394
+ }
5395
+
5340
5396
  function createInlineStyleVNode(content) {
5341
5397
  return h('style', {
5342
5398
  key: 'style',
@@ -5346,59 +5402,100 @@ function createInlineStyleVNode(content) {
5346
5402
  }, [t(content)]);
5347
5403
  }
5348
5404
 
5349
- function updateSyntheticShadowAttributes(vm, template) {
5405
+ function updateStylesheetToken(vm, template) {
5350
5406
  const {
5351
5407
  elm,
5352
5408
  context,
5353
5409
  renderer,
5354
- renderMode
5410
+ renderMode,
5411
+ shadowMode
5355
5412
  } = vm;
5356
5413
  const {
5357
5414
  stylesheets: newStylesheets,
5358
- stylesheetTokens: newStylesheetTokens
5415
+ stylesheetToken: newStylesheetToken
5359
5416
  } = template;
5360
- let newTokens; // Reset the styling token applied to the host element.
5417
+ const isSyntheticShadow = renderMode === 1
5418
+ /* Shadow */
5419
+ && shadowMode === 1
5420
+ /* Synthetic */
5421
+ ;
5422
+ const {
5423
+ hasScopedStyles
5424
+ } = context;
5425
+ let newToken;
5426
+ let newHasTokenInClass;
5427
+ let newHasTokenInAttribute; // Reset the styling token applied to the host element.
5428
+
5429
+ const {
5430
+ stylesheetToken: oldToken,
5431
+ hasTokenInClass: oldHasTokenInClass,
5432
+ hasTokenInAttribute: oldHasTokenInAttribute
5433
+ } = context;
5361
5434
 
5362
- const oldHostAttribute = context.hostAttribute;
5435
+ if (oldHasTokenInClass) {
5436
+ renderer.getClassList(elm).remove(makeHostToken(oldToken));
5437
+ }
5363
5438
 
5364
- if (!isUndefined$1(oldHostAttribute)) {
5365
- renderer.removeAttribute(elm, oldHostAttribute);
5439
+ if (oldHasTokenInAttribute) {
5440
+ renderer.removeAttribute(elm, makeHostToken(oldToken));
5366
5441
  } // Apply the new template styling token to the host element, if the new template has any
5367
- // associated stylesheets.
5442
+ // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
5368
5443
 
5369
5444
 
5370
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0 && renderMode === 1
5371
- /* Shadow */
5372
- ) {
5373
- newTokens = newStylesheetTokens;
5374
- }
5445
+ if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
5446
+ newToken = newStylesheetToken;
5447
+ } // Set the new styling token on the host element
5448
+
5449
+
5450
+ if (!isUndefined$1(newToken)) {
5451
+ if (hasScopedStyles) {
5452
+ renderer.getClassList(elm).add(makeHostToken(newToken));
5453
+ newHasTokenInClass = true;
5454
+ }
5375
5455
 
5376
- if (!isUndefined$1(newTokens)) {
5377
- renderer.setAttribute(elm, newTokens.hostAttribute, '');
5456
+ if (isSyntheticShadow) {
5457
+ renderer.setAttribute(elm, makeHostToken(newToken), '');
5458
+ newHasTokenInAttribute = true;
5459
+ }
5378
5460
  } // Update the styling tokens present on the context object.
5379
5461
 
5380
5462
 
5381
- context.hostAttribute = newTokens === null || newTokens === void 0 ? void 0 : newTokens.hostAttribute;
5382
- context.shadowAttribute = newTokens === null || newTokens === void 0 ? void 0 : newTokens.shadowAttribute;
5463
+ context.stylesheetToken = newToken;
5464
+ context.hasTokenInClass = newHasTokenInClass;
5465
+ context.hasTokenInAttribute = newHasTokenInAttribute;
5383
5466
  }
5384
5467
 
5385
- function evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, nativeShadow) {
5468
+ function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
5386
5469
  const content = [];
5387
5470
 
5388
5471
  for (let i = 0; i < stylesheets.length; i++) {
5389
5472
  let stylesheet = stylesheets[i];
5390
5473
 
5391
5474
  if (isArray$1(stylesheet)) {
5392
- ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, hostSelector, shadowSelector, nativeShadow));
5475
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
5393
5476
  } else {
5394
5477
  if (process.env.NODE_ENV !== 'production') {
5395
5478
  // in dev-mode, we support hot swapping of stylesheet, which means that
5396
5479
  // the component instance might be attempting to use an old version of
5397
5480
  // the stylesheet, while internally, we have a replacement for it.
5398
5481
  stylesheet = getStyleOrSwappedStyle(stylesheet);
5399
- }
5482
+ } // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
5483
+ // native shadow DOM. Synthetic shadow DOM never uses `:host`.
5484
+
5400
5485
 
5401
- ArrayPush$1.call(content, stylesheet(hostSelector, shadowSelector, nativeShadow));
5486
+ const isScopedCss = stylesheet[KEY__SCOPED_CSS];
5487
+ const useActualHostSelector = vm.renderMode === 0
5488
+ /* Light */
5489
+ ? !isScopedCss : vm.shadowMode === 0
5490
+ /* Native */
5491
+ ; // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
5492
+
5493
+ const scopeToken = isScopedCss || vm.shadowMode === 1
5494
+ /* Synthetic */
5495
+ && vm.renderMode === 1
5496
+ /* Shadow */
5497
+ ? stylesheetToken : undefined;
5498
+ ArrayPush$1.call(content, stylesheet(useActualHostSelector, scopeToken));
5402
5499
  }
5403
5500
  }
5404
5501
 
@@ -5408,37 +5505,36 @@ function evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, n
5408
5505
  function getStylesheetsContent(vm, template) {
5409
5506
  const {
5410
5507
  stylesheets,
5411
- stylesheetTokens
5508
+ stylesheetToken
5412
5509
  } = template;
5413
- const {
5414
- renderMode,
5415
- shadowMode
5416
- } = vm;
5417
5510
  let content = [];
5418
5511
 
5419
5512
  if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
5420
- let hostSelector;
5421
- let shadowSelector; // Scoping with the tokens is only necessary for synthetic shadow. For both
5422
- // light DOM elements and native shadow, we just render the CSS as-is.
5513
+ content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
5514
+ }
5515
+
5516
+ return content;
5517
+ } // It might be worth caching this to avoid doing the lookup repeatedly, but
5518
+ // perf testing has not shown it to be a huge improvement yet:
5519
+ // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
5520
+
5423
5521
 
5424
- if (renderMode === 1
5522
+ function getNearestNativeShadowComponent(vm) {
5523
+ let owner = vm;
5524
+
5525
+ while (!isNull(owner)) {
5526
+ if (owner.renderMode === 1
5425
5527
  /* Shadow */
5426
- && shadowMode === 1
5427
- /* Synthetic */
5428
- && !isUndefined$1(stylesheetTokens)) {
5429
- hostSelector = `[${stylesheetTokens.hostAttribute}]`;
5430
- shadowSelector = `[${stylesheetTokens.shadowAttribute}]`;
5431
- } else {
5432
- hostSelector = '';
5433
- shadowSelector = '';
5528
+ && owner.shadowMode === 0
5529
+ /* Native */
5530
+ ) {
5531
+ return owner;
5434
5532
  }
5435
5533
 
5436
- content = evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, shadowMode === 0
5437
- /* Native */
5438
- );
5534
+ owner = owner.owner;
5439
5535
  }
5440
5536
 
5441
- return content;
5537
+ return owner;
5442
5538
  }
5443
5539
 
5444
5540
  function createStylesheet(vm, stylesheets) {
@@ -5456,13 +5552,26 @@ function createStylesheet(vm, stylesheets) {
5456
5552
  for (let i = 0; i < stylesheets.length; i++) {
5457
5553
  renderer.insertGlobalStylesheet(stylesheets[i]);
5458
5554
  }
5459
-
5460
- return null;
5461
- } else {
5462
- // native shadow or light DOM
5555
+ } else if (renderer.ssr) {
5556
+ // native shadow or light DOM, SSR
5463
5557
  const combinedStylesheetContent = ArrayJoin.call(stylesheets, '\n');
5464
5558
  return createInlineStyleVNode(combinedStylesheetContent);
5559
+ } else {
5560
+ // native shadow or light DOM, DOM renderer
5561
+ const root = getNearestNativeShadowComponent(vm);
5562
+ const isGlobal = isNull(root);
5563
+
5564
+ for (let i = 0; i < stylesheets.length; i++) {
5565
+ if (isGlobal) {
5566
+ renderer.insertGlobalStylesheet(stylesheets[i]);
5567
+ } else {
5568
+ // local level
5569
+ renderer.insertStylesheet(stylesheets[i], root.cmpRoot);
5570
+ }
5571
+ }
5465
5572
  }
5573
+
5574
+ return null;
5466
5575
  }
5467
5576
  /*
5468
5577
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5616,8 +5725,7 @@ function evaluateTemplate(vm, html) {
5616
5725
  context,
5617
5726
  cmpSlots,
5618
5727
  cmpTemplate,
5619
- tro,
5620
- shadowMode
5728
+ tro
5621
5729
  } = vm;
5622
5730
  tro.observe(() => {
5623
5731
  // Reset the cache memoizer for template when needed.
@@ -5642,15 +5750,12 @@ function evaluateTemplate(vm, html) {
5642
5750
 
5643
5751
  vm.cmpTemplate = html; // Create a brand new template cache for the swapped templated.
5644
5752
 
5645
- context.tplCache = create(null); // Update the synthetic shadow attributes on the host element if necessary.
5753
+ context.tplCache = create(null); // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
5646
5754
 
5647
- if (shadowMode === 1
5648
- /* Synthetic */
5649
- ) {
5650
- updateSyntheticShadowAttributes(vm, html);
5651
- } // Evaluate, create stylesheet and cache the produced VNode for future
5652
- // re-rendering.
5755
+ context.hasScopedStyles = computeHasScopedStyles(html); // Update the scoping token on the host element.
5653
5756
 
5757
+ updateStylesheetToken(vm, html); // Evaluate, create stylesheet and cache the produced VNode for future
5758
+ // re-rendering.
5654
5759
 
5655
5760
  const stylesheetsContent = getStylesheetsContent(vm, html);
5656
5761
  context.styleVNode = stylesheetsContent.length === 0 ? null : createStylesheet(vm, stylesheetsContent);
@@ -5692,6 +5797,22 @@ function evaluateTemplate(vm, html) {
5692
5797
 
5693
5798
  return vnodes;
5694
5799
  }
5800
+
5801
+ function computeHasScopedStyles(template) {
5802
+ const {
5803
+ stylesheets
5804
+ } = template;
5805
+
5806
+ if (!isUndefined$1(stylesheets)) {
5807
+ for (let i = 0; i < stylesheets.length; i++) {
5808
+ if (isTrue(stylesheets[i][KEY__SCOPED_CSS])) {
5809
+ return true;
5810
+ }
5811
+ }
5812
+ }
5813
+
5814
+ return false;
5815
+ }
5695
5816
  /*
5696
5817
  * Copyright (c) 2018, salesforce.com, inc.
5697
5818
  * All rights reserved.
@@ -5963,7 +6084,6 @@ function invokeServiceHook(vm, cbs) {
5963
6084
  */
5964
6085
 
5965
6086
 
5966
- const isNativeShadowRootDefined = _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED];
5967
6087
  let idx = 0;
5968
6088
  /** The internal slot used to associate different objects the engine manipulates with the VM */
5969
6089
 
@@ -6072,29 +6192,6 @@ function getNearestShadowAncestor(vm) {
6072
6192
  return ancestor;
6073
6193
  }
6074
6194
 
6075
- function assertNotSyntheticComposedWithinNative(vm) {
6076
- const isSynthetic = vm.renderMode === 1
6077
- /* Shadow */
6078
- && vm.shadowMode === 1
6079
- /* Synthetic */
6080
- ;
6081
-
6082
- if (!isSynthetic) {
6083
- return;
6084
- }
6085
-
6086
- const ancestor = getNearestShadowAncestor(vm);
6087
-
6088
- if (!isNull(ancestor)) {
6089
- // Any native shadow component being an ancestor of a synthetic shadow component is disallowed.
6090
- assert.isFalse(ancestor.renderMode === 1
6091
- /* Shadow */
6092
- && ancestor.shadowMode === 0
6093
- /* Native */
6094
- , `${getComponentTag(vm)} (synthetic shadow DOM) cannot be composed inside of ${getComponentTag(ancestor)} (native shadow DOM), because synthetic-within-native composition is disallowed`);
6095
- }
6096
- }
6097
-
6098
6195
  function createVM(elm, def, options) {
6099
6196
  const {
6100
6197
  mode,
@@ -6102,22 +6199,6 @@ function createVM(elm, def, options) {
6102
6199
  renderer,
6103
6200
  tagName
6104
6201
  } = options;
6105
- let shadowMode;
6106
-
6107
- if (renderer.syntheticShadow) {
6108
- shadowMode = def.shadowSupportMode === "any"
6109
- /* Any */
6110
- && isNativeShadowRootDefined ? 0
6111
- /* Native */
6112
- : 1
6113
- /* Synthetic */
6114
- ;
6115
- } else {
6116
- shadowMode = 0
6117
- /* Native */
6118
- ;
6119
- }
6120
-
6121
6202
  const vm = {
6122
6203
  elm,
6123
6204
  def,
@@ -6140,10 +6221,12 @@ function createVM(elm, def, options) {
6140
6221
  oar: create(null),
6141
6222
  cmpTemplate: null,
6142
6223
  renderMode: def.renderMode,
6143
- shadowMode,
6224
+ shadowMode: null,
6144
6225
  context: {
6145
- hostAttribute: undefined,
6146
- shadowAttribute: undefined,
6226
+ stylesheetToken: undefined,
6227
+ hasTokenInClass: undefined,
6228
+ hasTokenInAttribute: undefined,
6229
+ hasScopedStyles: undefined,
6147
6230
  styleVNode: null,
6148
6231
  tplCache: EmptyObject,
6149
6232
  wiredConnecting: EmptyArray,
@@ -6156,26 +6239,87 @@ function createVM(elm, def, options) {
6156
6239
  setHook,
6157
6240
  getHook
6158
6241
  };
6242
+ vm.shadowMode = computeShadowMode(vm);
6159
6243
  vm.tro = getTemplateReactiveObserver(vm);
6160
6244
 
6161
6245
  if (process.env.NODE_ENV !== 'production') {
6162
6246
  vm.toString = () => {
6163
6247
  return `[object:vm ${def.name} (${vm.idx})]`;
6164
6248
  };
6165
-
6166
- assertNotSyntheticComposedWithinNative(vm);
6167
6249
  } // Create component instance associated to the vm and the element.
6168
6250
 
6169
6251
 
6170
6252
  invokeComponentConstructor(vm, def.ctor); // Initializing the wire decorator per instance only when really needed
6171
6253
 
6172
- if (isFalse(renderer.ssr) && hasWireAdapters(vm)) {
6254
+ if (hasWireAdapters(vm)) {
6173
6255
  installWireAdapters(vm);
6174
6256
  }
6175
6257
 
6176
6258
  return vm;
6177
6259
  }
6178
6260
 
6261
+ function computeShadowMode(vm) {
6262
+ const {
6263
+ def,
6264
+ renderer
6265
+ } = vm;
6266
+ const {
6267
+ isNativeShadowDefined,
6268
+ isSyntheticShadowDefined
6269
+ } = renderer;
6270
+ let shadowMode;
6271
+
6272
+ if (isSyntheticShadowDefined) {
6273
+ if (def.renderMode === 0
6274
+ /* Light */
6275
+ ) {
6276
+ // ShadowMode.Native implies "not synthetic shadow" which is consistent with how
6277
+ // everything defaults to native when the synthetic shadow polyfill is unavailable.
6278
+ shadowMode = 0
6279
+ /* Native */
6280
+ ;
6281
+ } else if (isNativeShadowDefined) {
6282
+ if (def.shadowSupportMode === "any"
6283
+ /* Any */
6284
+ ) {
6285
+ shadowMode = 0
6286
+ /* Native */
6287
+ ;
6288
+ } else {
6289
+ const shadowAncestor = getNearestShadowAncestor(vm);
6290
+
6291
+ if (!isNull(shadowAncestor) && shadowAncestor.shadowMode === 0
6292
+ /* Native */
6293
+ ) {
6294
+ // Transitive support for native Shadow DOM. A component in native mode
6295
+ // transitively opts all of its descendants into native.
6296
+ shadowMode = 0
6297
+ /* Native */
6298
+ ;
6299
+ } else {
6300
+ // Synthetic if neither this component nor any of its ancestors are configured
6301
+ // to be native.
6302
+ shadowMode = 1
6303
+ /* Synthetic */
6304
+ ;
6305
+ }
6306
+ }
6307
+ } else {
6308
+ // Synthetic if there is no native Shadow DOM support.
6309
+ shadowMode = 1
6310
+ /* Synthetic */
6311
+ ;
6312
+ }
6313
+ } else {
6314
+ // Native if the synthetic shadow polyfill is unavailable.
6315
+ shadowMode = 0
6316
+ /* Native */
6317
+ ;
6318
+ }
6319
+
6320
+ return shadowMode;
6321
+ }
6322
+
6179
6323
  function assertIsVM(obj) {
6180
6324
  if (isNull(obj) || !isObject(obj) || !('cmpRoot' in obj)) {
6181
6325
  throw new TypeError(`${obj} is not a VM.`);
@@ -6899,11 +7043,14 @@ function installWireAdapters(vm) {
6899
7043
  ArrayPush$1.call(wiredConnecting, () => {
6900
7044
  connector.connect();
6901
7045
 
6902
- if (hasDynamicParams) {
6903
- Promise.resolve().then(computeConfigAndUpdate);
6904
- } else {
6905
- computeConfigAndUpdate();
7046
+ if (!runtimeFlags.ENABLE_WIRE_SYNC_EMIT) {
7047
+ if (hasDynamicParams) {
7048
+ Promise.resolve().then(computeConfigAndUpdate);
7049
+ return;
7050
+ }
6906
7051
  }
7052
+
7053
+ computeConfigAndUpdate();
6907
7054
  });
6908
7055
  ArrayPush$1.call(wiredDisconnecting, () => {
6909
7056
  connector.disconnect();
@@ -7010,7 +7157,7 @@ function readonly(obj) {
7010
7157
 
7011
7158
  return reactiveMembrane.getReadOnlyProxy(obj);
7012
7159
  }
7013
- /* version: 2.3.4 */
7160
+ /* version: 2.5.1 */
7014
7161
 
7015
7162
  /*
7016
7163
  * Copyright (c) 2020, salesforce.com, inc.
@@ -7101,7 +7248,8 @@ class HTMLElement$1 {
7101
7248
 
7102
7249
  const renderer = {
7103
7250
  ssr: true,
7104
- syntheticShadow: false,
7251
+ isNativeShadowDefined: false,
7252
+ isSyntheticShadowDefined: false,
7105
7253
 
7106
7254
  insert(node, parent, anchor) {
7107
7255
  if (node.parent !== null && node.parent !== parent) {
@@ -7319,6 +7467,10 @@ const renderer = {
7319
7467
  // synthetic shadow.
7320
7468
  },
7321
7469
 
7470
+ insertStylesheet() {// Noop on SSR (for now). This need to be reevaluated whenever we will implement support for
7471
+ // synthetic shadow.
7472
+ },
7473
+
7322
7474
  addEventListener() {// Noop on SSR.
7323
7475
  },
7324
7476
 
@@ -7476,7 +7628,7 @@ function renderComponent(tagName, Ctor, props = {}) {
7476
7628
 
7477
7629
  freeze(LightningElement);
7478
7630
  seal(LightningElement.prototype);
7479
- /* version: 2.3.4 */
7631
+ /* version: 2.5.1 */
7480
7632
 
7481
7633
  exports.LightningElement = LightningElement;
7482
7634
  exports.api = api$1;