lwc 2.3.3 → 2.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +360 -198
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +360 -198
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +2 -2
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +361 -168
  5. package/dist/engine-dom/iife/es5/engine-dom.js +371 -218
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +2 -2
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +370 -186
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +360 -198
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +2 -2
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +361 -168
  11. package/dist/engine-dom/umd/es5/engine-dom.js +371 -218
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +2 -2
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +370 -186
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +304 -205
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +2 -2
  16. package/dist/engine-server/esm/es2017/engine-server.js +304 -205
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +29 -16
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +29 -16
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.min.js +2 -2
  20. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +29 -16
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +31 -16
  22. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.min.js +2 -2
  23. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +31 -16
  24. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +29 -16
  25. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.min.js +2 -2
  26. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +29 -16
  27. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +31 -16
  28. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.min.js +2 -2
  29. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +31 -16
  30. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  31. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/iife/es5/wire-service.js +3 -3
  34. package/dist/wire-service/iife/es5/wire-service.min.js +1 -1
  35. package/dist/wire-service/iife/es5/wire-service_debug.js +3 -3
  36. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  37. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  38. package/dist/wire-service/umd/es5/wire-service.js +3 -3
  39. package/dist/wire-service/umd/es5/wire-service.min.js +1 -1
  40. package/dist/wire-service/umd/es5/wire-service_debug.js +3 -3
  41. package/package.json +8 -8
@@ -104,6 +104,10 @@ function isFalse(obj) {
104
104
  return obj === false;
105
105
  }
106
106
 
107
+ function isBoolean(obj) {
108
+ return typeof obj === 'boolean';
109
+ }
110
+
107
111
  function isFunction$1(obj) {
108
112
  return typeof obj === 'function';
109
113
  }
