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
@@ -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.3 */
304
+ /** version: 2.5.0 */
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.3 */
475
+ /** version: 2.5.0 */
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 = {
@@ -3367,6 +3368,19 @@
3367
3368
 
3368
3369
  function setElementShadowToken(elm, token) {
3369
3370
  elm.$shadowToken$ = token;
3371
+ } // Set the scope token class for *.scoped.css styles
3372
+
3373
+
3374
+ function setScopeTokenClassIfNecessary(elm, owner) {
3375
+ const {
3376
+ cmpTemplate,
3377
+ context
3378
+ } = owner;
3379
+ const token = cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken;
3380
+
3381
+ if (!isUndefined$1(token) && context.hasScopedStyles) {
3382
+ owner.renderer.getClassList(elm).add(token);
3383
+ }
3370
3384
  }
3371
3385
 
3372
3386
  function updateNodeHook(oldVnode, vnode) {
@@ -3417,6 +3431,7 @@
3417
3431
  const {
3418
3432
  owner
3419
3433
  } = vnode;
3434
+ setScopeTokenClassIfNecessary(elm, owner);
3420
3435
 
3421
3436
  if (owner.shadowMode === 1
3422
3437
  /* Synthetic */
@@ -3427,7 +3442,7 @@
3427
3442
  }
3428
3443
  } = vnode;
3429
3444
  const {
3430
- shadowAttribute
3445
+ stylesheetToken
3431
3446
  } = owner.context;
3432
3447
 
3433
3448
  if (!isUndefined$1(context) && !isUndefined$1(context.lwc) && context.lwc.dom === "manual"
@@ -3439,7 +3454,7 @@
3439
3454
  // into each element from the template, so they can be styled accordingly.
3440
3455
 
3441
3456
 
3442
- setElementShadowToken(elm, shadowAttribute);
3457
+ setElementShadowToken(elm, stylesheetToken);
3443
3458
  }
3444
3459
  }
3445
3460
 
@@ -3510,16 +3525,17 @@
3510
3525
  ctor,
3511
3526
  owner
3512
3527
  } = vnode;
3528
+ setScopeTokenClassIfNecessary(elm, owner);
3513
3529
 
3514
3530
  if (owner.shadowMode === 1
3515
3531
  /* Synthetic */
3516
3532
  ) {
3517
3533
  const {
3518
- shadowAttribute
3534
+ stylesheetToken
3519
3535
  } = owner.context; // when running in synthetic shadow mode, we need to set the shadowToken value
3520
3536
  // into each element from the template, so they can be styled accordingly.
3521
3537
 
3522
- setElementShadowToken(elm, shadowAttribute);
3538
+ setElementShadowToken(elm, stylesheetToken);
3523
3539
  }
3524
3540
 
3525
3541
  const def = getComponentInternalDef(ctor);
@@ -3807,13 +3823,19 @@
3807
3823
 
