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