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
@@ -107,6 +107,10 @@ var LWC = (function (exports) {
107
107
  return obj === false;
108
108
  }
109
109
 
110
+ function isBoolean(obj) {
111
+ return typeof obj === 'boolean';
112
+ }
113
+
110
114
  function isFunction$1(obj) {
111
115
  return typeof obj === 'function';
112
116
  }
@@ -245,6 +249,7 @@ var LWC = (function (exports) {
245
249
  const KEY__SHADOW_RESOLVER = '$shadowResolver$';
246
250
  const KEY__SHADOW_TOKEN = '$shadowToken$';
247
251
  const KEY__SYNTHETIC_MODE = '$$lwc-synthetic-mode';
252
+ const KEY__SCOPED_CSS = '$scoped$';
248
253
  /**
249
254
  * Map composed of properties to attributes not following the HTML property to attribute mapping
250
255
  * convention.
@@ -293,7 +298,7 @@ var LWC = (function (exports) {
293
298
  CACHED_PROPERTY_ATTRIBUTE_MAPPING.set(propName, attributeName);
294
299
  return attributeName;
295
300
  }
296
- /** version: 2.3.4 */
301
+ /** version: 2.5.1 */
297
302
 
298
303
  /*
299
304
  * Copyright (c) 2018, salesforce.com, inc.
@@ -398,19 +403,33 @@ var LWC = (function (exports) {
398
403
  */
399
404
 
400
405
 
406
+ const features = {
407
+ ENABLE_REACTIVE_SETTER: null,
408
+ ENABLE_HMR: null,
409
+ ENABLE_INNER_OUTER_TEXT_PATCH: null,
410
+ ENABLE_ELEMENT_PATCH: null,
411
+ ENABLE_NODE_LIST_PATCH: null,
412
+ ENABLE_HTML_COLLECTIONS_PATCH: null,
413
+ ENABLE_NODE_PATCH: null,
414
+ ENABLE_NON_COMPOSED_EVENTS_LEAKAGE: null,
415
+ ENABLE_MIXED_SHADOW_MODE: null,
416
+ ENABLE_WIRE_SYNC_EMIT: null
417
+ };
418
+
401
419
  if (!_globalThis.lwcRuntimeFlags) {
402
420
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', {
403
421
  value: create(null)
404
422
  });
405
423
  }
406
424
 
407
- const runtimeFlags = _globalThis.lwcRuntimeFlags; // This function is not supported for use within components and is meant for
408
- // configuring runtime feature flags during app initialization.
425
+ const runtimeFlags = _globalThis.lwcRuntimeFlags;
426
+ /**
427
+ * Set the value at runtime of a given feature flag. This method only be invoked once per feature
428
+ * flag. It is meant to be used during the app initialization.
429
+ */
409
430
 
410
431
  function setFeatureFlag(name, value) {
411
- const isBoolean = isTrue(value) || isFalse(value);
412
-
413
- if (!isBoolean) {
432
+ if (!isBoolean(value)) {
414
433
  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.`;
415
434
 
416
435
  {
@@ -420,9 +439,10 @@ var LWC = (function (exports) {
420
439
  }
421
440
  }
422
441
 
423
- if (isUndefined$1(featureFlagLookup[name])) {
424
- // eslint-disable-next-line no-console
425
- 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.`);
442
+ if (isUndefined$1(features[name])) {
443
+ const availableFlags = keys(features).map(name => `"${name}"`).join(', '); // eslint-disable-next-line no-console
444
+
445
+ console.warn(`Failed to set the value "${value}" for the runtime feature flag "${name}" because it is undefined. Available flags: ${availableFlags}.`);
426
446
  return;
427
447
  }
428
448
 
@@ -436,34 +456,20 @@ var LWC = (function (exports) {
436
456
  return;
437
457
  }
438
458
 
439
- Object.defineProperty(runtimeFlags, name, {
459
+ defineProperty(runtimeFlags, name, {
440
460
  value
441
461
  });
442
462
  }
443
- } // This function is exposed to components to facilitate testing so we add a
444
- // check to make sure it is not invoked in production.
463
+ }
464
+ /**
465
+ * Set the value at runtime of a given feature flag. This method should only be used for testing
466
+ * purposes. It is a no-op when invoked in production mode.
467
+ */
445
468
 
446
469
 
447
470
  function setFeatureFlagForTest(name, value) {
448
471
  }
449
-
450
- const featureFlagLookup = {
451
- ENABLE_REACTIVE_SETTER: null,
452
- ENABLE_HMR: null,
453
- // Flag to toggle on/off the enforcement of innerText/outerText shadow dom semantic in elements when using synthetic shadow.
454
- // Note: Once active, elements outside the lwc boundary are controlled by the ENABLE_ELEMENT_PATCH flag.
455
- ENABLE_INNER_OUTER_TEXT_PATCH: null,
456
- // Flags to toggle on/off the enforcement of shadow dom semantic in element/node outside lwc boundary when using synthetic shadow.
457
- ENABLE_ELEMENT_PATCH: null,
458
- ENABLE_NODE_LIST_PATCH: null,
459
- ENABLE_HTML_COLLECTIONS_PATCH: null,
460
- ENABLE_NODE_PATCH: null,
461
- // Disables the fix for #2121 where non-composed events are visible outside of their shadow root.
462
- ENABLE_NON_COMPOSED_EVENTS_LEAKAGE: null,
463
- ENABLE_LIGHT_DOM_COMPONENTS: null,
464
- ENABLE_MIXED_SHADOW_MODE: null
465
- };
466
- /** version: 2.3.4 */
472
+ /** version: 2.5.1 */
467
473
 
468
474
  /* proxy-compat-disable */
469
475
 
@@ -474,6 +480,7 @@ var LWC = (function (exports) {
474
480
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
475
481
  */
476
482
 
483
+
477
484
  let nextTickCallbackQueue = [];
478
485
  const SPACE_CHAR = 32;
479
486
  const EmptyObject = seal(create(null));
@@ -2192,12 +2199,6 @@ var LWC = (function (exports) {
2192
2199
  associateVM(component, vm);
2193
2200
  associateVM(elm, vm);
2194
2201
 
2195
- if (!runtimeFlags.ENABLE_LIGHT_DOM_COMPONENTS) {
2196
- assert.isTrue(def.renderMode !== 0
2197
- /* Light */
2198
- , `${def.name || 'Anonymous class'} is an invalid LWC component. Light DOM components are not available in this environment.`);
2199
- }
2200
-
2201
2202
  if (vm.renderMode === 1
2202
2203
  /* Shadow */
2203
2204
  ) {
@@ -2226,7 +2227,7 @@ var LWC = (function (exports) {
2226
2227
  });
2227
2228
  vm.cmpRoot = cmpRoot;
2228
2229
  associateVM(cmpRoot, vm);
2229
- } // @ts-ignore
2230
+ }
2230
2231
 
2231
2232
 
2232
2233
  LightningElement.prototype = {
@@ -2755,8 +2756,15 @@ var LWC = (function (exports) {
2755
2756
 
2756
2757
  descriptor = createPublicAccessorDescriptor(fieldName, descriptor);
2757
2758
  } else {
2759
+ // with the same name, the property is defined as a public accessor. This branch is
2760
+ // only here for backward compatibility reasons.
2758
2761
 
2759
- descriptor = createPublicPropertyDescriptor(fieldName);
2762
+
2763
+ if (!isUndefined$1(descriptor) && !isUndefined$1(descriptor.get)) {
2764
+ descriptor = createPublicAccessorDescriptor(fieldName, descriptor);
2765
+ } else {
2766
+ descriptor = createPublicPropertyDescriptor(fieldName);
2767
+ }
2760
2768
  }
2761
2769
 
2762
2770
  apiFields[fieldName] = descriptor;
@@ -2817,8 +2825,15 @@ var LWC = (function (exports) {
2817
2825
  for (let i = 0, n = fields.length; i < n; i++) {
2818
2826
  const fieldName = fields[i];
2819
2827
  descriptor = getOwnPropertyDescriptor$1(proto, fieldName);
2828
+ // tracked property. This is only here for backward compatibility purposes.
2820
2829
 
2821
- observedFields[fieldName] = createObservedFieldPropertyDescriptor(fieldName);
2830
+
2831
+ const isDuplicatePublicProp = !isUndefined$1(publicProps) && fieldName in publicProps;
2832
+ const isDuplicateTrackedProp = !isUndefined$1(track) && fieldName in track;
2833
+
2834
+ if (!isDuplicatePublicProp && !isDuplicateTrackedProp) {
2835
+ observedFields[fieldName] = createObservedFieldPropertyDescriptor(fieldName);
2836
+ }
2822
2837
  }
2823
2838
  }
2824
2839
 
@@ -3364,6 +3379,19 @@ var LWC = (function (exports) {
3364
3379
 
3365
3380
  function setElementShadowToken(elm, token) {
3366
3381
  elm.$shadowToken$ = token;
3382
+ } // Set the scope token class for *.scoped.css styles
3383
+
3384
+
3385
+ function setScopeTokenClassIfNecessary(elm, owner) {
3386
+ const {
3387
+ cmpTemplate,
3388
+ context
3389
+ } = owner;
3390
+ const token = cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken;
3391
+
3392
+ if (!isUndefined$1(token) && context.hasScopedStyles) {
3393
+ owner.renderer.getClassList(elm).add(token);
3394
+ }
3367
3395
  }
3368
3396
 
3369
3397
  function updateNodeHook(oldVnode, vnode) {
@@ -3414,6 +3442,7 @@ var LWC = (function (exports) {
3414
3442
  const {
3415
3443
  owner
3416
3444
  } = vnode;
3445
+ setScopeTokenClassIfNecessary(elm, owner);
3417
3446
 
3418
3447
  if (owner.shadowMode === 1
3419
3448
  /* Synthetic */
@@ -3424,7 +3453,7 @@ var LWC = (function (exports) {
3424
3453
  }
3425
3454
  } = vnode;
3426
3455
  const {
3427
- shadowAttribute
3456
+ stylesheetToken
3428
3457
  } = owner.context;
3429
3458
 
3430
3459
  if (!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
@@ -3436,7 +3465,7 @@ var LWC = (function (exports) {
3436
3465
  // into each element from the template, so they can be styled accordingly.
3437
3466
 
3438
3467
 
3439
- setElementShadowToken(elm, shadowAttribute);
3468
+ setElementShadowToken(elm, stylesheetToken);
3440
3469
  }
3441
3470
  }
3442
3471
 
@@ -3507,16 +3536,17 @@ var LWC = (function (exports) {
3507
3536
  ctor,
3508
3537
  owner
3509
3538
  } = vnode;
3539
+ setScopeTokenClassIfNecessary(elm, owner);
3510
3540
 
3511
3541
  if (owner.shadowMode === 1
3512
3542
  /* Synthetic */
3513
3543
  ) {
3514
3544
  const {
3515
- shadowAttribute
3545
+ stylesheetToken
3516
3546
  } = owner.context; // when running in synthetic shadow mode, we need to set the shadowToken value
3517
3547
  // into each element from the template, so they can be styled accordingly.
3518
3548
 
3519
- setElementShadowToken(elm, shadowAttribute);
3549
+ setElementShadowToken(elm, stylesheetToken);
3520
3550
  }
3521
3551
 
3522
3552
  const def = getComponentInternalDef(ctor);
@@ -3804,13 +3834,19 @@ var LWC = (function (exports) {
3804
3834
 
3805
3835
  function linkNodeToShadow(elm, owner) {
3806
3836
  const {
3837
+ renderer,
3838
+ renderMode,
3807
3839
  shadowMode
3808
3840
  } = owner; // TODO [#1164]: this should eventually be done by the polyfill directly
3809
3841
 
3810
- if (shadowMode === 1
3811
- /* Synthetic */
3812
- ) {
3813
- elm[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
3842
+ if (renderer.isSyntheticShadowDefined) {
3843
+ if (shadowMode === 1
3844
+ /* Synthetic */
3845
+ || renderMode === 0
3846
+ /* Light */
3847
+ ) {
3848
+ elm[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
3849
+ }
3814
3850
  }
3815
3851
  }
3816
3852
 
@@ -4045,14 +4081,11 @@ var LWC = (function (exports) {
4045
4081
 
4046
4082
  const {
4047
4083
  idx,
4048
- renderMode,
4049
4084
  shadowMode
4050
4085
  } = vmBeingRendered;
4051
4086
 
4052
4087
  if (shadowMode === 1
4053
4088
  /* Synthetic */
4054
- && renderMode === 1
4055
- /* Shadow */
4056
4089
  ) {
4057
4090
  return StringReplace.call(id, /\S+/g, id => `${id}-${idx}`);
4058
4091
  }
@@ -4076,14 +4109,11 @@ var LWC = (function (exports) {
4076
4109
 
4077
4110
  const {
4078
4111
  idx,
4079
- renderMode,
4080
4112
  shadowMode
4081
4113
  } = vmBeingRendered; // Apply transformation only for fragment-only-urls, and only in shadow DOM
4082
4114
 
4083
4115
  if (shadowMode === 1
4084
4116
  /* Synthetic */
4085
- && renderMode === 1
4086
- /* Shadow */
4087
4117
  && /^#/.test(url)) {
4088
4118
  return `${url}-${idx}`;
4089
4119
  }
@@ -4176,6 +4206,10 @@ var LWC = (function (exports) {
4176
4206
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4177
4207
  */
4178
4208
 
4209
+ function makeHostToken(token) {
4210
+ return `${token}-host`;
4211
+ }
4212
+
4179
4213
  function createInlineStyleVNode(content) {
4180
4214
  return h('style', {
4181
4215
  key: 'style',
@@ -4185,53 +4219,94 @@ var LWC = (function (exports) {
4185
4219
  }, [t(content)]);
4186
4220
  }
4187
4221
 
4188
- function updateSyntheticShadowAttributes(vm, template) {
4222
+ function updateStylesheetToken(vm, template) {
4189
4223
  const {
4190
4224
  elm,
4191
4225
  context,
4192
4226
  renderer,
4193
- renderMode
4227
+ renderMode,
4228
+ shadowMode
4194
4229
  } = vm;
4195
4230
  const {
4196
4231
  stylesheets: newStylesheets,
4197
- stylesheetTokens: newStylesheetTokens
4232
+ stylesheetToken: newStylesheetToken
4198
4233
  } = template;
4199
- let newTokens; // Reset the styling token applied to the host element.
4234
+ const isSyntheticShadow = renderMode === 1
4235
+ /* Shadow */
4236
+ && shadowMode === 1
4237
+ /* Synthetic */
4238
+ ;
4239
+ const {
4240
+ hasScopedStyles
4241
+ } = context;
4242
+ let newToken;
4243
+ let newHasTokenInClass;
4244
+ let newHasTokenInAttribute; // Reset the styling token applied to the host element.
4245
+
4246
+ const {
4247
+ stylesheetToken: oldToken,
4248
+ hasTokenInClass: oldHasTokenInClass,
4249
+ hasTokenInAttribute: oldHasTokenInAttribute
4250
+ } = context;
4200
4251
 
4201
- const oldHostAttribute = context.hostAttribute;
4252
+ if (oldHasTokenInClass) {
4253
+ renderer.getClassList(elm).remove(makeHostToken(oldToken));
4254
+ }
4202
4255
 
4203
- if (!isUndefined$1(oldHostAttribute)) {
4204
- renderer.removeAttribute(elm, oldHostAttribute);
4256
+ if (oldHasTokenInAttribute) {
4257
+ renderer.removeAttribute(elm, makeHostToken(oldToken));
4205
4258
  } // Apply the new template styling token to the host element, if the new template has any
4206
- // associated stylesheets.
4259
+ // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
4207
4260
 
4208
4261
 
4209
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0 && renderMode === 1
4210
- /* Shadow */
4211
- ) {
4212
- newTokens = newStylesheetTokens;
4213
- }
4262
+ if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
4263
+ newToken = newStylesheetToken;
4264
+ } // Set the new styling token on the host element
4265
+
4214
4266
 
4215
- if (!isUndefined$1(newTokens)) {
4216
- renderer.setAttribute(elm, newTokens.hostAttribute, '');
4267
+ if (!isUndefined$1(newToken)) {
4268
+ if (hasScopedStyles) {
4269
+ renderer.getClassList(elm).add(makeHostToken(newToken));
4270
+ newHasTokenInClass = true;
4271
+ }
4272
+
4273
+ if (isSyntheticShadow) {
4274
+ renderer.setAttribute(elm, makeHostToken(newToken), '');
4275
+ newHasTokenInAttribute = true;
4276
+ }
4217
4277
  } // Update the styling tokens present on the context object.
4218
4278
 
4219
4279
 
4220
- context.hostAttribute = newTokens === null || newTokens === void 0 ? void 0 : newTokens.hostAttribute;
4221
- context.shadowAttribute = newTokens === null || newTokens === void 0 ? void 0 : newTokens.shadowAttribute;
4280
+ context.stylesheetToken = newToken;
4281
+ context.hasTokenInClass = newHasTokenInClass;
4282
+ context.hasTokenInAttribute = newHasTokenInAttribute;
4222
4283
  }
4223
4284
 
4224
- function evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, nativeShadow) {
4285
+ function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
4225
4286
  const content = [];
4226
4287
 
4227
4288
  for (let i = 0; i < stylesheets.length; i++) {
4228
4289
  let stylesheet = stylesheets[i];
4229
4290
 
4230
4291
  if (isArray$1(stylesheet)) {
4231
- ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, hostSelector, shadowSelector, nativeShadow));
4292
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
4232
4293
  } else {
4233
-
4234
- ArrayPush$1.call(content, stylesheet(hostSelector, shadowSelector, nativeShadow));
4294
+ // native shadow DOM. Synthetic shadow DOM never uses `:host`.
4295
+
4296
+
4297
+ const isScopedCss = stylesheet[KEY__SCOPED_CSS];
4298
+ const useActualHostSelector = vm.renderMode === 0
4299
+ /* Light */
4300
+ ? !isScopedCss : vm.shadowMode === 0
4301
+ /* Native */
4302
+ ; // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
4303
+
4304
+ const scopeToken = isScopedCss || vm.shadowMode === 1
4305
+ /* Synthetic */
4306
+ && vm.renderMode === 1
4307
+ /* Shadow */
4308
+ ? stylesheetToken : undefined;
4309
+ ArrayPush$1.call(content, stylesheet(useActualHostSelector, scopeToken));
4235
4310
  }
4236
4311
  }
4237
4312
 
@@ -4241,37 +4316,36 @@ var LWC = (function (exports) {
4241
4316
  function getStylesheetsContent(vm, template) {
4242
4317
  const {
4243
4318
  stylesheets,
4244
- stylesheetTokens
4319
+ stylesheetToken
4245
4320
  } = template;
4246
- const {
4247
- renderMode,
4248
- shadowMode
4249
- } = vm;
4250
4321
  let content = [];
4251
4322
 
4252
4323
  if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
4253
- let hostSelector;
4254
- let shadowSelector; // Scoping with the tokens is only necessary for synthetic shadow. For both
4255
- // light DOM elements and native shadow, we just render the CSS as-is.
4324
+ content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
4325
+ }
4326
+
4327
+ return content;
4328
+ } // It might be worth caching this to avoid doing the lookup repeatedly, but
4329
+ // perf testing has not shown it to be a huge improvement yet:
4330
+ // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
4331
+
4256
4332
 
4257
- if (renderMode === 1
4333
+ function getNearestNativeShadowComponent(vm) {
4334
+ let owner = vm;
4335
+
4336
+ while (!isNull(owner)) {
4337
+ if (owner.renderMode === 1
4258
4338
  /* Shadow */
4259
- && shadowMode === 1
4260
- /* Synthetic */
4261
- && !isUndefined$1(stylesheetTokens)) {
4262
- hostSelector = `[${stylesheetTokens.hostAttribute}]`;
4263
- shadowSelector = `[${stylesheetTokens.shadowAttribute}]`;
4264
- } else {
4265
- hostSelector = '';
4266
- shadowSelector = '';
4339
+ && owner.shadowMode === 0
4340
+ /* Native */
4341
+ ) {
4342
+ return owner;
4267
4343
  }
4268
4344
 
4269
- content = evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, shadowMode === 0
4270
- /* Native */
4271
- );
4345
+ owner = owner.owner;
4272
4346
  }
4273
4347
 
4274
- return content;
4348
+ return owner;
4275
4349
  }
4276
4350
 
4277
4351
  function createStylesheet(vm, stylesheets) {
@@ -4289,13 +4363,26 @@ var LWC = (function (exports) {
4289
4363
  for (let i = 0; i < stylesheets.length; i++) {
4290
4364
  renderer.insertGlobalStylesheet(stylesheets[i]);
4291
4365
  }
4292
-
4293
- return null;
4294
- } else {
4295
- // native shadow or light DOM
4366
+ } else if (renderer.ssr) {
4367
+ // native shadow or light DOM, SSR
4296
4368
  const combinedStylesheetContent = ArrayJoin.call(stylesheets, '\n');
4297
4369
  return createInlineStyleVNode(combinedStylesheetContent);
4370
+ } else {
4371
+ // native shadow or light DOM, DOM renderer
4372
+ const root = getNearestNativeShadowComponent(vm);
4373
+ const isGlobal = isNull(root);
4374
+
4375
+ for (let i = 0; i < stylesheets.length; i++) {
4376
+ if (isGlobal) {
4377
+ renderer.insertGlobalStylesheet(stylesheets[i]);
4378
+ } else {
4379
+ // local level
4380
+ renderer.insertStylesheet(stylesheets[i], root.cmpRoot);
4381
+ }
4382
+ }
4298
4383
  }
4384
+
4385
+ return null;
4299
4386
  }
4300
4387
  /** Indicates if operations should be logged by the profiler. */
4301
4388
 
@@ -4417,8 +4504,7 @@ var LWC = (function (exports) {
4417
4504
  context,
4418
4505
  cmpSlots,
4419
4506
  cmpTemplate,
4420
- tro,
4421
- shadowMode
4507
+ tro
4422
4508
  } = vm;
4423
4509
  tro.observe(() => {
4424
4510
  // Reset the cache memoizer for template when needed.
@@ -4441,15 +4527,12 @@ var LWC = (function (exports) {
4441
4527
 
4442
4528
  vm.cmpTemplate = html; // Create a brand new template cache for the swapped templated.
4443
4529
 
4444
- context.tplCache = create(null); // Update the synthetic shadow attributes on the host element if necessary.
4530
+ context.tplCache = create(null); // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
4445
4531
 
4446
- if (shadowMode === 1
4447
- /* Synthetic */
4448
- ) {
4449
- updateSyntheticShadowAttributes(vm, html);
4450
- } // Evaluate, create stylesheet and cache the produced VNode for future
4451
- // re-rendering.
4532
+ context.hasScopedStyles = computeHasScopedStyles(html); // Update the scoping token on the host element.
4452
4533
 
4534
+ updateStylesheetToken(vm, html); // Evaluate, create stylesheet and cache the produced VNode for future
4535
+ // re-rendering.
4453
4536
 
4454
4537
  const stylesheetsContent = getStylesheetsContent(vm, html);
4455
4538
  context.styleVNode = stylesheetsContent.length === 0 ? null : createStylesheet(vm, stylesheetsContent);
@@ -4482,6 +4565,22 @@ var LWC = (function (exports) {
4482
4565
 
4483
4566
  return vnodes;
4484
4567
  }
4568
+
4569
+ function computeHasScopedStyles(template) {
4570
+ const {
4571
+ stylesheets
4572
+ } = template;
4573
+
4574
+ if (!isUndefined$1(stylesheets)) {
4575
+ for (let i = 0; i < stylesheets.length; i++) {
4576
+ if (isTrue(stylesheets[i][KEY__SCOPED_CSS])) {
4577
+ return true;
4578
+ }
4579
+ }
4580
+ }
4581
+
4582
+ return false;
4583
+ }
4485
4584
  /*
4486
4585
  * Copyright (c) 2018, salesforce.com, inc.
4487
4586
  * All rights reserved.
@@ -4722,7 +4821,6 @@ var LWC = (function (exports) {
4722
4821
  */
4723
4822
 
4724
4823
 
4725
- const isNativeShadowRootDefined = _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED];
4726
4824
  let idx = 0;
4727
4825
  /** The internal slot used to associate different objects the engine manipulates with the VM */
4728
4826
 
@@ -4808,6 +4906,18 @@ var LWC = (function (exports) {
4808
4906
  resetComponentStateWhenRemoved(vm);
4809
4907
  }
4810
4908
 
4909
+ function getNearestShadowAncestor(vm) {
4910
+ let ancestor = vm.owner;
4911
+
4912
+ while (!isNull(ancestor) && ancestor.renderMode === 0
4913
+ /* Light */
4914
+ ) {
4915
+ ancestor = ancestor.owner;
4916
+ }
4917
+
4918
+ return ancestor;
4919
+ }
4920
+
4811
4921
  function createVM(elm, def, options) {
4812
4922
  const {
4813
4923
  mode,
@@ -4815,22 +4925,6 @@ var LWC = (function (exports) {
4815
4925
  renderer,
4816
4926
  tagName
4817
4927
  } = options;
4818
- let shadowMode;
4819
-
4820
- if (renderer.syntheticShadow) {
4821
- shadowMode = def.shadowSupportMode === "any"
4822
- /* Any */
4823
- && isNativeShadowRootDefined ? 0
4824
- /* Native */
4825
- : 1
4826
- /* Synthetic */
4827
- ;
4828
- } else {
4829
- shadowMode = 0
4830
- /* Native */
4831
- ;
4832
- }
4833
-
4834
4928
  const vm = {
4835
4929
  elm,
4836
4930
  def,
@@ -4853,10 +4947,12 @@ var LWC = (function (exports) {
4853
4947
  oar: create(null),
4854
4948
  cmpTemplate: null,
4855
4949
  renderMode: def.renderMode,
4856
- shadowMode,
4950
+ shadowMode: null,
4857
4951
  context: {
4858
- hostAttribute: undefined,
4859
- shadowAttribute: undefined,
4952
+ stylesheetToken: undefined,
4953
+ hasTokenInClass: undefined,
4954
+ hasTokenInAttribute: undefined,
4955
+ hasScopedStyles: undefined,
4860
4956
  styleVNode: null,
4861
4957
  tplCache: EmptyObject,
4862
4958
  wiredConnecting: EmptyArray,
@@ -4869,18 +4965,81 @@ var LWC = (function (exports) {
4869
4965
  setHook,
4870
4966
  getHook
4871
4967
  };
4968
+ vm.shadowMode = computeShadowMode(vm);
4872
4969
  vm.tro = getTemplateReactiveObserver(vm);
4873
4970
 
4874
4971
 
4875
4972
  invokeComponentConstructor(vm, def.ctor); // Initializing the wire decorator per instance only when really needed
4876
4973
 
4877
- if (isFalse(renderer.ssr) && hasWireAdapters(vm)) {
4974
+ if (hasWireAdapters(vm)) {
4878
4975
  installWireAdapters(vm);
4879
4976
  }
4880
4977
 
4881
4978
  return vm;
4882
4979
  }
4883
4980
 
4981
+ function computeShadowMode(vm) {
4982
+ const {
4983
+ def,
4984
+ renderer
4985
+ } = vm;
4986
+ const {
4987
+ isNativeShadowDefined,
4988
+ isSyntheticShadowDefined
4989
+ } = renderer;
4990
+ let shadowMode;
4991
+
4992
+ if (isSyntheticShadowDefined) {
4993
+ if (def.renderMode === 0
4994
+ /* Light */
4995
+ ) {
4996
+ // ShadowMode.Native implies "not synthetic shadow" which is consistent with how
4997
+ // everything defaults to native when the synthetic shadow polyfill is unavailable.
4998
+ shadowMode = 0
4999
+ /* Native */
5000
+ ;
5001
+ } else if (isNativeShadowDefined) {
5002
+ if (def.shadowSupportMode === "any"
5003
+ /* Any */
5004
+ ) {
5005
+ shadowMode = 0
5006
+ /* Native */
5007
+ ;
5008
+ } else {
5009
+ const shadowAncestor = getNearestShadowAncestor(vm);
5010
+
5011
+ if (!isNull(shadowAncestor) && shadowAncestor.shadowMode === 0
5012
+ /* Native */
5013
+ ) {
5014
+ // Transitive support for native Shadow DOM. A component in native mode
5015
+ // transitively opts all of its descendants into native.
5016
+ shadowMode = 0
5017
+ /* Native */
5018
+ ;
5019
+ } else {
5020
+ // Synthetic if neither this component nor any of its ancestors are configured
5021
+ // to be native.
5022
+ shadowMode = 1
5023
+ /* Synthetic */
5024
+ ;
5025
+ }
5026
+ }
5027
+ } else {
5028
+ // Synthetic if there is no native Shadow DOM support.
5029
+ shadowMode = 1
5030
+ /* Synthetic */
5031
+ ;
5032
+ }
5033
+ } else {
5034
+ // Native if the synthetic shadow polyfill is unavailable.
5035
+ shadowMode = 0
5036
+ /* Native */
5037
+ ;
5038
+ }
5039
+
5040
+ return shadowMode;
5041
+ }
5042
+
4884
5043
  function associateVM(obj, vm) {
4885
5044
  ViewModelReflection.set(obj, vm);
4886
5045
  }
@@ -5575,11 +5734,14 @@ var LWC = (function (exports) {
5575
5734
  ArrayPush$1.call(wiredConnecting, () => {
5576
5735
  connector.connect();
5577
5736
 
5578
- if (hasDynamicParams) {
5579
- Promise.resolve().then(computeConfigAndUpdate);
5580
- } else {
5581
- computeConfigAndUpdate();
5737
+ if (!runtimeFlags.ENABLE_WIRE_SYNC_EMIT) {
5738
+ if (hasDynamicParams) {
5739
+ Promise.resolve().then(computeConfigAndUpdate);
5740
+ return;
5741
+ }
5582
5742
  }
5743
+
5744
+ computeConfigAndUpdate();
5583
5745
  });
5584
5746
  ArrayPush$1.call(wiredDisconnecting, () => {
5585
5747
  connector.disconnect();
@@ -5680,7 +5842,7 @@ var LWC = (function (exports) {
5680
5842
 
5681
5843
  return reactiveMembrane.getReadOnlyProxy(obj);
5682
5844
  }
5683
- /* version: 2.3.4 */
5845
+ /* version: 2.5.1 */
5684
5846
 
5685
5847
  /*
5686
5848
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5693,6 +5855,10 @@ var LWC = (function (exports) {
5693
5855
  const globalStylesheets = create(null);
5694
5856
 
5695
5857
  const globalStylesheetsParentElement = document.head || document.body || document;
5858
+ const supportsConstructableStyleSheets = isFunction$1(CSSStyleSheet.prototype.replaceSync);
5859
+ const styleElements = create(null);
5860
+ const styleSheets = create(null);
5861
+ const nodesToStyleSheets = new WeakMap();
5696
5862
  let getCustomElement, defineCustomElement, HTMLElementConstructor;
5697
5863
 
5698
5864
  function isCustomElementRegistryAvailable() {
@@ -5719,6 +5885,52 @@ var LWC = (function (exports) {
5719
5885
  }
5720
5886
  }
5721
5887
 
5888
+ function insertConstructableStyleSheet(content, target) {
5889
+ // It's important for CSSStyleSheets to be unique based on their content, so that
5890
+ // `shadowRoot.adoptedStyleSheets.includes(sheet)` works.
5891
+ let styleSheet = styleSheets[content];
5892
+
5893
+ if (isUndefined$1(styleSheet)) {
5894
+ styleSheet = new CSSStyleSheet();
5895
+ styleSheet.replaceSync(content);
5896
+ styleSheets[content] = styleSheet;
5897
+ }
5898
+
5899
+ if (!target.adoptedStyleSheets.includes(styleSheet)) {
5900
+ target.adoptedStyleSheets = [...target.adoptedStyleSheets, styleSheet];
5901
+ }
5902
+ }
5903
+
5904
+ function insertStyleElement(content, target) {
5905
+ // Avoid inserting duplicate `<style>`s
5906
+ let sheets = nodesToStyleSheets.get(target);
5907
+
5908
+ if (isUndefined$1(sheets)) {
5909
+ sheets = create(null);
5910
+ nodesToStyleSheets.set(target, sheets);
5911
+ }
5912
+
5913
+ if (sheets[content]) {
5914
+ return;
5915
+ }
5916
+
5917
+ sheets[content] = true; // This `<style>` may be repeated multiple times in the DOM, so cache it. It's a bit
5918
+ // faster to call `cloneNode()` on an existing node than to recreate it every time.
5919
+
5920
+ let elm = styleElements[content];
5921
+
5922
+ if (isUndefined$1(elm)) {
5923
+ elm = document.createElement('style');
5924
+ elm.type = 'text/css';
5925
+ elm.textContent = content;
5926
+ styleElements[content] = elm;
5927
+ } else {
5928
+ elm = elm.cloneNode(true);
5929
+ }
5930
+
5931
+ target.appendChild(elm);
5932
+ }
5933
+
5722
5934
  if (isCustomElementRegistryAvailable()) {
5723
5935
  getCustomElement = customElements.get.bind(customElements);
5724
5936
  defineCustomElement = customElements.define.bind(customElements);
@@ -5764,7 +5976,8 @@ var LWC = (function (exports) {
5764
5976
 
5765
5977
  const renderer = {
5766
5978
  ssr: false,
5767
- syntheticShadow: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
5979
+ isNativeShadowDefined: _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED],
5980
+ isSyntheticShadowDefined: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
5768
5981
 
5769
5982
  createElement(tagName, namespace) {
5770
5983
  return isUndefined$1(namespace) ? document.createElement(tagName) : document.createElementNS(namespace, tagName);
@@ -5881,6 +6094,15 @@ var LWC = (function (exports) {
5881
6094
  globalStylesheetsParentElement.appendChild(elm);
5882
6095
  },
5883
6096
 
6097
+ insertStylesheet(content, target) {
6098
+ if (supportsConstructableStyleSheets) {
6099
+ insertConstructableStyleSheet(content, target);
6100
+ } else {
6101
+ // Fall back to <style> element
6102
+ insertStyleElement(content, target);
6103
+ }
6104
+ },
6105
+
5884
6106
  assertInstanceOfHTMLElement(elm, msg) {
5885
6107
  assert.invariant(elm instanceof HTMLElement, msg);
5886
6108
  },
@@ -6103,7 +6325,7 @@ var LWC = (function (exports) {
6103
6325
  return false;
6104
6326
  }
6105
6327
 
6106
- if (renderer.syntheticShadow) {
6328
+ if (renderer.isSyntheticShadowDefined) {
6107
6329
  // TODO [#1252]: old behavior that is still used by some pieces of the platform,
6108
6330
  // specifically, nodes inserted manually on places where `lwc:dom="manual"` directive is not
6109
6331
  // used, will be considered global elements.
@@ -6156,7 +6378,7 @@ var LWC = (function (exports) {
6156
6378
  });
6157
6379
  freeze(LightningElement);
6158
6380
  seal(LightningElement.prototype);
6159
- /* version: 2.3.4 */
6381
+ /* version: 2.5.1 */
6160
6382
 
6161
6383
  exports.LightningElement = LightningElement;
6162
6384
  exports.__unstable__ProfilerControl = profilerControl;