3808
3824
  function linkNodeToShadow(elm, owner) {
3809
3825
  const {
3826
+ renderer,
3827
+ renderMode,
3810
3828
  shadowMode
3811
3829
  } = owner; // TODO [#1164]: this should eventually be done by the polyfill directly
3812
3830
 
3813
- if (shadowMode === 1
3814
- /* Synthetic */
3815
- ) {
3816
- elm[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
3831
+ if (renderer.isSyntheticShadowDefined) {
3832
+ if (shadowMode === 1
3833
+ /* Synthetic */
3834
+ || renderMode === 0
3835
+ /* Light */
3836
+ ) {
3837
+ elm[KEY__SHADOW_RESOLVER] = getRenderRoot(owner)[KEY__SHADOW_RESOLVER];
3838
+ }
3817
3839
  }
3818
3840
  }
3819
3841
 
@@ -4048,14 +4070,11 @@
4048
4070
 
4049
4071
  const {
4050
4072
  idx,
4051
- renderMode,
4052
4073
  shadowMode
4053
4074
  } = vmBeingRendered;
4054
4075
 
4055
4076
  if (shadowMode === 1
4056
4077
  /* Synthetic */
4057
- && renderMode === 1
4058
- /* Shadow */
4059
4078
  ) {
4060
4079
  return StringReplace.call(id, /\S+/g, id => `${id}-${idx}`);
4061
4080
  }
@@ -4079,14 +4098,11 @@
4079
4098
 
4080
4099
  const {
4081
4100
  idx,
4082
- renderMode,
4083
4101
  shadowMode
4084
4102
  } = vmBeingRendered; // Apply transformation only for fragment-only-urls, and only in shadow DOM
4085
4103
 
4086
4104
  if (shadowMode === 1
4087
4105
  /* Synthetic */
4088
- && renderMode === 1
4089
- /* Shadow */
4090
4106
  && /^#/.test(url)) {
4091
4107
  return `${url}-${idx}`;
4092
4108
  }
@@ -4179,6 +4195,10 @@
4179
4195
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
4180
4196
  */
4181
4197
 
4198
+ function makeHostToken(token) {
4199
+ return `${token}-host`;
4200
+ }
4201
+
4182
4202
  function createInlineStyleVNode(content) {
4183
4203
  return h('style', {
4184
4204
  key: 'style',
@@ -4188,53 +4208,94 @@
4188
4208
  }, [t(content)]);
4189
4209
  }
4190
4210
 
4191
- function updateSyntheticShadowAttributes(vm, template) {
4211
+ function updateStylesheetToken(vm, template) {
4192
4212
  const {
4193
4213
  elm,
4194
4214
  context,
4195
4215
  renderer,
4196
- renderMode
4216
+ renderMode,
4217
+ shadowMode
4197
4218
  } = vm;
4198
4219
  const {
4199
4220
  stylesheets: newStylesheets,
4200
- stylesheetTokens: newStylesheetTokens
4221
+ stylesheetToken: newStylesheetToken
4201
4222
  } = template;
4202
- let newTokens; // Reset the styling token applied to the host element.
4223
+ const isSyntheticShadow = renderMode === 1
4224
+ /* Shadow */
4225
+ && shadowMode === 1
4226
+ /* Synthetic */
4227
+ ;
4228
+ const {
4229
+ hasScopedStyles
4230
+ } = context;
4231
+ let newToken;
4232
+ let newHasTokenInClass;
4233
+ let newHasTokenInAttribute; // Reset the styling token applied to the host element.
4234
+
4235
+ const {
4236
+ stylesheetToken: oldToken,
4237
+ hasTokenInClass: oldHasTokenInClass,
4238
+ hasTokenInAttribute: oldHasTokenInAttribute
4239
+ } = context;
4203
4240
 
4204
- const oldHostAttribute = context.hostAttribute;
4241
+ if (oldHasTokenInClass) {
4242
+ renderer.getClassList(elm).remove(makeHostToken(oldToken));
4243
+ }
4205
4244
 
4206
- if (!isUndefined$1(oldHostAttribute)) {
4207
- renderer.removeAttribute(elm, oldHostAttribute);
4245
+ if (oldHasTokenInAttribute) {
4246
+ renderer.removeAttribute(elm, makeHostToken(oldToken));
4208
4247
  } // Apply the new template styling token to the host element, if the new template has any
4209
- // associated stylesheets.
4248
+ // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
4210
4249
 
4211
4250
 
4212
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0 && renderMode === 1
4213
- /* Shadow */
4214
- ) {
4215
- newTokens = newStylesheetTokens;
4216
- }
4251
+ if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
4252
+ newToken = newStylesheetToken;
4253
+ } // Set the new styling token on the host element
4254
+
4255
+
4256
+ if (!isUndefined$1(newToken)) {
4257
+ if (hasScopedStyles) {
4258
+ renderer.getClassList(elm).add(makeHostToken(newToken));
4259
+ newHasTokenInClass = true;
4260
+ }
4217
4261
 
4218
- if (!isUndefined$1(newTokens)) {
4219
- renderer.setAttribute(elm, newTokens.hostAttribute, '');
4262
+ if (isSyntheticShadow) {
4263
+ renderer.setAttribute(elm, makeHostToken(newToken), '');
4264
+ newHasTokenInAttribute = true;
4265
+ }
4220
4266
  } // Update the styling tokens present on the context object.
4221
4267
 
4222
4268
 
4223
- context.hostAttribute = newTokens === null || newTokens === void 0 ? void 0 : newTokens.hostAttribute;
4224
- context.shadowAttribute = newTokens === null || newTokens === void 0 ? void 0 : newTokens.shadowAttribute;
4269
+ context.stylesheetToken = newToken;
4270
+ context.hasTokenInClass = newHasTokenInClass;
4271
+ context.hasTokenInAttribute = newHasTokenInAttribute;
4225
4272
  }
4226
4273
 
4227
- function evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, nativeShadow) {
4274
+ function evaluateStylesheetsContent(stylesheets, stylesheetToken, vm) {
4228
4275
  const content = [];
4229
4276
 
4230
4277
  for (let i = 0; i < stylesheets.length; i++) {
4231
4278
  let stylesheet = stylesheets[i];
4232
4279
 
4233
4280
  if (isArray$1(stylesheet)) {
4234
- ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, hostSelector, shadowSelector, nativeShadow));
4281
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(stylesheet, stylesheetToken, vm));
4235
4282
  } else {
4236
-
4237
- ArrayPush$1.call(content, stylesheet(hostSelector, shadowSelector, nativeShadow));
4283
+ // native shadow DOM. Synthetic shadow DOM never uses `:host`.
4284
+
4285
+
4286
+ const isScopedCss = stylesheet[KEY__SCOPED_CSS];
4287
+ const useActualHostSelector = vm.renderMode === 0
4288
+ /* Light */
4289
+ ? !isScopedCss : vm.shadowMode === 0
4290
+ /* Native */
4291
+ ; // Apply the scope token only if the stylesheet itself is scoped, or if we're rendering synthetic shadow.
4292
+
4293
+ const scopeToken = isScopedCss || vm.shadowMode === 1
4294
+ /* Synthetic */
4295
+ && vm.renderMode === 1
4296
+ /* Shadow */
4297
+ ? stylesheetToken : undefined;
4298
+ ArrayPush$1.call(content, stylesheet(useActualHostSelector, scopeToken));
4238
4299
  }
4239
4300
  }
4240
4301
 
@@ -4244,37 +4305,36 @@
4244
4305
  function getStylesheetsContent(vm, template) {
4245
4306
  const {
4246
4307
  stylesheets,
4247
- stylesheetTokens
4308
+ stylesheetToken
4248
4309
  } = template;
4249
- const {
4250
- renderMode,
4251
- shadowMode
4252
- } = vm;
4253
4310
  let content = [];
4254
4311
 
4255
4312
  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.
4313
+ content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
4314
+ }
4315
+
4316
+ return content;
4317
+ } // It might be worth caching this to avoid doing the lookup repeatedly, but
4318
+ // perf testing has not shown it to be a huge improvement yet:
4319
+ // https://github.com/salesforce/lwc/pull/2460#discussion_r691208892
4320
+
4259
4321
 
