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