@@ -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.3 */
338
+ /** version: 2.5.0 */
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.3 */
458
+ /** version: 2.5.0 */
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);
@@ -4344,6 +4343,19 @@ function observeElementChildNodes(elm) {
4344
4343
 
4345
4344
  function setElementShadowToken(elm, token) {
4346
4345
  elm.$shadowToken$ = token;
4346
+ } // Set the scope token class for *.scoped.css styles
4347
+
4348
+
4349
+ function setScopeTokenClassIfNecessary(elm, owner) {
4350
+ const {
4351
+ cmpTemplate,
4352
+ context
4353
+ } = owner;
4354
+ const token = cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken;
4355
+
4356
+ if (!isUndefined$1(token) && context.hasScopedStyles) {
4357
+ owner.renderer.getClassList(elm).add(token);
4358
+ }
4347
4359
  }
4348
4360
 
4349
4361
  function updateNodeHook(oldVnode, vnode) {
@@ -4417,6 +4429,7 @@ function fallbackElmHook(elm, vnode) {
4417
4429
  const {
4418
4430
  owner
4419
4431
  } = vnode;
4432
+ setScopeTokenClassIfNecessary(elm, owner);
4420
4433
 
4421
4434
  if (owner.shadowMode === 1
4422
4435
  /* Synthetic */
@@ -4427,7 +4440,7 @@ function fallbackElmHook(elm, vnode) {
4427
4440
  }
4428
4441
  } = vnode;
4429
4442
  const {
4430
- shadowAttribute
4443
+ stylesheetToken
4431
4444
  } = owner.context;
4432
4445
 
4433
4446
  if (!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
@@ -4439,7 +4452,7 @@ function fallbackElmHook(elm, vnode) {
4439
4452
  // into each element from the template, so they can be styled accordingly.
4440
4453
 
4441
4454
 
4442
- setElementShadowToken(elm, shadowAttribute);
4455
+ setElementShadowToken(elm, stylesheetToken);
4443
4456
  }
4444
4457
 
4445
4458
  if (process.env.NODE_ENV !== 'production') {
@@ -4528,16 +4541,17 @@ function createViewModelHook(elm, vnode) {
4528
4541
  ctor,
4529
4542
  owner
4530
4543
  } = vnode;
4544
+ setScopeTokenClassIfNecessary(elm, owner);
4531
4545
 
4532
4546
  if (owner.shadowMode === 1
4533
4547
  /* Synthetic */
4534
4548
  ) {
4535
4549
  const {
4536
- shadowAttribute
4550
+ stylesheetToken
4537
4551
  } = owner.context; // when running in synthetic shadow mode, we need to set the shadowToken value
4538
4552
  // into each element from the template, so they can be styled accordingly.
4539
4553
 
4540
- setElementShadowToken(elm, shadowAttribute);
4554
+ setElementShadowToken(elm, stylesheetToken);
4541
4555
  }
4542
4556
 
4543
4557
  const def = getComponentInternalDef(ctor);
@@ -4837,13 +4851,19 @@ const CustomElementHook = {
4837
4851
 
4838
4852
  function linkNodeToShadow(elm, owner) {
4839
4853
  const {
4854
+ renderer,
4855
+ renderMode,
4840
4856
  shadowMode
4841
4857
  } = owner; // TODO [#1164]: this should eventually be done by the polyfill directly
4842
4858
 
4843
- if (shadowMode === 1
4844
- /* Synthetic */
4845
- ) {
4846
- elm[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
4859
+ if (renderer.isSyntheticShadowDefined) {
4860
+ if (shadowMode === 1
4861
+ /* Synthetic */
4862
+ || renderMode === 0
4863
+ /* Light */
4864
+ ) {
4865
+ elm[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
4866
+ }
4847
4867
  }
4848
4868
  }
4849
4869
 
@@ -5189,14 +5209,11 @@ function gid(id) {
5189
5209
 
5190
5210
  const {
5191
5211
  idx,
5192
- renderMode,
5193
5212
  shadowMode
5194
5213
  } = vmBeingRendered;
5195
5214
 
5196
5215
  if (shadowMode === 1
5197
5216
  /* Synthetic */
5198
- && renderMode === 1
5199
- /* Shadow */
5200
5217
  ) {
5201
5218
  return StringReplace.call(id, /\S+/g, id => `${id}-${idx}`);
5202
5219
  }
@@ -5225,14 +5242,11 @@ function fid(url) {
5225
5242
 
5226
5243
  const {
5227
5244
  idx,
5228
- renderMode,
5229
5245
  shadowMode
5230
5246
  } = vmBeingRendered; // Apply transformation only for fragment-only-urls, and only in shadow DOM
5231
5247
 
5232
5248
  if (shadowMode === 1
5233
5249
  /* Synthetic */
5234
- && renderMode === 1
5235
- /* Shadow */
5236
5250
  && /^#/.test(url)) {
5237
5251
  return `${url}-${idx}`;
5238
5252
  }
@@ -5333,6 +5347,10 @@ var api = /*#__PURE__*/Object.freeze({
5333
5347
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
5334
5348
  */
5335
5349
 
5350
+ function makeHostToken(token) {
5351
+ return `${token}-host`;
5352
+ }
5353
+
5336
5354
  function createInlineStyleVNode(content) {
5337
5355
  return h('style', {
5338
5356
  key: 'style',
@@ -5342,59 +5360,100 @@ function createInlineStyleVNode(content) {
5342
5360
  }, [t(content)]);
5343
5361
  }
5344
5362
 
5345
- function updateSyntheticShadowAttributes(vm, template) {
5363
+ function updateStylesheetToken(vm, template) {
5346
5364
  const {
5347
5365
  elm,
5348
5366
  context,
5349
5367
  renderer,
5350
- renderMode
5368
+ renderMode,
5369
+ shadowMode
5351
5370
  } = vm;
5352
5371
  const {
5353
5372
  stylesheets: newStylesheets,
5354
- stylesheetTokens: newStylesheetTokens
5373
+ stylesheetToken: newStylesheetToken
5355
5374
  } = template;
5356
- let newTokens; // Reset the styling token applied to the host element.
5375
+ const isSyntheticShadow = renderMode === 1
5376
+ /* Shadow */
5377
+ && shadowMode === 1
5378
+ /* Synthetic */
5379
+ ;
5380
+ const {
5381
+ hasScopedStyles
5382
+ } = context;
5383
+ let newToken;
5384
+ let newHasTokenInClass;
5385
+ let newHasTokenInAttribute; // Reset the styling token applied to the host element.
5357
5386
 
5358
- const oldHostAttribute = context.hostAttribute;
5387
+ const {
5388
+ stylesheetToken: oldToken,
5389
+ hasTokenInClass: oldHasTokenInClass,
5390
+ hasTokenInAttribute: oldHasTokenInAttribute
5391
+ } = context;
5359
5392
 
5360
- if (!isUndefined$1(oldHostAttribute)) {
5361
- renderer.removeAttribute(elm, oldHostAttribute);
5393
+ if (oldHasTokenInClass) {
5394
+ renderer.getClassList(elm).remove(makeHostToken(oldToken));
5395
+ }
5396
+
5397
+ if (oldHasTokenInAttribute) {
5398
+ renderer.removeAttribute(elm, makeHostToken(oldToken));
5362
5399
  } // Apply the new template styling token to the host element, if the new template has any
5363
- // associated stylesheets.
5400
+ // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
5364
5401
 
5365
5402
 
5366
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0 && renderMode === 1
5367
- /* Shadow */
5368
- ) {
5369
- newTokens = newStylesheetTokens;
5370
- }
5403
+ if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
5404
+ newToken = newStylesheetToken;
5405
+ } // Set the new styling token on the host element
5406
+
5407
+
5408
+ if (!isUndefined$1(newToken)) {
5409
+ if (hasScopedStyles) {
5410
+ renderer.getClassList(elm).add(makeHostToken(newToken));
5411
+ newHasTokenInClass = true;
5412
+ }
5371
5413
 
5372
- if (!isUndefined$1(newTokens)) {
5373
- renderer.setAttribute(elm, newTokens.hostAttribute, '');
5414
+ if (isSyntheticShadow) {
5415
+ renderer.setAttribute(elm, makeHostToken(newToken), '');
5416
+ newHasTokenInAttribute = true;
5417
+ }
5374
5418
  } // Update the styling tokens present on the context object.
5375
5419
 
5376
5420
 
5377
- context.hostAttribute = newTokens === null || newTokens === void 0 ? void 0 : newTokens.hostAttribute;
5378
- context.shadowAttribute = newTokens === null || newTokens === void 0 ? void 0 : newTokens.shadowAttribute;
5421
+ context.stylesheetToken = newToken;
5422
+ context.hasTokenInClass = newHasTokenInClass;
5423
+ context.hasTokenInAttribute = newHasTokenInAttribute;
5379
5424
  }
5380
5425
 
5381
- function evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, nativeShadow) {
5426
+ function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
5382
5427
  const content = [];
5383
5428
 
5384
5429
  for (let i = 0; i < stylesheets.length; i++) {
5385
5430
  let stylesheet = stylesheets[i];
5386
5431
 
5387
5432
  if (isArray$1(stylesheet)) {
5388
- ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, hostSelector, shadowSelector, nativeShadow));
5433
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
5389
5434
  } else {
5390
5435
  if (process.env.NODE_ENV !== 'production') {
5391
5436
  // in dev-mode, we support hot swapping of stylesheet, which means that
5392
5437
  // the component instance might be attempting to use an old version of
5393
5438
  // the stylesheet, while internally, we have a replacement for it.
5394
5439
  stylesheet = getStyleOrSwappedStyle(stylesheet);
5395
- }
5440
+ } // Use the actual `:host` selector if we're rendering global CSS for light DOM, or if we're rendering
5441
+ // native shadow DOM. Synthetic shadow DOM never uses `:host`.
5442
+
5396
5443
 
5397
- ArrayPush$1.call(content, stylesheet(hostSelector, shadowSelector, nativeShadow));
5444
+ const isScopedCss = stylesheet[KEY__SCOPED_CSS];
5445
+ const useActualHostSelector = vm.renderMode === 0
5446
+ /* Light */
5447
+ ? !isScopedCss : vm.shadowMode === 0
5448
+ /* Native */
5449
+ ; // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
5450
+
5451
+ const scopeToken = isScopedCss || vm.shadowMode === 1
5452
+ /* Synthetic */
5453
+ && vm.renderMode === 1
5454
+ /* Shadow */
5455
+ ? stylesheetToken : undefined;
5456
+ ArrayPush$1.call(content, stylesheet(useActualHostSelector, scopeToken));
5398
5457
  }
5399
5458
  }
5400
5459
 
@@ -5404,37 +5463,36 @@ function evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, n
5404
5463
  function getStylesheetsContent(vm, template) {
5405
5464
  const {
5406
5465
  stylesheets,
5407
- stylesheetTokens
5466
+ stylesheetToken
5408
5467
  } = template;
5409
- const {
5410
- renderMode,
5411
- shadowMode
5412
- } = vm;
5413
5468
  let content = [];
5414
5469
 
5415
5470
  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.
5471
+ content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
5472
+ }
5419
5473
 
5420
- if (renderMode === 1
5474
+ return content;
5475
+ } // It might be worth caching this to avoid doing the lookup repeatedly, but
5476
+ // perf testing has not shown it to be a huge improvement yet:
5477
+ // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
5478
+
5479
+
5480
+ function getNearestNativeShadowComponent(vm) {
5481
+ let owner = vm;
5482
+
5483
+ while (!isNull(owner)) {
5484
+ if (owner.renderMode === 1
5421
5485
  /* Shadow */
5422
- && shadowMode === 1
5423
- /* Synthetic */
5424
- && !isUndefined$1(stylesheetTokens)) {
5425
- hostSelector = `[${stylesheetTokens.hostAttribute}]`;
5426
- shadowSelector = `[${stylesheetTokens.shadowAttribute}]`;
5427
- } else {
5428
- hostSelector = '';
5429
- shadowSelector = '';
5486
+ && owner.shadowMode === 0
5487
+ /* Native */
5488
+ ) {
5489
+ return owner;
5430
5490
  }
5431
5491
 
5432
- content = evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, shadowMode === 0
5433
- /* Native */
5434
- );
5492
+ owner = owner.owner;
5435
5493
  }
5436
5494
 
5437
- return content;
5495
+ return owner;
5438
5496
  }
5439
5497
 
5440
5498
  function createStylesheet(vm, stylesheets) {
@@ -5452,13 +5510,26 @@ function createStylesheet(vm, stylesheets) {
5452
5510
  for (let i = 0; i < stylesheets.length; i++) {
5453
5511
  renderer.insertGlobalStylesheet(stylesheets[i]);
5454
5512
  }
5455
-
5456
- return null;
5457
- } else {
5458
- // native shadow or light DOM
5513
+ } else if (renderer.ssr) {
5514
+ // native shadow or light DOM, SSR
5459
5515
  const combinedStylesheetContent = ArrayJoin.call(stylesheets, '\n');
5460
5516
  return createInlineStyleVNode(combinedStylesheetContent);
5517
+ } else {
5518
+ // native shadow or light DOM, DOM renderer
5519
+ const root = getNearestNativeShadowComponent(vm);
5520
+ const isGlobal = isNull(root);
5521
+
5522
+ for (let i = 0; i < stylesheets.length; i++) {
5523
+ if (isGlobal) {
5524
+ renderer.insertGlobalStylesheet(stylesheets[i]);
5525
+ } else {
5526
+ // local level
5527
+ renderer.insertStylesheet(stylesheets[i], root.cmpRoot);
5528
+ }
5529
+ }
5461
5530
  }
5531
+
5532
+ return null;
5462
5533
  }
5463
5534
  /*
5464
5535
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5612,8 +5683,7 @@ function evaluateTemplate(vm, html) {
5612
5683
  context,
5613
5684
  cmpSlots,
5614
5685
  cmpTemplate,
5615
- tro,
5616
- shadowMode
5686
+ tro
5617
5687
  } = vm;
5618
5688
  tro.observe(() => {
5619
5689
  // Reset the cache memoizer for template when needed.
@@ -5638,15 +5708,12 @@ function evaluateTemplate(vm, html) {
5638
5708
 
5639
5709
  vm.cmpTemplate = html; // Create a brand new template cache for the swapped templated.
5640
5710
 
5641
- context.tplCache = create(null); // Update the synthetic shadow attributes on the host element if necessary.
5711
+ context.tplCache = create(null); // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
5642
5712
 
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.
5713
+ context.hasScopedStyles = computeHasScopedStyles(html); // Update the scoping token on the host element.
5649
5714
 
5715
+ updateStylesheetToken(vm, html); // Evaluate, create stylesheet and cache the produced VNode for future
5716
+ // re-rendering.
5650
5717
 
5651
5718
  const stylesheetsContent = getStylesheetsContent(vm, html);
5652
5719
  context.styleVNode = stylesheetsContent.length === 0 ? null : createStylesheet(vm, stylesheetsContent);
@@ -5688,6 +5755,22 @@ function evaluateTemplate(vm, html) {
5688
5755
 
5689
5756
  return vnodes;
5690
5757
  }
5758
+
5759
+ function computeHasScopedStyles(template) {
5760
+ const {
5761
+ stylesheets
5762
+ } = template;
5763
+
5764
+ if (!isUndefined$1(stylesheets)) {
5765
+ for (let i = 0; i < stylesheets.length; i++) {
5766
+ if (isTrue(stylesheets[i][KEY__SCOPED_CSS])) {
5767
+ return true;
5768
+ }
5769
+ }
5770
+ }
5771
+
5772
+ return false;
5773
+ }
5691
5774
  /*
5692
5775
  * Copyright (c) 2018, salesforce.com, inc.
5693
5776
  * All rights reserved.
@@ -5728,12 +5811,9 @@ function invokeComponentCallback(vm, fn, args) {
5728
5811
  callHook,
5729
5812
  owner
5730
5813
  } = vm;
5731
- let result;
5732
5814
  runWithBoundaryProtection(vm, owner, noop, () => {
5733
- // job
5734
- result = callHook(component, fn, args);
5815
+ callHook(component, fn, args);
5735
5816
  }, noop);
5736
- return result;
5737
5817
  }
5738
5818
 
5739
5819
  function invokeComponentConstructor(vm, Ctor) {
@@ -5807,33 +5887,6 @@ function invokeComponentRenderMethod(vm) {
5807
5887
  return renderInvocationSuccessful ? evaluateTemplate(vm, html) : [];
5808
5888
  }
5809
5889
 
5810
- function invokeComponentRenderedCallback(vm) {
5811
- const {
5812
- def: {
5813
- renderedCallback
5814
- },
5815
- component,
5816
- callHook,
5817
- owner
5818
- } = vm;
5819
-
5820
- if (!isUndefined$1(renderedCallback)) {
5821
- runWithBoundaryProtection(vm, owner, () => {
5822
- logOperationStart(4
5823
- /* RenderedCallback */
5824
- , vm);
5825
- }, () => {
5826
- // job
5827
- callHook(component, renderedCallback);
5828
- }, () => {
5829
- // post
5830
- logOperationEnd(4
5831
- /* RenderedCallback */
5832
- , vm);
5833
- });
5834
- }
5835
- }
5836
-
5837
5890
  function invokeEventListener(vm, fn, thisValue, event) {
5838
5891
  const {
5839
5892
  callHook,
@@ -5989,7 +6042,6 @@ function invokeServiceHook(vm, cbs) {
5989
6042
  */
5990
6043
 
5991
6044
 
5992
- const isNativeShadowRootDefined = _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED];
5993
6045
  let idx = 0;
5994
6046
  /** The internal slot used to associate different objects the engine manipulates with the VM */
5995
6047
 
@@ -6098,29 +6150,6 @@ function getNearestShadowAncestor(vm) {
6098
6150
  return ancestor;
6099
6151
  }
6100
6152
 
6101
- function assertNotSyntheticComposedWithinNative(vm) {
6102
- const isSynthetic = vm.renderMode === 1
6103
- /* Shadow */
6104
- && vm.shadowMode === 1
6105
- /* Synthetic */
6106
- ;
6107
-
6108
- if (!isSynthetic) {
6109
- return;
6110
- }
6111
-
6112
- const ancestor = getNearestShadowAncestor(vm);
6113
-
6114
- if (!isNull(ancestor)) {
6115
- // Any native shadow component being an ancestor of a synthetic shadow component is disallowed.
6116
- assert.isFalse(ancestor.renderMode === 1
6117
- /* Shadow */
6118
- && ancestor.shadowMode === 0
6119
- /* Native */
6120
- , `${getComponentTag(vm)} (synthetic shadow DOM) cannot be composed inside of ${getComponentTag(ancestor)} (native shadow DOM), because synthetic-within-native composition is disallowed`);
6121
- }
6122
- }
6123
-
6124
6153
  function createVM(elm, def, options) {
6125
6154
  const {
6126
6155
  mode,
@@ -6128,22 +6157,6 @@ function createVM(elm, def, options) {
6128
6157
  renderer,
6129
6158
  tagName
6130
6159
  } = options;
6131
- let shadowMode;
6132
-
6133
- if (renderer.syntheticShadow) {
6134
- shadowMode = def.shadowSupportMode === "any"
6135
- /* Any */
6136
- && isNativeShadowRootDefined ? 0
6137
- /* Native */
6138
- : 1
6139
- /* Synthetic */
6140
- ;
6141
- } else {
6142
- shadowMode = 0
6143
- /* Native */
6144
- ;
6145
- }
6146
-
6147
6160
  const vm = {
6148
6161
  elm,
6149
6162
  def,
@@ -6166,10 +6179,12 @@ function createVM(elm, def, options) {
6166
6179
  oar: create(null),
6167
6180
  cmpTemplate: null,
6168
6181
  renderMode: def.renderMode,
6169
- shadowMode,
6182
+ shadowMode: null,
6170
6183
  context: {
6171
- hostAttribute: undefined,
6172
- shadowAttribute: undefined,
6184
+ stylesheetToken: undefined,
6185
+ hasTokenInClass: undefined,
6186
+ hasTokenInAttribute: undefined,
6187
+ hasScopedStyles: undefined,
6173
6188
  styleVNode: null,
6174
6189
  tplCache: EmptyObject,
6175
6190
  wiredConnecting: EmptyArray,
@@ -6182,26 +6197,87 @@ function createVM(elm, def, options) {
6182
6197
  setHook,
6183
6198
  getHook
6184
6199
  };
6200
+ vm.shadowMode = computeShadowMode(vm);
6185
6201
  vm.tro = getTemplateReactiveObserver(vm);
6186
6202
 
6187
6203
  if (process.env.NODE_ENV !== 'production') {
6188
6204
  vm.toString = () => {
6189
6205
  return `[object:vm ${def.name} (${vm.idx})]`;
6190
6206
  };
6191
-
6192
- assertNotSyntheticComposedWithinNative(vm);
6193
6207
  } // Create component instance associated to the vm and the element.
6194
6208
 
6195
6209
 
6196
6210
  invokeComponentConstructor(vm, def.ctor); // Initializing the wire decorator per instance only when really needed
6197
6211
 
6198
- if (isFalse(renderer.ssr) && hasWireAdapters(vm)) {
6212
+ if (hasWireAdapters(vm)) {
6199
6213
  installWireAdapters(vm);
6200
6214
  }
6201
6215
 
6202
6216
  return vm;
6203
6217
  }
6204
6218
 
6219
+ function computeShadowMode(vm) {
6220
+ const {
6221
+ def,
6222
+ renderer
6223
+ } = vm;
6224
+ const {
6225
+ isNativeShadowDefined,
6226
+ isSyntheticShadowDefined
6227
+ } = renderer;
6228
+ let shadowMode;
6229
+
6230
+ if (isSyntheticShadowDefined) {
6231
+ if (def.renderMode === 0
6232
+ /* Light */
6233
+ ) {
6234
+ // ShadowMode.Native implies "not synthetic shadow" which is consistent with how
6235
+ // everything defaults to native when the synthetic shadow polyfill is unavailable.
6236
+ shadowMode = 0
6237
+ /* Native */
6238
+ ;
6239
+ } else if (isNativeShadowDefined) {
6240
+ if (def.shadowSupportMode === "any"
6241
+ /* Any */
6242
+ ) {
6243
+ shadowMode = 0
6244
+ /* Native */
6245
+ ;
6246
+ } else {
6247
+ const shadowAncestor = getNearestShadowAncestor(vm);
6248
+
6249
+ if (!isNull(shadowAncestor) && shadowAncestor.shadowMode === 0
6250
+ /* Native */
6251
+ ) {
6252
+ // Transitive support for native Shadow DOM. A component in native mode
6253
+ // transitively opts all of its descendants into native.
6254
+ shadowMode = 0
6255
+ /* Native */
6256
+ ;
6257
+ } else {
6258
+ // Synthetic if neither this component nor any of its ancestors are configured
6259
+ // to be native.
6260
+ shadowMode = 1
6261
+ /* Synthetic */
6262
+ ;
6263
+ }
6264
+ }
6265
+ } else {
6266
+ // Synthetic if there is no native Shadow DOM support.
6267
+ shadowMode = 1
6268
+ /* Synthetic */
6269
+ ;
6270
+ }
6271
+ } else {
6272
+ // Native if the synthetic shadow polyfill is unavailable.
6273
+ shadowMode = 0
6274
+ /* Native */
6275
+ ;
6276
+ }
6277
+
6278
+ return shadowMode;
6279
+ }
6280
+
6205
6281
  function assertIsVM(obj) {
6206
6282
  if (isNull(obj) || !isObject(obj) || !('cmpRoot' in obj)) {
6207
6283
  throw new TypeError(`${obj} is not a VM.`);
@@ -6283,7 +6359,14 @@ function patchShadowRoot(vm, newCh) {
6283
6359
  }
6284
6360
 
6285
6361
  function runRenderedCallback(vm) {
6286
- if (isTrue(vm.renderer.ssr)) {
6362
+ const {
6363
+ renderer,
6364
+ def: {
6365
+ renderedCallback
6366
+ }
6367
+ } = vm;
6368
+
6369
+ if (isTrue(renderer.ssr)) {
6287
6370
  return;
6288
6371
  }
6289
6372
 
@@ -6295,7 +6378,15 @@ function runRenderedCallback(vm) {
6295
6378
  invokeServiceHook(vm, rendered);
6296
6379
  }
6297
6380
 
6298
- invokeComponentRenderedCallback(vm);
6381
+ if (!isUndefined$1(renderedCallback)) {
6382
+ logOperationStart(4
6383
+ /* RenderedCallback */
6384
+ , vm);
6385
+ invokeComponentCallback(vm, renderedCallback);
6386
+ logOperationEnd(4
6387
+ /* RenderedCallback */
6388
+ , vm);
6389
+ }
6299
6390
  }
6300
6391
 
6301
6392
  let rehydrateQueue = [];
@@ -6910,11 +7001,14 @@ function installWireAdapters(vm) {
6910
7001
  ArrayPush$1.call(wiredConnecting, () => {
6911
7002
  connector.connect();
6912
7003
 
6913
- if (hasDynamicParams) {
6914
- Promise.resolve().then(computeConfigAndUpdate);
6915
- } else {
6916
- computeConfigAndUpdate();
7004
+ if (!runtimeFlags.ENABLE_WIRE_SYNC_EMIT) {
7005
+ if (hasDynamicParams) {
7006
+ Promise.resolve().then(computeConfigAndUpdate);
7007
+ return;
7008
+ }
6917
7009
  }
7010
+
7011
+ computeConfigAndUpdate();
6918
7012
  });
6919
7013
  ArrayPush$1.call(wiredDisconnecting, () => {
6920
7014
  connector.disconnect();
@@ -7021,7 +7115,7 @@ function readonly(obj) {
7021
7115
 
7022
7116
  return reactiveMembrane.getReadOnlyProxy(obj);
7023
7117
  }
7024
- /* version: 2.3.3 */
7118
+ /* version: 2.5.0 */
7025
7119
 
7026
7120
  /*
7027
7121
  * Copyright (c) 2020, salesforce.com, inc.
@@ -7112,7 +7206,8 @@ class HTMLElement$1 {
7112
7206
 
7113
7207
  const renderer = {
7114
7208
  ssr: true,
7115
- syntheticShadow: false,
7209
+ isNativeShadowDefined: false,
7210
+ isSyntheticShadowDefined: false,
7116
7211
 
7117
7212
  insert(node, parent, anchor) {
7118
7213
  if (node.parent !== null && node.parent !== parent) {
@@ -7330,6 +7425,10 @@ const renderer = {
7330
7425
  // synthetic shadow.
7331
7426
  },
7332
7427
 
7428
+ insertStylesheet() {// Noop on SSR (for now). This need to be reevaluated whenever we will implement support for
7429
+ // synthetic shadow.
7430
+ },
7431
+
7333
7432
  addEventListener() {// Noop on SSR.
7334
7433
  },
7335
7434
 
@@ -7487,6 +7586,6 @@ function renderComponent(tagName, Ctor, props = {}) {
7487
7586
 
7488
7587
  freeze(LightningElement);
7489
7588
  seal(LightningElement.prototype);
7490
- /* version: 2.3.3 */
7589
+ /* version: 2.5.0 */
7491
7590
 
7492
7591
  export { LightningElement, api$1 as api, createContextProvider, getComponentDef, isComponentConstructor, readonly, register, registerComponent, registerDecorators, registerTemplate, renderComponent, sanitizeAttribute, setFeatureFlag, setFeatureFlagForTest, track, unwrap, wire };