4260
- if (renderMode === 1
4322
+ function getNearestNativeShadowComponent(vm) {
4323
+ let owner = vm;
4324
+
4325
+ while (!isNull(owner)) {
4326
+ if (owner.renderMode === 1
4261
4327
  /* Shadow */
4262
- && shadowMode === 1
4263
- /* Synthetic */
4264
- && !isUndefined$1(stylesheetTokens)) {
4265
- hostSelector = `[${stylesheetTokens.hostAttribute}]`;
4266
- shadowSelector = `[${stylesheetTokens.shadowAttribute}]`;
4267
- } else {
4268
- hostSelector = '';
4269
- shadowSelector = '';
4328
+ && owner.shadowMode === 0
4329
+ /* Native */
4330
+ ) {
4331
+ return owner;
4270
4332
  }
4271
4333
 
4272
- content = evaluateStylesheetsContent(stylesheets, hostSelector, shadowSelector, shadowMode === 0
4273
- /* Native */
4274
- );
4334
+ owner = owner.owner;
4275
4335
  }
4276
4336
 
4277
- return content;
4337
+ return owner;
4278
4338
  }
4279
4339
 
4280
4340
  function createStylesheet(vm, stylesheets) {
@@ -4292,13 +4352,26 @@
4292
4352
  for (let i = 0; i < stylesheets.length; i++) {
4293
4353
  renderer.insertGlobalStylesheet(stylesheets[i]);
4294
4354
  }
4295
-
4296
- return null;
4297
- } else {
4298
- // native shadow or light DOM
4355
+ } else if (renderer.ssr) {
4356
+ // native shadow or light DOM, SSR
4299
4357
  const combinedStylesheetContent = ArrayJoin.call(stylesheets, '\n');
4300
4358
  return createInlineStyleVNode(combinedStylesheetContent);
4359
+ } else {
4360
+ // native shadow or light DOM, DOM renderer
4361
+ const root = getNearestNativeShadowComponent(vm);
4362
+ const isGlobal = isNull(root);
4363
+
4364
+ for (let i = 0; i < stylesheets.length; i++) {
4365
+ if (isGlobal) {
4366
+ renderer.insertGlobalStylesheet(stylesheets[i]);
4367
+ } else {
4368
+ // local level
4369
+ renderer.insertStylesheet(stylesheets[i], root.cmpRoot);
4370
+ }
4371
+ }
4301
4372
  }
4373
+
4374
+ return null;
4302
4375
  }
