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
@@ -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.3 */
342
+ /** version: 2.5.0 */
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.3 */
462
+ /** version: 2.5.0 */
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);
@@ -4348,6 +4347,19 @@ function observeElementChildNodes(elm) {
4348
4347
 
4349
4348
  function setElementShadowToken(elm, token) {
4350
4349
  elm.$shadowToken$ = token;
4350
+ } // Set the scope token class for *.scoped.css styles
4351
+
4352
+
4353
+ function setScopeTokenClassIfNecessary(elm, owner) {
4354
+ const {
4355
+ cmpTemplate,
4356
+ context
4357
+ } = owner;
4358
+ const token = cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken;
4359
+
4360
+ if (!isUndefined$1(token) && context.hasScopedStyles) {
4361
+ owner.renderer.getClassList(elm).add(token);
4362
+ }
4351
4363
  }
4352
4364
 
4353
4365
  function updateNodeHook(oldVnode, vnode) {
@@ -4421,6 +4433,7 @@ function fallbackElmHook(elm, vnode) {
4421
4433
  const {
4422
4434
  owner
4423
4435
  } = vnode;
4436
+ setScopeTokenClassIfNecessary(elm, owner);
4424
4437
 
4425
4438
  if (owner.shadowMode === 1
4426
4439
  /* Synthetic */
@@ -4431,7 +4444,7 @@ function fallbackElmHook(elm, vnode) {
4431
4444
  }
4432
4445
  } = vnode;
4433
4446
  const {
4434
- shadowAttribute
4447
+ stylesheetToken
4435
4448
  } = owner.context;
4436
4449
 
4437
4450
  if (!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
@@ -4443,7 +4456,7 @@ function fallbackElmHook(elm, vnode) {
4443
4456
  // into each element from the template, so they can be styled accordingly.
4444
4457
 
4445
4458
 
4446
- setElementShadowToken(elm, shadowAttribute);
4459
+ setElementShadowToken(elm, stylesheetToken);
4447
4460
  }
4448
4461
 
4449
4462
  if (process.env.NODE_ENV !== 'production') {
@@ -4532,16 +4545,17 @@ function createViewModelHook(elm, vnode) {
4532
4545
  ctor,
4533
4546
  owner
4534
4547
  } = vnode;
4548
+ setScopeTokenClassIfNecessary(elm, owner);
4535
4549
 
4536
4550
  if (owner.shadowMode === 1
4537
4551
  /* Synthetic */
4538
4552
  ) {
4539
4553
  const {
4540
- shadowAttribute
4554
+ stylesheetToken
4541
4555
  } = owner.context; // when running in synthetic shadow mode, we need to set the shadowToken value
4542
4556
  // into each element from the template, so they can be styled accordingly.
4543
4557
 
4544
- setElementShadowToken(elm, shadowAttribute);
4558
+ setElementShadowToken(elm, stylesheetToken);
4545
4559
  }
4546
4560
 
4547
4561
  const def = getComponentInternalDef(ctor);
@@ -4841,13 +4855,19 @@ const CustomElementHook = {
4841
4855
 
4842
4856
  function linkNodeToShadow(elm, owner) {
4843
4857
  const {
4858
+ renderer,
4859
+ renderMode,
4844
4860
  shadowMode
4845
4861
  } = owner; // TODO [#1164]: this should eventually be done by the polyfill directly
4846
4862
 
4847
- if (shadowMode === 1
4848
- /* Synthetic */
4849
- ) {
4850
- elm[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
4863
+ if (renderer.isSyntheticShadowDefined) {
4864
+ if (shadowMode === 1
4865
+ /* Synthetic */
4866
+ || renderMode === 0
4867
+ /* Light */
4868
+ ) {
4869
+ elm[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
4870
+ }
4851
4871
  }
4852
4872
  }
4853
4873
 
@@ -5193,14 +5213,11 @@ function gid(id) {
5193
5213
 
5194
5214
  const {
5195
5215
  idx,
5196
- renderMode,
5197
5216
  shadowMode
5198
5217
  } = vmBeingRendered;
5199
5218
 
5200
5219
  if (shadowMode === 1
5201
5220
  /* Synthetic */
5202
- && renderMode === 1
5203
- /* Shadow */
5204
5221
  ) {
5205
5222
  return StringReplace.call(id, /\S+/g, id => `${id}-${idx}`);
5206
5223
  }
@@ -5229,14 +5246,11 @@ function fid(url) {
5229
5246
 
5230
5247
  const {
5231
5248
  idx,
5232
- renderMode,
5233
5249
  shadowMode
5234
5250
  } = vmBeingRendered; // Apply transformation only for fragment-only-urls, and only in shadow DOM
5235
5251
 
5236
5252
  if (shadowMode === 1
5237
5253
  /* Synthetic */
5238
- && renderMode === 1
5239
- /* Shadow */
5240
5254
  && /^#/.test(url)) {
5241
5255
  return `${url}-${idx}`;
5242
5256
  }
@@ -5337,6 +5351,10 @@ var api = /*#__PURE__*/Object.freeze({
5337
5351
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5338
5352
  */
5339
5353
 
5354
+ function makeHostToken(token) {
5355
+ return `${token}-host`;
5356
+ }
5357
+
5340
5358
  function createInlineStyleVNode(content) {
5341
5359
  return h('style', {
5342
5360
  key: 'style',
@@ -5346,59 +5364,100 @@ function createInlineStyleVNode(content) {
5346
5364
  }, [t(content)]);
5347
5365
  }
5348
5366
 
5349
- function updateSyntheticShadowAttributes(vm, template) {
5367
+ function updateStylesheetToken(vm, template) {
5350
5368
  const {
5351
5369
  elm,
5352
5370
  context,
5353
5371
  renderer,
5354
- renderMode
5372
+ renderMode,
5373
+ shadowMode
5355
5374
  } = vm;
5356
5375
  const {
5357
5376
  stylesheets: newStylesheets,
5358
- stylesheetTokens: newStylesheetTokens
5377
+ stylesheetToken: newStylesheetToken
5359
5378
  } = template;
5360
- let newTokens; // Reset the styling token applied to the host element.
5379
+ const isSyntheticShadow = renderMode === 1
5380
+ /* Shadow */
5381
+ && shadowMode === 1
5382
+ /* Synthetic */
5383
+ ;
5384
+ const {
5385
+ hasScopedStyles
5386
+ } = context;
5387
+ let newToken;
5388
+ let newHasTokenInClass;
5389
+ let newHasTokenInAttribute; // Reset the styling token applied to the host element.
5361
5390
 
5362
- const oldHostAttribute = context.hostAttribute;
5391
+ const {
5392
+ stylesheetToken: oldToken,
5393
+ hasTokenInClass: oldHasTokenInClass,
5394
+ hasTokenInAttribute: oldHasTokenInAttribute
5395
+ } = context;
5363
5396
 
5364
- if (!isUndefined$1(oldHostAttribute)) {
5365
- renderer.removeAttribute(elm, oldHostAttribute);
5397
+ if (oldHasTokenInClass) {
5398
+ renderer.getClassList(elm).remove(makeHostToken(oldToken));
5399
+ }
5400
+
5401
+ if (oldHasTokenInAttribute) {
5402
+ renderer.removeAttribute(elm, makeHostToken(oldToken));
5366
5403
  } // Apply the new template styling token to the host element, if the new template has any
5367
- // associated stylesheets.
5404
+ // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
5368
5405
 
5369
5406
 
5370
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0 && renderMode === 1
5371
- /* Shadow */
5372
- ) {
5373
- newTokens = newStylesheetTokens;
5374
- }
5407
+ if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
5408
+ newToken = newStylesheetToken;
5409
+ } // Set the new styling token on the host element
5410
+
5411
+
5412
+ if (!isUndefined$1(newToken)) {
5413
+ if (hasScopedStyles) {
5414
+ renderer.getClassList(elm).add(makeHostToken(newToken));
5415
+ newHasTokenInClass = true;
5416
+ }
5375
5417
 
5376
- if (!isUndefined$1(newTokens)) {
5377
- renderer.setAttribute(elm, newTokens.hostAttribute, '');
5418
+ if (isSyntheticShadow) {
5419
+ renderer.setAttribute(elm, makeHostToken(newToken), '');
5420
+ newHasTokenInAttribute = true;
5421
+ }
5378
5422
  } // Update the styling tokens present on the context object.
5379
5423
 
5380
5424
 
5381
- context.hostAttribute = newTokens === null || newTokens === void 0 ? void 0 : newTokens.hostAttribute;
5382
- context.shadowAttribute = newTokens === null || newTokens === void 0 ? void 0 : newTokens.shadowAttribute;
5425
+ context.stylesheetToken = newToken;
5426
+ context.hasTokenInClass = newHasTokenInClass;
5427
+ context.hasTokenInAttribute = newHasTokenInAttribute;
5383
5428
  }
5384
5429
 
5385
- function evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, nativeShadow) {
5430
+ function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
5386
5431
  const content = [];
5387
5432
 
5388
5433
  for (let i = 0; i < stylesheets.length; i++) {
5389
5434
  let stylesheet = stylesheets[i];
5390
5435
 
5391
5436
  if (isArray$1(stylesheet)) {
5392
- ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, hostSelector, shadowSelector, nativeShadow));
5437
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
5393
5438
  } else {
5394
5439
  if (process.env.NODE_ENV !== 'production') {
5395
5440
  // in dev-mode, we support hot swapping of stylesheet, which means that
5396
5441
  // the component instance might be attempting to use an old version of
5397
5442
  // the stylesheet, while internally, we have a replacement for it.
5398
5443
  stylesheet = getStyleOrSwappedStyle(stylesheet);
5399
- }
5444
+ } // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
5445
+ // native shadow DOM. Synthetic shadow DOM never uses `:host`.
5446
+
5400
5447
 
5401
- ArrayPush$1.call(content, stylesheet(hostSelector, shadowSelector, nativeShadow));
5448
+ const isScopedCss = stylesheet[KEY__SCOPED_CSS];
5449
+ const useActualHostSelector = vm.renderMode === 0
5450
+ /* Light */
5451
+ ? !isScopedCss : vm.shadowMode === 0
5452
+ /* Native */
5453
+ ; // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
5454
+
5455
+ const scopeToken = isScopedCss || vm.shadowMode === 1
5456
+ /* Synthetic */
5457
+ && vm.renderMode === 1
5458
+ /* Shadow */
5459
+ ? stylesheetToken : undefined;
5460
+ ArrayPush$1.call(content, stylesheet(useActualHostSelector, scopeToken));
5402
5461
  }
5403
5462
  }
5404
5463
 
@@ -5408,37 +5467,36 @@ function evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, n
5408
5467
  function getStylesheetsContent(vm, template) {
5409
5468
  const {
5410
5469
  stylesheets,
5411
- stylesheetTokens
5470
+ stylesheetToken
5412
5471
  } = template;
5413
- const {
5414
- renderMode,
5415
- shadowMode
5416
- } = vm;
5417
5472
  let content = [];
5418
5473
 
5419
5474
  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.
5475
+ content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
5476
+ }
5423
5477
 
5424
- if (renderMode === 1
5478
+ return content;
5479
+ } // It might be worth caching this to avoid doing the lookup repeatedly, but
5480
+ // perf testing has not shown it to be a huge improvement yet:
5481
+ // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
5482
+
5483
+
5484
+ function getNearestNativeShadowComponent(vm) {
5485
+ let owner = vm;
5486
+
5487
+ while (!isNull(owner)) {
5488
+ if (owner.renderMode === 1
5425
5489
  /* Shadow */
5426
- && shadowMode === 1
5427
- /* Synthetic */
5428
- && !isUndefined$1(stylesheetTokens)) {
5429
- hostSelector = `[${stylesheetTokens.hostAttribute}]`;
5430
- shadowSelector = `[${stylesheetTokens.shadowAttribute}]`;
5431
- } else {
5432
- hostSelector = '';
5433
- shadowSelector = '';
5490
+ && owner.shadowMode === 0
5491
+ /* Native */
5492
+ ) {
5493
+ return owner;
5434
5494
  }
5435
5495
 
5436
- content = evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, shadowMode === 0
5437
- /* Native */
5438
- );
5496
+ owner = owner.owner;
5439
5497
  }
5440
5498
 
5441
- return content;
5499
+ return owner;
5442
5500
  }
5443
5501
 
5444
5502
  function createStylesheet(vm, stylesheets) {
@@ -5456,13 +5514,26 @@ function createStylesheet(vm, stylesheets) {
5456
5514
  for (let i = 0; i < stylesheets.length; i++) {
5457
5515
  renderer.insertGlobalStylesheet(stylesheets[i]);
5458
5516
  }
5459
-
5460
- return null;
5461
- } else {
5462
- // native shadow or light DOM
5517
+ } else if (renderer.ssr) {
5518
+ // native shadow or light DOM, SSR
5463
5519
  const combinedStylesheetContent = ArrayJoin.call(stylesheets, '\n');
5464
5520
  return createInlineStyleVNode(combinedStylesheetContent);
5521
+ } else {
5522
+ // native shadow or light DOM, DOM renderer
5523
+ const root = getNearestNativeShadowComponent(vm);
5524
+ const isGlobal = isNull(root);
5525
+
5526
+ for (let i = 0; i < stylesheets.length; i++) {
5527
+ if (isGlobal) {
5528
+ renderer.insertGlobalStylesheet(stylesheets[i]);
5529
+ } else {
5530
+ // local level
5531
+ renderer.insertStylesheet(stylesheets[i], root.cmpRoot);
5532
+ }
5533
+ }
5465
5534
  }
5535
+
5536
+ return null;
5466
5537
  }
5467
5538
  /*
5468
5539
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5616,8 +5687,7 @@ function evaluateTemplate(vm, html) {
5616
5687
  context,
5617
5688
  cmpSlots,
5618
5689
  cmpTemplate,
5619
- tro,
5620
- shadowMode
5690
+ tro
5621
5691
  } = vm;
5622
5692
  tro.observe(() => {
5623
5693
  // Reset the cache memoizer for template when needed.
@@ -5642,15 +5712,12 @@ function evaluateTemplate(vm, html) {
5642
5712
 
5643
5713
  vm.cmpTemplate = html; // Create a brand new template cache for the swapped templated.
5644
5714
 
5645
- context.tplCache = create(null); // Update the synthetic shadow attributes on the host element if necessary.
5715
+ context.tplCache = create(null); // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
5646
5716
 
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.
5717
+ context.hasScopedStyles = computeHasScopedStyles(html); // Update the scoping token on the host element.
5653
5718
 
5719
+ updateStylesheetToken(vm, html); // Evaluate, create stylesheet and cache the produced VNode for future
5720
+ // re-rendering.
5654
5721
 
5655
5722
  const stylesheetsContent = getStylesheetsContent(vm, html);
5656
5723
  context.styleVNode = stylesheetsContent.length === 0 ? null : createStylesheet(vm, stylesheetsContent);
@@ -5692,6 +5759,22 @@ function evaluateTemplate(vm, html) {
5692
5759
 
5693
5760
  return vnodes;
5694
5761
  }
5762
+
5763
+ function computeHasScopedStyles(template) {
5764
+ const {
5765
+ stylesheets
5766
+ } = template;
5767
+
5768
+ if (!isUndefined$1(stylesheets)) {
5769
+ for (let i = 0; i < stylesheets.length; i++) {
5770
+ if (isTrue(stylesheets[i][KEY__SCOPED_CSS])) {
5771
+ return true;
5772
+ }
5773
+ }
5774
+ }
5775
+
5776
+ return false;
5777
+ }
5695
5778
  /*
5696
5779
  * Copyright (c) 2018, salesforce.com, inc.
5697
5780
  * All rights reserved.
@@ -5732,12 +5815,9 @@ function invokeComponentCallback(vm, fn, args) {
5732
5815
  callHook,
5733
5816
  owner
5734
5817
  } = vm;
5735
- let result;
5736
5818
  runWithBoundaryProtection(vm, owner, noop, () => {
5737
- // job
5738
- result = callHook(component, fn, args);
5819
+ callHook(component, fn, args);
5739
5820
  }, noop);
5740
- return result;
5741
5821
  }
5742
5822
 
5743
5823
  function invokeComponentConstructor(vm, Ctor) {
@@ -5811,33 +5891,6 @@ function invokeComponentRenderMethod(vm) {
5811
5891
  return renderInvocationSuccessful ? evaluateTemplate(vm, html) : [];
5812
5892
  }
5813
5893
 
5814
- function invokeComponentRenderedCallback(vm) {
5815
- const {
5816
- def: {
5817
- renderedCallback
5818
- },
5819
- component,
5820
- callHook,
5821
- owner
5822
- } = vm;
5823
-
5824
- if (!isUndefined$1(renderedCallback)) {
5825
- runWithBoundaryProtection(vm, owner, () => {
5826
- logOperationStart(4
5827
- /* RenderedCallback */
5828
- , vm);
5829
- }, () => {
5830
- // job
5831
- callHook(component, renderedCallback);
5832
- }, () => {
5833
- // post
5834
- logOperationEnd(4
5835
- /* RenderedCallback */
5836
- , vm);
5837
- });
5838
- }
5839
- }
5840
-
5841
5894
  function invokeEventListener(vm, fn, thisValue, event) {
5842
5895
  const {
5843
5896
  callHook,
@@ -5993,7 +6046,6 @@ function invokeServiceHook(vm, cbs) {
5993
6046
  */
5994
6047
 
5995
6048
 
5996
- const isNativeShadowRootDefined = _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED];
5997
6049
  let idx = 0;
5998
6050
  /** The internal slot used to associate different objects the engine manipulates with the VM */
5999
6051
 
@@ -6102,29 +6154,6 @@ function getNearestShadowAncestor(vm) {
6102
6154
  return ancestor;
6103
6155
  }
6104
6156
 
6105
- function assertNotSyntheticComposedWithinNative(vm) {
6106
- const isSynthetic = vm.renderMode === 1
6107
- /* Shadow */
6108
- && vm.shadowMode === 1
6109
- /* Synthetic */
6110
- ;
6111
-
6112
- if (!isSynthetic) {
6113
- return;
6114
- }
6115
-
6116
- const ancestor = getNearestShadowAncestor(vm);
6117
-
6118
- if (!isNull(ancestor)) {
6119
- // Any native shadow component being an ancestor of a synthetic shadow component is disallowed.
6120
- assert.isFalse(ancestor.renderMode === 1
6121
- /* Shadow */
6122
- && ancestor.shadowMode === 0
6123
- /* Native */
6124
- , `${getComponentTag(vm)} (synthetic shadow DOM) cannot be composed inside of ${getComponentTag(ancestor)} (native shadow DOM), because synthetic-within-native composition is disallowed`);
6125
- }
6126
- }
6127
-
6128
6157
  function createVM(elm, def, options) {
6129
6158
  const {
6130
6159
  mode,
@@ -6132,22 +6161,6 @@ function createVM(elm, def, options) {
6132
6161
  renderer,
6133
6162
  tagName
6134
6163
  } = options;
6135
- let shadowMode;
6136
-
6137
- if (renderer.syntheticShadow) {
6138
- shadowMode = def.shadowSupportMode === "any"
6139
- /* Any */
6140
- && isNativeShadowRootDefined ? 0
6141
- /* Native */
6142
- : 1
6143
- /* Synthetic */
6144
- ;
6145
- } else {
6146
- shadowMode = 0
6147
- /* Native */
6148
- ;
6149
- }
6150
-
6151
6164
  const vm = {
6152
6165
  elm,
6153
6166
  def,
@@ -6170,10 +6183,12 @@ function createVM(elm, def, options) {
6170
6183
  oar: create(null),
6171
6184
  cmpTemplate: null,
6172
6185
  renderMode: def.renderMode,
6173
- shadowMode,
6186
+ shadowMode: null,
6174
6187
  context: {
6175
- hostAttribute: undefined,
6176
- shadowAttribute: undefined,
6188
+ stylesheetToken: undefined,
6189
+ hasTokenInClass: undefined,
6190
+ hasTokenInAttribute: undefined,
6191
+ hasScopedStyles: undefined,
6177
6192
  styleVNode: null,
6178
6193
  tplCache: EmptyObject,
6179
6194
  wiredConnecting: EmptyArray,
@@ -6186,26 +6201,87 @@ function createVM(elm, def, options) {
6186
6201
  setHook,
6187
6202
  getHook
6188
6203
  };
6204
+ vm.shadowMode = computeShadowMode(vm);
6189
6205
  vm.tro = getTemplateReactiveObserver(vm);
6190
6206
 
6191
6207
  if (process.env.NODE_ENV !== 'production') {
6192
6208
  vm.toString = () => {
6193
6209
  return `[object:vm ${def.name} (${vm.idx})]`;
6194
6210
  };
6195
-
6196
- assertNotSyntheticComposedWithinNative(vm);
6197
6211
  } // Create component instance associated to the vm and the element.
6198
6212
 
6199
6213
 
6200
6214
  invokeComponentConstructor(vm, def.ctor); // Initializing the wire decorator per instance only when really needed
6201
6215
 
6202
- if (isFalse(renderer.ssr) && hasWireAdapters(vm)) {
6216
+ if (hasWireAdapters(vm)) {
6203
6217
  installWireAdapters(vm);
6204
6218
  }
6205
6219
 
6206
6220
  return vm;
6207
6221
  }
6208
6222
 
6223
+ function computeShadowMode(vm) {
6224
+ const {
6225
+ def,
6226
+ renderer
6227
+ } = vm;
6228
+ const {
6229
+ isNativeShadowDefined,
6230
+ isSyntheticShadowDefined
6231
+ } = renderer;
6232
+ let shadowMode;
6233
+
6234
+ if (isSyntheticShadowDefined) {
6235
+ if (def.renderMode === 0
6236
+ /* Light */
6237
+ ) {
6238
+ // ShadowMode.Native implies "not synthetic shadow" which is consistent with how
6239
+ // everything defaults to native when the synthetic shadow polyfill is unavailable.
6240
+ shadowMode = 0
6241
+ /* Native */
6242
+ ;
6243
+ } else if (isNativeShadowDefined) {
6244
+ if (def.shadowSupportMode === "any"
6245
+ /* Any */
6246
+ ) {
6247
+ shadowMode = 0
6248
+ /* Native */
6249
+ ;
6250
+ } else {
6251
+ const shadowAncestor = getNearestShadowAncestor(vm);
6252
+
6253
+ if (!isNull(shadowAncestor) && shadowAncestor.shadowMode === 0
6254
+ /* Native */
6255
+ ) {
6256
+ // Transitive support for native Shadow DOM. A component in native mode
6257
+ // transitively opts all of its descendants into native.
6258
+ shadowMode = 0
6259
+ /* Native */
6260
+ ;
6261
+ } else {
6262
+ // Synthetic if neither this component nor any of its ancestors are configured
6263
+ // to be native.
6264
+ shadowMode = 1
6265
+ /* Synthetic */
6266
+ ;
6267
+ }
6268
+ }
6269
+ } else {
6270
+ // Synthetic if there is no native Shadow DOM support.
6271
+ shadowMode = 1
6272
+ /* Synthetic */
6273
+ ;
6274
+ }
6275
+ } else {
6276
+ // Native if the synthetic shadow polyfill is unavailable.
6277
+ shadowMode = 0
6278
+ /* Native */
6279
+ ;
6280
+ }
6281
+
6282
+ return shadowMode;
6283
+ }
6284
+
6209
6285
  function assertIsVM(obj) {
6210
6286
  if (isNull(obj) || !isObject(obj) || !('cmpRoot' in obj)) {
6211
6287
  throw new TypeError(`${obj} is not a VM.`);
@@ -6287,7 +6363,14 @@ function patchShadowRoot(vm, newCh) {
6287
6363
  }
6288
6364
 
6289
6365
  function runRenderedCallback(vm) {
6290
- if (isTrue(vm.renderer.ssr)) {
6366
+ const {
6367
+ renderer,
6368
+ def: {
6369
+ renderedCallback
6370
+ }
6371
+ } = vm;
6372
+
6373
+ if (isTrue(renderer.ssr)) {
6291
6374
  return;
6292
6375
  }
6293
6376
 
@@ -6299,7 +6382,15 @@ function runRenderedCallback(vm) {
6299
6382
  invokeServiceHook(vm, rendered);
6300
6383
  }
6301
6384
 
6302
- invokeComponentRenderedCallback(vm);
6385
+ if (!isUndefined$1(renderedCallback)) {
6386
+ logOperationStart(4
6387
+ /* RenderedCallback */
6388
+ , vm);
6389
+ invokeComponentCallback(vm, renderedCallback);
6390
+ logOperationEnd(4
6391
+ /* RenderedCallback */
6392
+ , vm);
6393
+ }
6303
6394
  }
6304
6395
 
6305
6396
  let rehydrateQueue = [];
@@ -6914,11 +7005,14 @@ function installWireAdapters(vm) {
6914
7005
  ArrayPush$1.call(wiredConnecting, () => {
6915
7006
  connector.connect();
6916
7007
 
6917
- if (hasDynamicParams) {
6918
- Promise.resolve().then(computeConfigAndUpdate);
6919
- } else {
6920
- computeConfigAndUpdate();
7008
+ if (!runtimeFlags.ENABLE_WIRE_SYNC_EMIT) {
7009
+ if (hasDynamicParams) {
7010
+ Promise.resolve().then(computeConfigAndUpdate);
7011
+ return;
7012
+ }
6921
7013
  }
7014
+
7015
+ computeConfigAndUpdate();
6922
7016
  });
6923
7017
  ArrayPush$1.call(wiredDisconnecting, () => {
6924
7018
  connector.disconnect();
@@ -7025,7 +7119,7 @@ function readonly(obj) {
7025
7119
 
7026
7120
  return reactiveMembrane.getReadOnlyProxy(obj);
7027
7121
  }
7028
- /* version: 2.3.3 */
7122
+ /* version: 2.5.0 */
7029
7123
 
7030
7124
  /*
7031
7125
  * Copyright (c) 2020, salesforce.com, inc.
@@ -7116,7 +7210,8 @@ class HTMLElement$1 {
7116
7210
 
7117
7211
  const renderer = {
7118
7212
  ssr: true,
7119
- syntheticShadow: false,
7213
+ isNativeShadowDefined: false,
7214
+ isSyntheticShadowDefined: false,
7120
7215
 
7121
7216
  insert(node, parent, anchor) {
7122
7217
  if (node.parent !== null && node.parent !== parent) {
@@ -7334,6 +7429,10 @@ const renderer = {
7334
7429
  // synthetic shadow.
7335
7430
  },
7336
7431
 
7432
+ insertStylesheet() {// Noop on SSR (for now). This need to be reevaluated whenever we will implement support for
7433
+ // synthetic shadow.
7434
+ },
7435
+
7337
7436
  addEventListener() {// Noop on SSR.
7338
7437
  },
7339
7438
 
@@ -7491,7 +7590,7 @@ function renderComponent(tagName, Ctor, props = {}) {
7491
7590
 
7492
7591
  freeze(LightningElement);
7493
7592
  seal(LightningElement.prototype);
7494
- /* version: 2.3.3 */
7593
+ /* version: 2.5.0 */
7495
7594
 
7496
7595
  exports.LightningElement = LightningElement;
7497
7596
  exports.api = api$1;