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
@@ -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
  }
@@ -238,17 +242,10 @@ const _globalThis = /*@__PURE__*/function () {
238
242
 
239
243
  return _globalThis;
240
244
  }();
241
- /*
242
- * Copyright (c) 2018, salesforce.com, inc.
243
- * All rights reserved.
244
- * SPDX-License-Identifier: MIT
245
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
246
- */
247
-
248
245
 
249
- const KEY__IS_NATIVE_SHADOW_ROOT_DEFINED = '$isNativeShadowRootDefined$';
250
246
  const KEY__SHADOW_RESOLVER = '$shadowResolver$';
251
247
  const KEY__SYNTHETIC_MODE = '$$lwc-synthetic-mode';
248
+ const KEY__SCOPED_CSS = '$scoped$';
252
249
  /*
253
250
  * Copyright (c) 2020, salesforce.com, inc.
254
251
  * All rights reserved.
@@ -338,7 +335,7 @@ function htmlPropertyToAttribute(propName) {
338
335
  CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName);
339
336
  return attributeName;
340
337
  }
341
- /** version: 2.3.4 */
338
+ /** version: 2.5.1 */
342
339
 
343
340
  /*
344
341
  * Copyright (c) 2020, salesforce.com, inc.
@@ -384,19 +381,33 @@ if (typeof Event !== 'function' && typeof CustomEvent !== 'function') {
384
381
  */
385
382
 
386
383
 
384
+ const features = {
385
+ ENABLE_REACTIVE_SETTER: null,
386
+ ENABLE_HMR: null,
387
+ ENABLE_INNER_OUTER_TEXT_PATCH: null,
388
+ ENABLE_ELEMENT_PATCH: null,
389
+ ENABLE_NODE_LIST_PATCH: null,
390
+ ENABLE_HTML_COLLECTIONS_PATCH: null,
391
+ ENABLE_NODE_PATCH: null,
392
+ ENABLE_NON_COMPOSED_EVENTS_LEAKAGE: null,
393
+ ENABLE_MIXED_SHADOW_MODE: null,
394
+ ENABLE_WIRE_SYNC_EMIT: null
395
+ };
396
+
387
397
  if (!_globalThis.lwcRuntimeFlags) {
388
398
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', {
389
399
  value: create(null)
390
400
  });
391
401
  }
392
402
 
393
- const runtimeFlags = _globalThis.lwcRuntimeFlags; // This function is not supported for use within components and is meant for
394
- // configuring runtime feature flags during app initialization.
403
+ const runtimeFlags = _globalThis.lwcRuntimeFlags;
404
+ /**
405
+ * Set the value at runtime of a given feature flag. This method only be invoked once per feature
406
+ * flag. It is meant to be used during the app initialization.
407
+ */
395
408
 