4303
4376
  /** Indicates if operations should be logged by the profiler. */
4304
4377
 
@@ -4420,8 +4493,7 @@
4420
4493
  context,
4421
4494
  cmpSlots,
4422
4495
  cmpTemplate,
4423
- tro,
4424
- shadowMode
4496
+ tro
4425
4497
  } = vm;
4426
4498
  tro.observe(() => {
4427
4499
  // Reset the cache memoizer for template when needed.
@@ -4444,15 +4516,12 @@
4444
4516
 
4445
4517
  vm.cmpTemplate = html; // Create a brand new template cache for the swapped templated.
4446
4518
 
4447
- context.tplCache = create(null); // Update the synthetic shadow attributes on the host element if necessary.
4519
+ context.tplCache = create(null); // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
4448
4520
 
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.
4521
+ context.hasScopedStyles = computeHasScopedStyles(html); // Update the scoping token on the host element.
4455
4522
 
4523
+ updateStylesheetToken(vm, html); // Evaluate, create stylesheet and cache the produced VNode for future
4524
+ // re-rendering.
4456
4525
 
4457
4526
  const stylesheetsContent = getStylesheetsContent(vm, html);
4458
4527
  context.styleVNode = stylesheetsContent.length === 0 ? null : createStylesheet(vm, stylesheetsContent);
@@ -4485,6 +4554,22 @@
4485
4554
 
4486
4555
  return vnodes;
4487
4556
  }
4557
+
4558
+ function computeHasScopedStyles(template) {
4559
+ const {
4560
+ stylesheets
4561
+ } = template;
4562
+
4563
+ if (!isUndefined$1(stylesheets)) {
4564
+ for (let i = 0; i < stylesheets.length; i++) {
4565
+ if (isTrue(stylesheets[i][KEY__SCOPED_CSS])) {
4566
+ return true;
4567
+ }
4568
+ }
4569
+ }
4570
+
4571
+ return false;
4572
+ }
4488
4573
  /*
4489
4574
  * Copyright (c) 2018, salesforce.com, inc.
4490
4575
  * All rights reserved.
@@ -4516,12 +4601,9 @@
4516
4601
  callHook,
4517
4602
  owner
4518
4603
  } = vm;
4519
- let result;
4520
4604
  runWithBoundaryProtection(vm, owner, noop, () => {
4521
- // job
4522
- result = callHook(component, fn, args);
4605
+ callHook(component, fn, args);
4523
4606
  }, noop);
4524
- return result;
4525
4607
  }
4526
4608
 
4527
4609
  function invokeComponentConstructor(vm, Ctor) {
@@ -4590,33 +4672,6 @@
4590
4672
  return renderInvocationSuccessful ? evaluateTemplate(vm, html) : [];
4591
4673
  }
4592
4674
 
4593
- function invokeComponentRenderedCallback(vm) {
4594
- const {
4595
- def: {
4596
- renderedCallback
4597
- },
4598
- component,
4599
- callHook,
4600
- owner
4601
- } = vm;
4602
-
4603
- if (!isUndefined$1(renderedCallback)) {
4604
- runWithBoundaryProtection(vm, owner, () => {
4605
- logOperationStart(4
4606
- /* RenderedCallback */
4607
- , vm);
4608
- }, () => {
4609
- // job
4610
- callHook(component, renderedCallback);
4611
- }, () => {
4612
- // post
4613
- logOperationEnd(4
4614
- /* RenderedCallback */
4615
- , vm);
4616
- });
4617
- }
4618
- }
4619
-
4620
4675
  function invokeEventListener(vm, fn, thisValue, event) {
4621
4676
  const {
4622
4677
  callHook,
@@ -4755,7 +4810,6 @@
4755
4810
  */
4756
4811
 
4757
4812
 
4758
- const isNativeShadowRootDefined = _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED];
4759
4813
  let idx = 0;
4760
4814
  /** The internal slot used to associate different objects the engine manipulates with the VM */
4761
4815
 
@@ -4841,6 +4895,18 @@
4841
4895
  resetComponentStateWhenRemoved(vm);
4842
4896
  }