396
409
  function setFeatureFlag(name, value) {
397
- const isBoolean = isTrue(value) || isFalse(value);
398
-
399
- if (!isBoolean) {
410
+ if (!isBoolean(value)) {
400
411
  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.`;
401
412
 
402
413
  if (process.env.NODE_ENV !== 'production') {
@@ -408,9 +419,10 @@ function setFeatureFlag(name, value) {
408
419
  }
409
420
  }
410
421
 
411
- if (isUndefined$1(featureFlagLookup[name])) {
412
- // eslint-disable-next-line no-console
413
- 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.`);
422
+ if (isUndefined$1(features[name])) {
423
+ const availableFlags = keys(features).map(name => `"${name}"`).join(', '); // eslint-disable-next-line no-console
424
+
425
+ console.warn(`Failed to set the value "${value}" for the runtime feature flag "${name}" because it is undefined. Available flags: ${availableFlags}.`);
414
426
  return;
415
427
  }
416
428
 
@@ -427,37 +439,23 @@ function setFeatureFlag(name, value) {
427
439
  return;
428
440
  }
429
441
 
430
- Object.defineProperty(runtimeFlags, name, {
442
+ defineProperty(runtimeFlags, name, {
431
443
  value
432
444
  });
433
445
  }
434
- } // This function is exposed to components to facilitate testing so we add a
435
- // check to make sure it is not invoked in production.
446
+ }
447
+ /**
448
+ * Set the value at runtime of a given feature flag. This method should only be used for testing
449
+ * purposes. It is a no-op when invoked in production mode.
450
+ */
436
451
 
437
452
 
438
453
  function setFeatureFlagForTest(name, value) {
439
454
  if (process.env.NODE_ENV !== 'production') {
440
- return setFeatureFlag(name, value);
455
+ setFeatureFlag(name, value);
441
456
  }
442
457
  }
443
-
444
- const featureFlagLookup = {
445
- ENABLE_REACTIVE_SETTER: null,
446
- ENABLE_HMR: null,
447
- // Flag to toggle on/off the enforcement of innerText/outerText shadow dom semantic in elements when using synthetic shadow.
448
- // Note: Once active, elements outside the lwc boundary are controlled by the ENABLE_ELEMENT_PATCH flag.
449
- ENABLE_INNER_OUTER_TEXT_PATCH: null,
450
- // Flags to toggle on/off the enforcement of shadow dom semantic in element/node outside lwc boundary when using synthetic shadow.
451
- ENABLE_ELEMENT_PATCH: null,
452
- ENABLE_NODE_LIST_PATCH: null,
453
- ENABLE_HTML_COLLECTIONS_PATCH: null,
454
- ENABLE_NODE_PATCH: null,
455
- // Disables the fix for #2121 where non-composed events are visible outside of their shadow root.
456
- ENABLE_NON_COMPOSED_EVENTS_LEAKAGE: null,
457
- ENABLE_LIGHT_DOM_COMPONENTS: null,
458
- ENABLE_MIXED_SHADOW_MODE: null
459
- };
460
- /** version: 2.3.4 */
458
+ /** version: 2.5.1 */
461
459
 
462
460
  /* proxy-compat-disable */
463
461
 
@@ -468,6 +466,7 @@ const featureFlagLookup = {
468
466
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
469
467
  */
470
468
 
469
+
471
470
  let nextTickCallbackQueue = [];
472
471
  const SPACE_CHAR = 32;
473
472
  const EmptyObject = seal(create(null));
@@ -2788,12 +2787,6 @@ const LightningElement = function () {
2788
2787
  associateVM(component, vm);
2789
2788
  associateVM(elm, vm);
2790
2789
 
2791
- if (!runtimeFlags.ENABLE_LIGHT_DOM_COMPONENTS) {
2792
- assert.isTrue(def.renderMode !== 0
2793
- /* Light */
2794
- , `${def.name || 'Anonymous class'} is an invalid LWC component. Light DOM components are not available in this environment.`);
2795
- }
2796
-
2797
2790
  if (vm.renderMode === 1
2798
2791
  /* Shadow */
2799
2792
  ) {
@@ -2832,6 +2825,12 @@ function attachShadow(vm) {
2832
2825
  if (process.env.NODE_ENV !== 'production') {
2833
2826
  patchShadowRootWithRestrictions(cmpRoot);
2834
2827
  }
2828
+ }
2829
+
2830
+ function warnIfInvokedDuringConstruction(vm, methodName) {
2831
+ if (isBeingConstructed(vm)) {
2832
+ 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.`);
2833
+ }
2835
2834
  } // @ts-ignore
2836
2835
 
2837
2836
 
@@ -2990,7 +2989,7 @@ LightningElement.prototype = {
2990
2989
  } = vm;
2991
2990
 
2992
2991
  if (process.env.NODE_ENV !== 'production') {
2993
- 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.`);
2992
+ warnIfInvokedDuringConstruction(vm, 'getBoundingClientRect');
2994
2993
  }
2995
2994
 
2996
2995
  return getBoundingClientRect(elm);
@@ -3006,7 +3005,7 @@ LightningElement.prototype = {
3006
3005
  } = vm;
3007
3006
 
3008
3007
  if (process.env.NODE_ENV !== 'production') {
3009
- 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.`);
3008
+ warnIfInvokedDuringConstruction(vm, 'querySelector');
3010
3009
  }
3011
3010
 
3012
3011
  return querySelector(elm, selectors);
@@ -3022,7 +3021,7 @@ LightningElement.prototype = {
3022
3021
  } = vm;
3023
3022
 
3024
3023
  if (process.env.NODE_ENV !== 'production') {
3025
- 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.`);
3024
+ warnIfInvokedDuringConstruction(vm, 'querySelectorAll');
3026
3025
  }
3027
3026
 
3028
3027
  return querySelectorAll(elm, selectors);
@@ -3038,7 +3037,7 @@ LightningElement.prototype = {
3038
3037
  } = vm;
3039
3038
 
3040
3039
  if (process.env.NODE_ENV !== 'production') {
3041
- 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.`);
3040
+ warnIfInvokedDuringConstruction(vm, 'getElementsByTagName');
3042
3041
  }
3043
3042
 
3044
3043
  return getElementsByTagName(elm, tagNameOrWildCard);
@@ -3054,7 +3053,7 @@ LightningElement.prototype = {
3054
3053
  } = vm;
3055
3054
 
3056
3055
  if (process.env.NODE_ENV !== 'production') {
3057
- 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.`);
3056
+ warnIfInvokedDuringConstruction(vm, 'getElementsByClassName');
3058
3057
  }
3059
3058
 
3060
3059
  return getElementsByClassName(elm, names);
@@ -3427,18 +3426,33 @@ function createObservedFieldPropertyDescriptor(key) {
3427
3426
 
3428
3427
  function getClassDescriptorType(descriptor) {
3429
3428
  if (isFunction$1(descriptor.value)) {
3430
- return 'method';
3429
+ return "method"
3430
+ /* Method */
3431
+ ;
3431
3432
  } else if (isFunction$1(descriptor.set) || isFunction$1(descriptor.get)) {
3432
- return 'accessor';
3433
+ return "accessor"
3434
+ /* Accessor */
3435
+ ;
3433
3436
  } else {
3434
- return 'field';
3437
+ return "field"
3438
+ /* Field */
3439
+ ;
3435
3440
  }
3436
3441
  }
3437
3442
 
3438
3443
  function validateObservedField(Ctor, fieldName, descriptor) {
3439
3444
  if (!isUndefined$1(descriptor)) {
3440
3445
  const type = getClassDescriptorType(descriptor);
3441
- assert.fail(`Invalid observed ${fieldName} field. Found a duplicate ${type} with the same name.`);
3446
+ 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.
3447
+ // This branch is only here for backward compatibility reasons.
3448
+
3449
+ if (type === "accessor"
3450
+ /* Accessor */
3451
+ ) {
3452
+ logError(message);
3453
+ } else {
3454
+ assert.fail(message);
3455
+ }
3442
3456
  }
3443
3457
  }
3444
3458
 
@@ -3465,7 +3479,16 @@ function validateMethodDecoratedWithWire(Ctor, methodName, descriptor) {
3465
3479
  function validateFieldDecoratedWithApi(Ctor, fieldName, descriptor) {
3466
3480
  if (!isUndefined$1(descriptor)) {
3467
3481
  const type = getClassDescriptorType(descriptor);
3468
- assert.fail(`Invalid @api ${fieldName} field. Found a duplicate ${type} with the same name.`);
3482
+ 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.
3483
+ // This branch is only here for backward compatibility reasons.
3484
+
3485
+ if (type === "accessor"
3486
+ /* Accessor */
3487
+ ) {
3488
+ logError(message);
3489
+ } else {
3490
+ assert.fail(message);
3491
+ }
3469
3492
  }
3470
3493
  }
3471
3494
 
@@ -3528,9 +3551,16 @@ function registerDecorators(Ctor, meta) {
3528
3551
  // field declaration
3529
3552
  if (process.env.NODE_ENV !== 'production') {
3530
3553
  validateFieldDecoratedWithApi(Ctor, fieldName, descriptor);
3531
- }
3554
+ } // [W-9927596] If a component has both a public property and a private setter/getter
3555
+ // with the same name, the property is defined as a public accessor. This branch is
3556
+ // only here for backward compatibility reasons.
3532
3557
 
3533
- descriptor = createPublicPropertyDescriptor(fieldName);
3558
+
3559
+ if (!isUndefined$1(descriptor) && !isUndefined$1(descriptor.get)) {
3560
+ descriptor = createPublicAccessorDescriptor(fieldName, descriptor);
3561
+ } else {
3562
+ descriptor = createPublicPropertyDescriptor(fieldName);
3563
+ }
3534
3564
  }
3535
3565
 
3536
3566
  apiFields[fieldName] = descriptor;
@@ -3610,9 +3640,16 @@ function registerDecorators(Ctor, meta) {
3610
3640
 
3611
3641
  if (process.env.NODE_ENV !== 'production') {
3612
3642
  validateObservedField(Ctor, fieldName, descriptor);
3613
- }
3643
+ } // [W-9927596] Only mark a field as observed whenever it isn't a duplicated public nor
3644
+ // tracked property. This is only here for backward compatibility purposes.
3645
+
3614
3646
 
3615
- observedFields[fieldName] = createObservedFieldPropertyDescriptor(fieldName);
3647
+ const isDuplicatePublicProp = !isUndefined$1(publicProps) && fieldName in publicProps;
3648
+ const isDuplicateTrackedProp = !isUndefined$1(track) && fieldName in track;
3649
+
3650
+ if (!isDuplicatePublicProp && !isDuplicateTrackedProp) {
3651
+ observedFields[fieldName] = createObservedFieldPropertyDescriptor(fieldName);
3652
+ }
3616
3653
  }
3617
3654
  }
3618
3655
 
@@ -4344,6 +4381,19 @@ function observeElementChildNodes(elm) {
4344
4381
 
4345
4382
  function setElementShadowToken(elm, token) {
4346
4383
  elm.$shadowToken$ = token;
4384
+ } // Set the scope token class for *.scoped.css styles
4385
+
4386
+
4387
+ function setScopeTokenClassIfNecessary(elm, owner) {
4388
+ const {
4389
+ cmpTemplate,
4390
+ context
4391
+ } = owner;
4392
+ const token = cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken;
4393
+
4394
+ if (!isUndefined$1(token) && context.hasScopedStyles) {
4395
+ owner.renderer.getClassList(elm).add(token);
4396
+ }
4347
4397
  }
4348
4398
 
4349
4399
  function updateNodeHook(oldVnode, vnode) {
@@ -4417,6 +4467,7 @@ function fallbackElmHook(elm, vnode) {
4417
4467
  const {
4418
4468
  owner
4419
4469
  } = vnode;
4470
+ setScopeTokenClassIfNecessary(elm, owner);
4420
4471
 
4421
4472
  if (owner.shadowMode === 1
4422
4473
  /* Synthetic */
@@ -4427,7 +4478,7 @@ function fallbackElmHook(elm, vnode) {
4427
4478
  }
4428
4479
  } = vnode;
4429
4480
  const {
4430
- shadowAttribute
4481
+ stylesheetToken
4431
4482
  } = owner.context;
4432
4483
 
4433
4484
  if (!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
@@ -4439,7 +4490,7 @@ function fallbackElmHook(elm, vnode) {
4439
4490
  // into each element from the template, so they can be styled accordingly.
4440
4491
 
4441
4492
 
4442
- setElementShadowToken(elm, shadowAttribute);
4493
+ setElementShadowToken(elm, stylesheetToken);
4443
4494
  }
4444
4495
 
4445
4496
  if (process.env.NODE_ENV !== 'production') {
@@ -4528,16 +4579,17 @@ function createViewModelHook(elm, vnode) {
4528
4579
  ctor,
4529
4580
  owner
4530
4581
  } = vnode;
4582
+ setScopeTokenClassIfNecessary(elm, owner);
4531
4583
 
4532
4584
  if (owner.shadowMode === 1
4533
4585
  /* Synthetic */
4534
4586
  ) {
4535
4587
  const {
4536
- shadowAttribute
4588
+ stylesheetToken
4537
4589
  } = owner.context; // when running in synthetic shadow mode, we need to set the shadowToken value
4538
4590
  // into each element from the template, so they can be styled accordingly.
4539
4591
 
4540
- setElementShadowToken(elm, shadowAttribute);
4592
+ setElementShadowToken(elm, stylesheetToken);
4541
4593
  }
4542
4594
 
4543
4595
  const def = getComponentInternalDef(ctor);
@@ -4837,13 +4889,19 @@ const CustomElementHook = {
4837
4889
 
4838
4890
  function linkNodeToShadow(elm, owner) {
4839
4891
  const {
4892
+ renderer,
4893
+ renderMode,
4840
4894
  shadowMode
4841
4895
  } = owner; // TODO [#1164]: this should eventually be done by the polyfill directly
4842
4896
 
4843
- if (shadowMode === 1
4844
- /* Synthetic */
4845
- ) {
4846
- elm[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
4897
+ if (renderer.isSyntheticShadowDefined) {
4898
+ if (shadowMode === 1
4899
+ /* Synthetic */
4900
+ || renderMode === 0
4901
+ /* Light */
4902
+ ) {
4903
+ elm[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
4904
+ }
4847
4905
  }
4848
4906
  }
4849
4907
 
@@ -5189,14 +5247,11 @@ function gid(id) {
5189
5247
 
5190
5248
  const {
5191
5249
  idx,
5192
- renderMode,
5193
5250
  shadowMode
5194
5251
  } = vmBeingRendered;
5195
5252
 
5196
5253
  if (shadowMode === 1
5197
5254
  /* Synthetic */
5198
- && renderMode === 1
5199
- /* Shadow */
5200
5255
  ) {
5201
5256
  return StringReplace.call(id, /\S+/g, id => `${id}-${idx}`);
5202
5257
  }
@@ -5225,14 +5280,11 @@ function fid(url) {
5225
5280
 
5226
5281
  const {
5227
5282
  idx,
5228
- renderMode,
5229
5283
  shadowMode
5230
5284
  } = vmBeingRendered; // Apply transformation only for fragment-only-urls, and only in shadow DOM
5231
5285
 
5232
5286
  if (shadowMode === 1
5233
5287
  /* Synthetic */
5234
- && renderMode === 1
5235
- /* Shadow */
5236
5288
  && /^#/.test(url)) {
5237
5289
  return `${url}-${idx}`;
5238
5290
  }
@@ -5333,6 +5385,10 @@ var api = /*#__PURE__*/Object.freeze({
5333
5385
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5334
5386
  */
5335
5387
 
5388
+ function makeHostToken(token) {
5389
+ return `${token}-host`;
5390
+ }
5391
+
5336
5392
  function createInlineStyleVNode(content) {
5337
5393
  return h('style', {
5338
5394
  key: 'style',
@@ -5342,59 +5398,100 @@ function createInlineStyleVNode(content) {
5342
5398
  }, [t(content)]);
5343
5399
  }
5344
5400
 
5345
- function updateSyntheticShadowAttributes(vm, template) {
5401
+ function updateStylesheetToken(vm, template) {
5346
5402
  const {
5347
5403
  elm,
5348
5404
  context,
5349
5405
  renderer,
5350
- renderMode
5406
+ renderMode,
5407
+ shadowMode
5351
5408
  } = vm;
5352
5409
  const {
5353
5410
  stylesheets: newStylesheets,
5354
- stylesheetTokens: newStylesheetTokens
5411
+ stylesheetToken: newStylesheetToken
5355
5412
  } = template;
5356
- let newTokens; // Reset the styling token applied to the host element.
5413
+ const isSyntheticShadow = renderMode === 1
5414
+ /* Shadow */
5415
+ && shadowMode === 1
5416
+ /* Synthetic */
5417
+ ;
5418
+ const {
5419
+ hasScopedStyles
5420
+ } = context;
5421
+ let newToken;
5422
+ let newHasTokenInClass;
5423
+ let newHasTokenInAttribute; // Reset the styling token applied to the host element.
5424
+
5425
+ const {
5426
+ stylesheetToken: oldToken,
5427
+ hasTokenInClass: oldHasTokenInClass,
5428
+ hasTokenInAttribute: oldHasTokenInAttribute
5429
+ } = context;
5357
5430
 
5358
- const oldHostAttribute = context.hostAttribute;
5431
+ if (oldHasTokenInClass) {
5432
+ renderer.getClassList(elm).remove(makeHostToken(oldToken));
5433
+ }
5359
5434
 
5360
- if (!isUndefined$1(oldHostAttribute)) {
5361
- renderer.removeAttribute(elm, oldHostAttribute);
5435
+ if (oldHasTokenInAttribute) {
5436
+ renderer.removeAttribute(elm, makeHostToken(oldToken));
5362
5437
  } // Apply the new template styling token to the host element, if the new template has any
5363
- // associated stylesheets.
5438
+ // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
5364
5439
 
5365
5440
 
5366
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0 && renderMode === 1
5367
- /* Shadow */
5368
- ) {
5369
- newTokens = newStylesheetTokens;
5370
- }
5441
+ if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
5442
+ newToken = newStylesheetToken;
5443
+ } // Set the new styling token on the host element
5444
+
5445
+
5446
+ if (!isUndefined$1(newToken)) {
5447
+ if (hasScopedStyles) {
5448
+ renderer.getClassList(elm).add(makeHostToken(newToken));
5449
+ newHasTokenInClass = true;
5450
+ }
5371
5451
 
5372
- if (!isUndefined$1(newTokens)) {
5373
- renderer.setAttribute(elm, newTokens.hostAttribute, '');
5452
+ if (isSyntheticShadow) {
5453
+ renderer.setAttribute(elm, makeHostToken(newToken), '');
5454
+ newHasTokenInAttribute = true;
5455
+ }
5374
5456
  } // Update the styling tokens present on the context object.
5375
5457
 
5376
5458
 
5377
- context.hostAttribute = newTokens === null || newTokens === void 0 ? void 0 : newTokens.hostAttribute;
5378
- context.shadowAttribute = newTokens === null || newTokens === void 0 ? void 0 : newTokens.shadowAttribute;
5459
+ context.stylesheetToken = newToken;
5460
+ context.hasTokenInClass = newHasTokenInClass;
5461
+ context.hasTokenInAttribute = newHasTokenInAttribute;
5379
5462
  }
5380
5463
 
5381
- function evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, nativeShadow) {
5464
+ function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
5382
5465
  const content = [];
5383
5466
 
5384
5467
  for (let i = 0; i < stylesheets.length; i++) {
5385
5468
  let stylesheet = stylesheets[i];
5386
5469
 
5387
5470
  if (isArray$1(stylesheet)) {
5388
- ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, hostSelector, shadowSelector, nativeShadow));
5471
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
5389
5472
  } else {
5390
5473
  if (process.env.NODE_ENV !== 'production') {
5391
5474
  // in dev-mode, we support hot swapping of stylesheet, which means that
5392
5475
  // the component instance might be attempting to use an old version of
5393
5476
  // the stylesheet, while internally, we have a replacement for it.
5394
5477
  stylesheet = getStyleOrSwappedStyle(stylesheet);
5395
- }
5478
+ } // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
5479
+ // native shadow DOM. Synthetic shadow DOM never uses `:host`.
5480
+
5396
5481
 
5397
- ArrayPush$1.call(content, stylesheet(hostSelector, shadowSelector, nativeShadow));
5482
+ const isScopedCss = stylesheet[KEY__SCOPED_CSS];
5483
+ const useActualHostSelector = vm.renderMode === 0
5484
+ /* Light */
5485
+ ? !isScopedCss : vm.shadowMode === 0
5486
+ /* Native */
5487
+ ; // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
5488
+
5489
+ const scopeToken = isScopedCss || vm.shadowMode === 1
5490
+ /* Synthetic */
5491
+ && vm.renderMode === 1
5492
+ /* Shadow */
5493
+ ? stylesheetToken : undefined;
5494
+ ArrayPush$1.call(content, stylesheet(useActualHostSelector, scopeToken));
5398
5495
  }
5399
5496
  }
5400
5497
 
@@ -5404,37 +5501,36 @@ function evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, n
5404
5501
  function getStylesheetsContent(vm, template) {
5405
5502
  const {
5406
5503
  stylesheets,
5407
- stylesheetTokens
5504
+ stylesheetToken
5408
5505
  } = template;
5409
- const {
5410
- renderMode,
5411
- shadowMode
5412
- } = vm;
5413
5506
  let content = [];
5414
5507
 
5415
5508
  if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
5416
- let hostSelector;
5417
- let shadowSelector; // Scoping with the tokens is only necessary for synthetic shadow. For both
5418
- // light DOM elements and native shadow, we just render the CSS as-is.
5509
+ content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
5510
+ }
5511
+
5512
+ return content;
5513
+ } // It might be worth caching this to avoid doing the lookup repeatedly, but
5514
+ // perf testing has not shown it to be a huge improvement yet:
5515
+ // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
5516
+
5419
5517
 
5420
- if (renderMode === 1
5518
+ function getNearestNativeShadowComponent(vm) {
5519
+ let owner = vm;
5520
+
5521
+ while (!isNull(owner)) {
5522
+ if (owner.renderMode === 1
5421
5523
  /* Shadow */
5422
- && shadowMode === 1
5423
- /* Synthetic */
5424
- && !isUndefined$1(stylesheetTokens)) {
5425
- hostSelector = `[${stylesheetTokens.hostAttribute}]`;
5426
- shadowSelector = `[${stylesheetTokens.shadowAttribute}]`;
5427
- } else {
5428
- hostSelector = '';
5429
- shadowSelector = '';
5524
+ && owner.shadowMode === 0
5525
+ /* Native */
5526
+ ) {
5527
+ return owner;
5430
5528
  }
5431
5529
 
5432
- content = evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, shadowMode === 0
5433
- /* Native */
5434
- );
5530
+ owner = owner.owner;
5435
5531
  }
5436
5532
 
5437
- return content;
5533
+ return owner;
5438
5534
  }
5439
5535
 
5440
5536
  function createStylesheet(vm, stylesheets) {
@@ -5452,13 +5548,26 @@ function createStylesheet(vm, stylesheets) {
5452
5548
  for (let i = 0; i < stylesheets.length; i++) {
5453
5549
  renderer.insertGlobalStylesheet(stylesheets[i]);
5454
5550
  }
5455
-
5456
- return null;
5457
- } else {
5458
- // native shadow or light DOM
5551
+ } else if (renderer.ssr) {
5552
+ // native shadow or light DOM, SSR
5459
5553
  const combinedStylesheetContent = ArrayJoin.call(stylesheets, '\n');
5460
5554
  return createInlineStyleVNode(combinedStylesheetContent);
5555
+ } else {
5556
+ // native shadow or light DOM, DOM renderer
5557
+ const root = getNearestNativeShadowComponent(vm);
5558
+ const isGlobal = isNull(root);
5559
+
5560
+ for (let i = 0; i < stylesheets.length; i++) {
5561
+ if (isGlobal) {
5562
+ renderer.insertGlobalStylesheet(stylesheets[i]);
5563
+ } else {
5564
+ // local level
5565
+ renderer.insertStylesheet(stylesheets[i], root.cmpRoot);
5566
+ }
5567
+ }
5461
5568
  }
5569
+
5570
+ return null;
5462
5571
  }
5463
5572
  /*
5464
5573
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5612,8 +5721,7 @@ function evaluateTemplate(vm, html) {
5612
5721
  context,
5613
5722
  cmpSlots,
5614
5723
  cmpTemplate,
5615
- tro,
5616
- shadowMode
5724
+ tro
5617
5725
  } = vm;
5618
5726
  tro.observe(() => {
5619
5727
  // Reset the cache memoizer for template when needed.
@@ -5638,15 +5746,12 @@ function evaluateTemplate(vm, html) {
5638
5746
 
5639
5747
  vm.cmpTemplate = html; // Create a brand new template cache for the swapped templated.
5640
5748
 
5641
- context.tplCache = create(null); // Update the synthetic shadow attributes on the host element if necessary.
5749
+ context.tplCache = create(null); // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
5642
5750
 
5643
- if (shadowMode === 1
5644
- /* Synthetic */
5645
- ) {
5646
- updateSyntheticShadowAttributes(vm, html);
5647
- } // Evaluate, create stylesheet and cache the produced VNode for future
5648
- // re-rendering.
5751
+ context.hasScopedStyles = computeHasScopedStyles(html); // Update the scoping token on the host element.
5649
5752
 
5753
+ updateStylesheetToken(vm, html); // Evaluate, create stylesheet and cache the produced VNode for future
5754
+ // re-rendering.
5650
5755
 
5651
5756
  const stylesheetsContent = getStylesheetsContent(vm, html);
5652
5757
  context.styleVNode = stylesheetsContent.length === 0 ? null : createStylesheet(vm, stylesheetsContent);
@@ -5688,6 +5793,22 @@ function evaluateTemplate(vm, html) {
5688
5793
 
5689
5794
  return vnodes;
5690
5795
  }
5796
+
5797
+ function computeHasScopedStyles(template) {
5798
+ const {
5799
+ stylesheets
5800
+ } = template;
5801
+
5802
+ if (!isUndefined$1(stylesheets)) {
5803
+ for (let i = 0; i < stylesheets.length; i++) {
5804
+ if (isTrue(stylesheets[i][KEY__SCOPED_CSS])) {
5805
+ return true;
5806
+ }
5807
+ }
5808
+ }
5809
+
5810
+ return false;
5811
+ }
5691
5812
  /*
5692
5813
  * Copyright (c) 2018, salesforce.com, inc.
5693
5814
  * All rights reserved.
@@ -5959,7 +6080,6 @@ function invokeServiceHook(vm, cbs) {
5959
6080
  */
5960
6081
 
5961
6082
 
5962
- const isNativeShadowRootDefined = _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED];
5963
6083
  let idx = 0;
5964
6084
  /** The internal slot used to associate different objects the engine manipulates with the VM */
5965
6085
 
@@ -6068,29 +6188,6 @@ function getNearestShadowAncestor(vm) {
6068
6188
  return ancestor;
6069
6189
  }
6070
6190
 
6071
- function assertNotSyntheticComposedWithinNative(vm) {
6072
- const isSynthetic = vm.renderMode === 1
6073
- /* Shadow */
6074
- && vm.shadowMode === 1
6075
- /* Synthetic */
6076
- ;
6077
-
6078
- if (!isSynthetic) {
6079
- return;
6080
- }
6081
-
6082
- const ancestor = getNearestShadowAncestor(vm);
6083
-
6084
- if (!isNull(ancestor)) {
6085
- // Any native shadow component being an ancestor of a synthetic shadow component is disallowed.
6086
- assert.isFalse(ancestor.renderMode === 1
6087
- /* Shadow */
6088
- && ancestor.shadowMode === 0
6089
- /* Native */
6090
- , `${getComponentTag(vm)} (synthetic shadow DOM) cannot be composed inside of ${getComponentTag(ancestor)} (native shadow DOM), because synthetic-within-native composition is disallowed`);
6091
- }
6092
- }
6093
-
6094
6191
  function createVM(elm, def, options) {
6095
6192
  const {
6096
6193
  mode,
@@ -6098,22 +6195,6 @@ function createVM(elm, def, options) {
6098
6195
  renderer,
6099
6196
  tagName
6100
6197
  } = options;
6101
- let shadowMode;
6102
-
6103
- if (renderer.syntheticShadow) {
6104
- shadowMode = def.shadowSupportMode === "any"
6105
- /* Any */
6106
- && isNativeShadowRootDefined ? 0
6107
- /* Native */
6108
- : 1
6109
- /* Synthetic */
6110
- ;
6111
- } else {
6112
- shadowMode = 0
6113
- /* Native */
6114
- ;
6115
- }
6116
-
6117
6198
  const vm = {
6118
6199
  elm,
6119
6200
  def,
@@ -6136,10 +6217,12 @@ function createVM(elm, def, options) {
6136
6217
  oar: create(null),
6137
6218
  cmpTemplate: null,
6138
6219
  renderMode: def.renderMode,
6139
- shadowMode,
6220
+ shadowMode: null,
6140
6221
  context: {
6141
- hostAttribute: undefined,
6142
- shadowAttribute: undefined,
6222
+ stylesheetToken: undefined,
6223
+ hasTokenInClass: undefined,
6224
+ hasTokenInAttribute: undefined,
6225
+ hasScopedStyles: undefined,
6143
6226
  styleVNode: null,
6144
6227
  tplCache: EmptyObject,
6145
6228
  wiredConnecting: EmptyArray,
@@ -6152,26 +6235,87 @@ function createVM(elm, def, options) {
6152
6235
  setHook,
6153
6236
  getHook
6154
6237
  };
6238
+ vm.shadowMode = computeShadowMode(vm);
6155
6239
  vm.tro = getTemplateReactiveObserver(vm);
6156
6240
 
6157
6241
  if (process.env.NODE_ENV !== 'production') {
6158
6242
  vm.toString = () => {
6159
6243
  return `[object:vm ${def.name} (${vm.idx})]`;
6160
6244
  };
6161
-
6162
- assertNotSyntheticComposedWithinNative(vm);
6163
6245
  } // Create component instance associated to the vm and the element.
6164
6246
 
6165
6247
 
6166
6248
  invokeComponentConstructor(vm, def.ctor); // Initializing the wire decorator per instance only when really needed
6167
6249
 
6168
- if (isFalse(renderer.ssr) && hasWireAdapters(vm)) {
6250
+ if (hasWireAdapters(vm)) {
6169
6251
  installWireAdapters(vm);
6170
6252
  }
6171
6253
 
6172
6254
  return vm;
6173
6255
  }
6174
6256
 
6257
+ function computeShadowMode(vm) {
6258
+ const {
6259
+ def,
6260
+ renderer
6261
+ } = vm;
6262
+ const {
6263
+ isNativeShadowDefined,
6264
+ isSyntheticShadowDefined
6265
+ } = renderer;
6266
+ let shadowMode;
6267
+
6268
+ if (isSyntheticShadowDefined) {
6269
+ if (def.renderMode === 0
6270
+ /* Light */
6271
+ ) {
6272
+ // ShadowMode.Native implies "not synthetic shadow" which is consistent with how
6273
+ // everything defaults to native when the synthetic shadow polyfill is unavailable.
6274
+ shadowMode = 0
6275
+ /* Native */
6276
+ ;
6277
+ } else if (isNativeShadowDefined) {
6278
+ if (def.shadowSupportMode === "any"
6279
+ /* Any */
6280
+ ) {
6281
+ shadowMode = 0
6282
+ /* Native */
6283
+ ;
6284
+ } else {
6285
+ const shadowAncestor = getNearestShadowAncestor(vm);
6286
+
6287
+ if (!isNull(shadowAncestor) && shadowAncestor.shadowMode === 0
6288
+ /* Native */
6289
+ ) {
6290
+ // Transitive support for native Shadow DOM. A component in native mode
6291
+ // transitively opts all of its descendants into native.
6292
+ shadowMode = 0
6293
+ /* Native */
6294
+ ;
6295
+ } else {
6296
+ // Synthetic if neither this component nor any of its ancestors are configured
6297
+ // to be native.
6298
+ shadowMode = 1
6299
+ /* Synthetic */
6300
+ ;
6301
+ }
6302
+ }
6303
+ } else {
6304
+ // Synthetic if there is no native Shadow DOM support.
6305
+ shadowMode = 1
6306
+ /* Synthetic */
6307
+ ;
6308
+ }
6309
+ } else {
6310
+ // Native if the synthetic shadow polyfill is unavailable.
6311
+ shadowMode = 0
6312
+ /* Native */
6313
+ ;
6314
+ }
6315
+
6316
+ return shadowMode;
6317
+ }
6318
+
6175
6319
  function assertIsVM(obj) {
6176
6320
  if (isNull(obj) || !isObject(obj) || !('cmpRoot' in obj)) {
6177
6321
  throw new TypeError(`${obj} is not a VM.`);
@@ -6895,11 +7039,14 @@ function installWireAdapters(vm) {
6895
7039
  ArrayPush$1.call(wiredConnecting, () => {
6896
7040
  connector.connect();
6897
7041
 
6898
- if (hasDynamicParams) {
6899
- Promise.resolve().then(computeConfigAndUpdate);
6900
- } else {
6901
- computeConfigAndUpdate();
7042
+ if (!runtimeFlags.ENABLE_WIRE_SYNC_EMIT) {
7043
+ if (hasDynamicParams) {
7044
+ Promise.resolve().then(computeConfigAndUpdate);
7045
+ return;
7046
+ }
6902
7047
  }
7048
+
7049
+ computeConfigAndUpdate();
6903
7050
  });
6904
7051
  ArrayPush$1.call(wiredDisconnecting, () => {
6905
7052
  connector.disconnect();
@@ -7006,7 +7153,7 @@ function readonly(obj) {
7006
7153
 
7007
7154
  return reactiveMembrane.getReadOnlyProxy(obj);
7008
7155
  }
7009
- /* version: 2.3.4 */
7156
+ /* version: 2.5.1 */
7010
7157
 
7011
7158
  /*
7012
7159
  * Copyright (c) 2020, salesforce.com, inc.
@@ -7097,7 +7244,8 @@ class HTMLElement$1 {
7097
7244
 
7098
7245
  const renderer = {
7099
7246
  ssr: true,
7100
- syntheticShadow: false,
7247
+ isNativeShadowDefined: false,
7248
+ isSyntheticShadowDefined: false,
7101
7249
 
7102
7250
  insert(node, parent, anchor) {
7103
7251
  if (node.parent !== null && node.parent !== parent) {
@@ -7315,6 +7463,10 @@ const renderer = {
7315
7463
  // synthetic shadow.
7316
7464
  },
7317
7465
 
7466
+ insertStylesheet() {// Noop on SSR (for now). This need to be reevaluated whenever we will implement support for
7467
+ // synthetic shadow.
7468
+ },
7469
+
7318
7470
  addEventListener() {// Noop on SSR.
7319
7471
  },
7320
7472
 
@@ -7472,6 +7624,6 @@ function renderComponent(tagName, Ctor, props = {}) {
7472
7624
 
7473
7625
  freeze(LightningElement);
7474
7626
  seal(LightningElement.prototype);
7475
- /* version: 2.3.4 */
7627
+ /* version: 2.5.1 */
7476
7628
 
7477
7629
  export { LightningElement, api$1 as api, createContextProvider, getComponentDef, isComponentConstructor, readonly, register, registerComponent, registerDecorators, registerTemplate, renderComponent, sanitizeAttribute, setFeatureFlag, setFeatureFlagForTest, track, unwrap, wire };