4843
4897
 
4898
+ function getNearestShadowAncestor(vm) {
4899
+ let ancestor = vm.owner;
4900
+
4901
+ while (!isNull(ancestor) && ancestor.renderMode === 0
4902
+ /* Light */
4903
+ ) {
4904
+ ancestor = ancestor.owner;
4905
+ }
4906
+
4907
+ return ancestor;
4908
+ }
4909
+
4844
4910
  function createVM(elm, def, options) {
4845
4911
  const {
4846
4912
  mode,
@@ -4848,22 +4914,6 @@
4848
4914
  renderer,
4849
4915
  tagName
4850
4916
  } = options;
4851
- let shadowMode;
4852
-
4853
- if (renderer.syntheticShadow) {
4854
- shadowMode = def.shadowSupportMode === "any"
4855
- /* Any */
4856
- && isNativeShadowRootDefined ? 0
4857
- /* Native */
4858
- : 1
4859
- /* Synthetic */
4860
- ;
4861
- } else {
4862
- shadowMode = 0
4863
- /* Native */
4864
- ;
4865
- }
4866
-
4867
4917
  const vm = {
4868
4918
  elm,
4869
4919
  def,
@@ -4886,10 +4936,12 @@
4886
4936
  oar: create(null),
4887
4937
  cmpTemplate: null,
4888
4938
  renderMode: def.renderMode,
4889
- shadowMode,
4939
+ shadowMode: null,
4890
4940
  context: {
4891
- hostAttribute: undefined,
4892
- shadowAttribute: undefined,
4941
+ stylesheetToken: undefined,
4942
+ hasTokenInClass: undefined,
4943
+ hasTokenInAttribute: undefined,
4944
+ hasScopedStyles: undefined,
4893
4945
  styleVNode: null,
4894
4946
  tplCache: EmptyObject,
4895
4947
  wiredConnecting: EmptyArray,
@@ -4902,18 +4954,81 @@
4902
4954
  setHook,
4903
4955
  getHook
4904
4956
  };
4957
+ vm.shadowMode = computeShadowMode(vm);
4905
4958
  vm.tro = getTemplateReactiveObserver(vm);
4906
4959
 
4907
4960
 
4908
4961
  invokeComponentConstructor(vm, def.ctor); // Initializing the wire decorator per instance only when really needed
4909
4962
 
4910
- if (isFalse(renderer.ssr) && hasWireAdapters(vm)) {
4963
+ if (hasWireAdapters(vm)) {
4911
4964
  installWireAdapters(vm);
4912
4965
  }
4913
4966
 
4914
4967
  return vm;
4915
4968
  }
4916
4969
 
4970
+ function computeShadowMode(vm) {
4971
+ const {
4972
+ def,
4973
+ renderer
4974
+ } = vm;
4975
+ const {
4976
+ isNativeShadowDefined,
4977
+ isSyntheticShadowDefined
4978
+ } = renderer;
4979
+ let shadowMode;
4980
+
4981
+ if (isSyntheticShadowDefined) {
4982
+ if (def.renderMode === 0
4983
+ /* Light */
4984
+ ) {
4985
+ // ShadowMode.Native implies "not synthetic shadow" which is consistent with how
4986
+ // everything defaults to native when the synthetic shadow polyfill is unavailable.
4987
+ shadowMode = 0
4988
+ /* Native */
4989
+ ;
4990
+ } else if (isNativeShadowDefined) {
4991
+ if (def.shadowSupportMode === "any"
4992
+ /* Any */
4993
+ ) {
4994
+ shadowMode = 0
4995
+ /* Native */
4996
+ ;
4997
+ } else {
4998
+ const shadowAncestor = getNearestShadowAncestor(vm);
4999
+
5000
+ if (!isNull(shadowAncestor) && shadowAncestor.shadowMode === 0
5001
+ /* Native */
5002
+ ) {
5003
+ // Transitive support for native Shadow DOM. A component in native mode
5004
+ // transitively opts all of its descendants into native.
5005
+ shadowMode = 0
5006
+ /* Native */
5007
+ ;
5008
+ } else {
5009
+ // Synthetic if neither this component nor any of its ancestors are configured
5010
+ // to be native.
5011
+ shadowMode = 1
5012
+ /* Synthetic */
5013
+ ;
5014
+ }
5015
+ }
5016
+ } else {
5017
+ // Synthetic if there is no native Shadow DOM support.
5018
+ shadowMode = 1
5019
+ /* Synthetic */
5020
+ ;
5021
+ }
5022
+ } else {
5023
+ // Native if the synthetic shadow polyfill is unavailable.
5024
+ shadowMode = 0
5025
+ /* Native */
5026
+ ;
5027
+ }
5028
+
5029
+ return shadowMode;
5030
+ }
5031
+
4917
5032
  function associateVM(obj, vm) {
4918
5033
  ViewModelReflection.set(obj, vm);
4919
5034
  }
@@ -4979,7 +5094,14 @@
4979
5094
  }
4980
5095
 
4981
5096
  function runRenderedCallback(vm) {
4982
- if (isTrue(vm.renderer.ssr)) {
5097
+ const {
5098
+ renderer,
5099
+ def: {
5100
+ renderedCallback
5101
+ }
5102
+ } = vm;
5103
+
5104
+ if (isTrue(renderer.ssr)) {
4983
5105
  return;
4984
5106
  }
4985
5107
 
@@ -4991,7 +5113,15 @@
4991
5113
  invokeServiceHook(vm, rendered);
4992
5114
  }
4993
5115
 
4994
- invokeComponentRenderedCallback(vm);
5116
+ if (!isUndefined$1(renderedCallback)) {
5117
+ logOperationStart(4
5118
+ /* RenderedCallback */
5119
+ , vm);
5120
+ invokeComponentCallback(vm, renderedCallback);
5121
+ logOperationEnd(4
5122
+ /* RenderedCallback */
5123
+ , vm);
5124
+ }
4995
5125
  }
4996
5126
 
4997
5127
  let rehydrateQueue = [];
@@ -5593,11 +5723,14 @@
5593
5723
  ArrayPush$1.call(wiredConnecting, () => {
5594
5724
  connector.connect();
5595
5725
 
5596
- if (hasDynamicParams) {
5597
- Promise.resolve().then(computeConfigAndUpdate);
5598
- } else {
5599
- computeConfigAndUpdate();
5726
+ if (!runtimeFlags.ENABLE_WIRE_SYNC_EMIT) {
5727
+ if (hasDynamicParams) {
5728
+ Promise.resolve().then(computeConfigAndUpdate);
5729
+ return;
5730
+ }
5600
5731
  }
5732
+
5733
+ computeConfigAndUpdate();
5601
5734
  });
5602
5735
  ArrayPush$1.call(wiredDisconnecting, () => {
5603
5736
  connector.disconnect();
@@ -5698,7 +5831,7 @@
5698
5831
 
5699
5832
  return reactiveMembrane.getReadOnlyProxy(obj);
5700
5833
  }
5701
- /* version: 2.3.3 */
5834
+ /* version: 2.5.0 */
5702
5835
 
5703
5836
  /*
5704
5837
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5711,6 +5844,10 @@
5711
5844
  const globalStylesheets = create(null);
5712
5845
 
5713
5846
  const globalStylesheetsParentElement = document.head || document.body || document;
5847
+ const supportsConstructableStyleSheets = isFunction$1(CSSStyleSheet.prototype.replaceSync);
5848
+ const styleElements = create(null);
5849
+ const styleSheets = create(null);
5850
+ const nodesToStyleSheets = new WeakMap();
5714
5851
  let getCustomElement, defineCustomElement, HTMLElementConstructor;
5715
5852
 
5716
5853
  function isCustomElementRegistryAvailable() {
@@ -5737,6 +5874,52 @@
5737
5874
  }
5738
5875
  }
5739
5876
 
5877
+ function insertConstructableStyleSheet(content, target) {
5878
+ // It's important for CSSStyleSheets to be unique based on their content, so that
5879
+ // `shadowRoot.adoptedStyleSheets.includes(sheet)` works.
5880
+ let styleSheet = styleSheets[content];
5881
+
5882
+ if (isUndefined$1(styleSheet)) {
5883
+ styleSheet = new CSSStyleSheet();
5884
+ styleSheet.replaceSync(content);
5885
+ styleSheets[content] = styleSheet;
5886
+ }
5887
+
5888
+ if (!target.adoptedStyleSheets.includes(styleSheet)) {
5889
+ target.adoptedStyleSheets = [...target.adoptedStyleSheets, styleSheet];
5890
+ }
5891
+ }
5892
+
5893
+ function insertStyleElement(content, target) {
5894
+ // Avoid inserting duplicate `<style>`s
5895
+ let sheets = nodesToStyleSheets.get(target);
5896
+
5897
+ if (isUndefined$1(sheets)) {
5898
+ sheets = create(null);
5899
+ nodesToStyleSheets.set(target, sheets);
5900
+ }
5901
+
5902
+ if (sheets[content]) {
5903
+ return;
5904
+ }
5905
+
5906
+ sheets[content] = true; // This `<style>` may be repeated multiple times in the DOM, so cache it. It's a bit
5907
+ // faster to call `cloneNode()` on an existing node than to recreate it every time.
5908
+
5909
+ let elm = styleElements[content];
5910
+
5911
+ if (isUndefined$1(elm)) {
5912
+ elm = document.createElement('style');
5913
+ elm.type = 'text/css';
5914
+ elm.textContent = content;
5915
+ styleElements[content] = elm;
5916
+ } else {
5917
+ elm = elm.cloneNode(true);
5918
+ }
5919
+
5920
+ target.appendChild(elm);
5921
+ }
5922
+
5740
5923
  if (isCustomElementRegistryAvailable()) {
5741
5924
  getCustomElement = customElements.get.bind(customElements);
5742
5925
  defineCustomElement = customElements.define.bind(customElements);
@@ -5782,7 +5965,8 @@
5782
5965
 
5783
5966
  const renderer = {
5784
5967
  ssr: false,
5785
- syntheticShadow: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
5968
+ isNativeShadowDefined: _globalThis[KEY__IS_NATIVE_SHADOW_ROOT_DEFINED],
5969
+ isSyntheticShadowDefined: hasOwnProperty$1.call(Element.prototype, KEY__SHADOW_TOKEN),
5786
5970
 
5787
5971
  createElement(tagName, namespace) {
5788
5972
  return isUndefined$1(namespace) ? document.createElement(tagName) : document.createElementNS(namespace, tagName);
@@ -5899,6 +6083,15 @@
5899
6083
  globalStylesheetsParentElement.appendChild(elm);
5900
6084
  },
5901
6085
 
6086
+ insertStylesheet(content, target) {
6087
+ if (supportsConstructableStyleSheets) {
6088
+ insertConstructableStyleSheet(content, target);
6089
+ } else {
6090
+ // Fall back to <style> element
6091
+ insertStyleElement(content, target);
6092
+ }
6093
+ },
6094
+
5902
6095
  assertInstanceOfHTMLElement(elm, msg) {
5903
6096
  assert.invariant(elm instanceof HTMLElement, msg);
5904
6097
  },
@@ -6121,7 +6314,7 @@
6121
6314
  return false;
6122
6315
  }
6123
6316
 
6124
- if (renderer.syntheticShadow) {
6317
+ if (renderer.isSyntheticShadowDefined) {
6125
6318
  // TODO [#1252]: old behavior that is still used by some pieces of the platform,
6126
6319
  // specifically, nodes inserted manually on places where `lwc:dom="manual"` directive is not
6127
6320
  // used, will be considered global elements.
@@ -6174,7 +6367,7 @@
6174
6367
  });
6175
6368
  freeze(LightningElement);
6176
6369
  seal(LightningElement.prototype);
6177
- /* version: 2.3.3 */
6370
+ /* version: 2.5.0 */
6178
6371
 
6179
6372
  exports.LightningElement = LightningElement;
6180
6373
  exports.__unstable__ProfilerControl = profilerControl;