lwc 2.33.0 → 2.34.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 (35) hide show
  1. package/dist/engine-dom/esm/es2017/engine-dom.js +166 -42
  2. package/dist/engine-dom/iife/es2017/engine-dom.js +166 -42
  3. package/dist/engine-dom/iife/es2017/engine-dom.min.js +1 -1
  4. package/dist/engine-dom/iife/es2017/engine-dom_debug.js +170 -39
  5. package/dist/engine-dom/iife/es5/engine-dom.js +204 -91
  6. package/dist/engine-dom/iife/es5/engine-dom.min.js +1 -1
  7. package/dist/engine-dom/iife/es5/engine-dom_debug.js +217 -88
  8. package/dist/engine-dom/umd/es2017/engine-dom.js +166 -42
  9. package/dist/engine-dom/umd/es2017/engine-dom.min.js +1 -1
  10. package/dist/engine-dom/umd/es2017/engine-dom_debug.js +170 -39
  11. package/dist/engine-dom/umd/es5/engine-dom.js +204 -91
  12. package/dist/engine-dom/umd/es5/engine-dom.min.js +1 -1
  13. package/dist/engine-dom/umd/es5/engine-dom_debug.js +217 -88
  14. package/dist/engine-server/commonjs/es2017/engine-server.js +158 -39
  15. package/dist/engine-server/commonjs/es2017/engine-server.min.js +1 -1
  16. package/dist/engine-server/esm/es2017/engine-server.js +158 -39
  17. package/dist/synthetic-shadow/esm/es2017/synthetic-shadow.js +3 -3
  18. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow.js +3 -3
  19. package/dist/synthetic-shadow/iife/es2017/synthetic-shadow_debug.js +3 -3
  20. package/dist/synthetic-shadow/iife/es5/synthetic-shadow.js +3 -3
  21. package/dist/synthetic-shadow/iife/es5/synthetic-shadow_debug.js +3 -3
  22. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow.js +3 -3
  23. package/dist/synthetic-shadow/umd/es2017/synthetic-shadow_debug.js +3 -3
  24. package/dist/synthetic-shadow/umd/es5/synthetic-shadow.js +3 -3
  25. package/dist/synthetic-shadow/umd/es5/synthetic-shadow_debug.js +3 -3
  26. package/dist/wire-service/esm/es2017/wire-service.js +2 -2
  27. package/dist/wire-service/iife/es2017/wire-service.js +2 -2
  28. package/dist/wire-service/iife/es2017/wire-service_debug.js +2 -2
  29. package/dist/wire-service/iife/es5/wire-service.js +2 -2
  30. package/dist/wire-service/iife/es5/wire-service_debug.js +2 -2
  31. package/dist/wire-service/umd/es2017/wire-service.js +2 -2
  32. package/dist/wire-service/umd/es2017/wire-service_debug.js +2 -2
  33. package/dist/wire-service/umd/es5/wire-service.js +2 -2
  34. package/dist/wire-service/umd/es5/wire-service_debug.js +2 -2
  35. package/package.json +7 -7
@@ -350,9 +350,9 @@
350
350
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
351
351
  */
352
352
  // Increment whenever the LWC template compiler changes
353
- const LWC_VERSION = "2.33.0";
353
+ const LWC_VERSION = "2.34.0";
354
354
  const LWC_VERSION_COMMENT_REGEX = /\/\*LWC compiler v([\d.]+)\*\/\s*}/;
355
- /** version: 2.33.0 */
355
+ /** version: 2.34.0 */
356
356
 
357
357
  /**
358
358
  * Copyright (C) 2018 salesforce.com, inc.
@@ -375,6 +375,7 @@
375
375
  ENABLE_SCOPED_CUSTOM_ELEMENT_REGISTRY: null,
376
376
  ENABLE_FROZEN_TEMPLATE: null,
377
377
  DISABLE_ARIA_REFLECTION_POLYFILL: null,
378
+ ENABLE_PROGRAMMATIC_STYLESHEETS: null,
378
379
  };
379
380
  if (!_globalThis.lwcRuntimeFlags) {
380
381
  Object.defineProperty(_globalThis, 'lwcRuntimeFlags', { value: create(null) });
@@ -428,7 +429,7 @@
428
429
  setFeatureFlag(name, value);
429
430
  }
430
431
  }
431
- /** version: 2.33.0 */
432
+ /** version: 2.34.0 */
432
433
 
433
434
  /**
434
435
  * Copyright (C) 2018 salesforce.com, inc.
@@ -492,7 +493,7 @@
492
493
  }
493
494
  }
494
495
  }
495
- /** version: 2.33.0 */
496
+ /** version: 2.34.0 */
496
497
 
497
498
  /*
498
499
  * Copyright (c) 2018, salesforce.com, inc.
@@ -821,6 +822,7 @@
821
822
  if (!isUndefined$1(vm)) {
822
823
  msg = `${msg}\n${getComponentStack(vm)}`;
823
824
  }
825
+ // In Jest tests, reduce the warning and error verbosity by not printing the callstack
824
826
  if (process.env.NODE_ENV === 'test') {
825
827
  /* eslint-disable-next-line no-console */
826
828
  console[method](msg);
@@ -890,6 +892,9 @@
890
892
  // Global HTML Attributes & Properties
891
893
  // https://developer.mozilla.org/en-US/docs/Web/HTML/Global_attributes
892
894
  // https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement
895
+ //
896
+ // If you update this list, check for test files that recapitulate the same list. Searching the codebase
897
+ // for e.g. "dropzone" should suffice.
893
898
  const globalHTMLProperties = assign(create(null), {
894
899
  accessKey: {
895
900
  attribute: 'accesskey',
@@ -3482,6 +3487,9 @@
3482
3487
  stylesheets: newStylesheets,
3483
3488
  stylesheetToken: newStylesheetToken
3484
3489
  } = template;
3490
+ const {
3491
+ stylesheets: newVmStylesheets
3492
+ } = vm;
3485
3493
  const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
3486
3494
  const {
3487
3495
  hasScopedStyles
@@ -3505,7 +3513,9 @@
3505
3513
  }
3506
3514
  // Apply the new template styling token to the host element, if the new template has any
3507
3515
  // associated stylesheets. In the case of light DOM, also ensure there is at least one scoped stylesheet.
3508
- if (!isUndefined$1(newStylesheets) && newStylesheets.length !== 0) {
3516
+ const hasNewStylesheets = hasStyles(newStylesheets);
3517
+ const hasNewVmStylesheets = hasStyles(newVmStylesheets);
3518
+ if (hasNewStylesheets || hasNewVmStylesheets) {
3509
3519
  newToken = newStylesheetToken;
3510
3520
  }
3511
3521
  // Set the new styling token on the host element
@@ -3577,10 +3587,17 @@
3577
3587
  stylesheets,
3578
3588
  stylesheetToken
3579
3589
  } = template;
3590
+ const {
3591
+ stylesheets: vmStylesheets
3592
+ } = vm;
3580
3593
  let content = [];
3581
- if (!isUndefined$1(stylesheets) && stylesheets.length !== 0) {
3594
+ if (hasStyles(stylesheets)) {
3582
3595
  content = evaluateStylesheetsContent(stylesheets, stylesheetToken, vm);
3583
3596
  }
3597
+ // VM (component) stylesheets apply after template stylesheets
3598
+ if (hasStyles(vmStylesheets)) {
3599
+ ArrayPush$1.apply(content, evaluateStylesheetsContent(vmStylesheets, stylesheetToken, vm));
3600
+ }
3584
3601
  return content;
3585
3602
  }
3586
3603
  // It might be worth caching this to avoid doing the lookup repeatedly, but
@@ -3618,10 +3635,13 @@
3618
3635
  const {
3619
3636
  template
3620
3637
  } = getComponentInternalDef(vnode.ctor);
3638
+ const {
3639
+ vm
3640
+ } = vnode;
3621
3641
  const {
3622
3642
  stylesheetToken
3623
3643
  } = template;
3624
- return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template) ? makeHostToken(stylesheetToken) : null;
3644
+ return !isUndefined$1(stylesheetToken) && computeHasScopedStyles(template, vm) ? makeHostToken(stylesheetToken) : null;
3625
3645
  }
3626
3646
  function getNearestNativeShadowComponent(vm) {
3627
3647
  const owner = getNearestShadowComponent(vm);
@@ -4234,6 +4254,28 @@
4234
4254
  // in fallback mode, the allocation will always set children to
4235
4255
  // empty and delegate the real allocation to the slot elements
4236
4256
  allocateChildren(n2, vm);
4257
+ // Solves an edge case with slotted VFragments in native shadow mode.
4258
+ //
4259
+ // During allocation, in native shadow, slotted VFragment nodes are flattened and their text delimiters are removed
4260
+ // to avoid interfering with native slot behavior. When this happens, if any of the fragments
4261
+ // were not stable, the children must go through the dynamic diffing algo.
4262
+ //
4263
+ // If the new children (n2.children) contain no VFragments, but the previous children (n1.children) were dynamic,
4264
+ // the new nodes must be marked dynamic so that all nodes are properly updated. The only indicator that the new
4265
+ // nodes need to be dynamic comes from the previous children, so we check that to determine whether we need to
4266
+ // mark the new children dynamic.
4267
+ //
4268
+ // Example:
4269
+ // n1.children: [div, VFragment('', div, null, ''), div] => [div, div, null, div]; // marked dynamic
4270
+ // n2.children: [div, null, div] => [div, null, div] // marked ???
4271
+ const {
4272
+ shadowMode,
4273
+ renderMode
4274
+ } = vm;
4275
+ if (shadowMode == 0 /* ShadowMode.Native */ && renderMode !== 0 /* RenderMode.Light */ && hasDynamicChildren(n1.children)) {
4276
+ // No-op if children has already been marked dynamic by 'allocateChildren()'.
4277
+ markAsDynamicChildren(n2.children);
4278
+ }
4237
4279
  }
4238
4280
  // in fallback mode, the children will be always empty, so, nothing
4239
4281
  // will happen, but in native, it does allocate the light dom
@@ -4426,7 +4468,6 @@
4426
4468
  //
4427
4469
  // In case #2, we will always get a fresh VCustomElement.
4428
4470
  const children = vnode.aChildren || vnode.children;
4429
- vm.aChildren = children;
4430
4471
  const {
4431
4472
  renderMode,
4432
4473
  shadowMode
@@ -4439,15 +4480,61 @@
4439
4480
  logError(`Invalid usage of 'lwc:slot-data' on ${getComponentTag(vm)} tag. Scoped slot content can only be passed to a light dom child.`);
4440
4481
  }
4441
4482
  }
4483
+ // If any of the children being allocated are VFragments, we remove the text delimiters and flatten all immediate
4484
+ // children VFragments to avoid them interfering with default slot behavior.
4485
+ const allocatedChildren = flattenFragmentsInChildren(children);
4486
+ vnode.children = allocatedChildren;
4487
+ vm.aChildren = allocatedChildren;
4442
4488
  if (shadowMode === 1 /* ShadowMode.Synthetic */ || renderMode === 0 /* RenderMode.Light */) {
4443
4489
  // slow path
4444
- allocateInSlot(vm, children, vnode.owner);
4490
+ allocateInSlot(vm, allocatedChildren, vnode.owner);
4445
4491
  // save the allocated children in case this vnode is reused.
4446
- vnode.aChildren = children;
4492
+ vnode.aChildren = allocatedChildren;
4447
4493
  // every child vnode is now allocated, and the host should receive none directly, it receives them via the shadow!
4448
4494
  vnode.children = EmptyArray;
4449
4495
  }
4450
4496
  }
4497
+ /**
4498
+ * Flattens the contents of all VFragments in an array of VNodes, removes the text delimiters on those VFragments, and
4499
+ * marks the resulting children array as dynamic. Uses a stack (array) to iteratively traverse the nested VFragments
4500
+ * and avoid the perf overhead of creating/destroying throwaway arrays/objects in a recursive approach.
4501
+ *
4502
+ * With the delimiters removed, the contents are marked dynamic so they are diffed correctly.
4503
+ *
4504
+ * This function is used for slotted VFragments to avoid the text delimiters interfering with slotting functionality.
4505
+ */
4506
+ function flattenFragmentsInChildren(children) {
4507
+ const flattenedChildren = [];
4508
+ // Initialize our stack with the direct children of the custom component and check whether we have a VFragment.
4509
+ // If no VFragment is found in children, we don't need to traverse anything or mark the children dynamic and can return early.
4510
+ const nodeStack = [];
4511
+ let fragmentFound = false;
4512
+ for (let i = children.length - 1; i > -1; i -= 1) {
4513
+ const child = children[i];
4514
+ ArrayPush$1.call(nodeStack, child);
4515
+ fragmentFound = fragmentFound || !!(child && isVFragment(child));
4516
+ }
4517
+ if (!fragmentFound) {
4518
+ return children;
4519
+ }
4520
+ let currentNode;
4521
+ while (!isUndefined$1(currentNode = ArrayPop.call(nodeStack))) {
4522
+ if (!isNull(currentNode) && isVFragment(currentNode)) {
4523
+ const fChildren = currentNode.children;
4524
+ // Ignore the start and end text node delimiters
4525
+ for (let i = fChildren.length - 2; i > 0; i -= 1) {
4526
+ ArrayPush$1.call(nodeStack, fChildren[i]);
4527
+ }
4528
+ } else {
4529
+ ArrayPush$1.call(flattenedChildren, currentNode);
4530
+ }
4531
+ }
4532
+ // We always mark the children as dynamic because nothing generates stable VFragments yet.
4533
+ // If/when stable VFragments are generated by the compiler, this code should be updated to
4534
+ // not mark dynamic if all flattened VFragments were stable.
4535
+ markAsDynamicChildren(flattenedChildren);
4536
+ return flattenedChildren;
4537
+ }
4451
4538
  function createViewModelHook(elm, vnode, renderer) {
4452
4539
  let vm = getAssociatedVMIfPresent(elm);
4453
4540
  // There is a possibility that a custom element is registered under tagName, in which case, the
@@ -4472,22 +4559,20 @@
4472
4559
  }
4473
4560
  return vm;
4474
4561
  }
4475
- /**
4476
- * Collects all slots into a SlotSet, traversing through VFragment Nodes
4477
- */
4478
- function collectSlots(vm, children, cmpSlotsMapping) {
4562
+ function allocateInSlot(vm, children, owner) {
4479
4563
  var _a, _b;
4564
+ const {
4565
+ cmpSlots: {
4566
+ slotAssignments: oldSlotsMapping
4567
+ }
4568
+ } = vm;
4569
+ const cmpSlotsMapping = create(null);
4570
+ // Collect all slots into cmpSlotsMapping
4480
4571
  for (let i = 0, len = children.length; i < len; i += 1) {
4481
4572
  const vnode = children[i];
4482
4573
  if (isNull(vnode)) {
4483
4574
  continue;
4484
4575
  }
4485
- // Dive further iff the content is wrapped in a VFragment
4486
- if (isVFragment(vnode)) {
4487
- // Remove the text delimiter nodes to avoid overriding default slot content
4488
- collectSlots(vm, vnode.children.slice(1, -1), cmpSlotsMapping);
4489
- continue;
4490
- }
4491
4576
  let slotName = '';
4492
4577
  if (isVBaseElement(vnode)) {
4493
4578
  slotName = (_b = (_a = vnode.data.attrs) === null || _a === void 0 ? void 0 : _a.slot) !== null && _b !== void 0 ? _b : '';
@@ -4497,15 +4582,6 @@
4497
4582
  const vnodes = cmpSlotsMapping[slotName] = cmpSlotsMapping[slotName] || [];
4498
4583
  ArrayPush$1.call(vnodes, vnode);
4499
4584
  }
4500
- }
4501
- function allocateInSlot(vm, children, owner) {
4502
- const {
4503
- cmpSlots: {
4504
- slotAssignments: oldSlotsMapping
4505
- }
4506
- } = vm;
4507
- const cmpSlotsMapping = create(null);
4508
- collectSlots(vm, children, cmpSlotsMapping);
4509
4585
  vm.cmpSlots = {
4510
4586
  owner,
4511
4587
  slotAssignments: cmpSlotsMapping
@@ -4536,14 +4612,14 @@
4536
4612
  }
4537
4613
  }
4538
4614
  // Using a WeakMap instead of a WeakSet because this one works in IE11 :(
4539
- const FromIteration = new WeakMap();
4540
- // dynamic children means it was generated by an iteration
4541
- // in a template, and will require a more complex diffing algo.
4615
+ const DynamicChildren = new WeakMap();
4616
+ // dynamic children means it was either generated by an iteration in a template
4617
+ // or part of an unstable fragment, and will require a more complex diffing algo.
4542
4618
  function markAsDynamicChildren(children) {
4543
- FromIteration.set(children, 1);
4619
+ DynamicChildren.set(children, 1);
4544
4620
  }
4545
4621
  function hasDynamicChildren(children) {
4546
- return FromIteration.has(children);
4622
+ return DynamicChildren.has(children);
4547
4623
  }
4548
4624
  function createKeyToOldIdx(children, beginIdx, endIdx) {
4549
4625
  const map = {};
@@ -5409,7 +5485,7 @@
5409
5485
  // Create a brand new template cache for the swapped templated.
5410
5486
  context.tplCache = create(null);
5411
5487
  // Set the computeHasScopedStyles property in the context, to avoid recomputing it repeatedly.
5412
- context.hasScopedStyles = computeHasScopedStyles(html);
5488
+ context.hasScopedStyles = computeHasScopedStyles(html, vm);
5413
5489
  // Update the scoping token on the host element.
5414
5490
  updateStylesheetToken(vm, html);
5415
5491
  // Evaluate, create stylesheet and cache the produced VNode for future
@@ -5452,9 +5528,8 @@
5452
5528
  }
5453
5529
  return vnodes;
5454
5530
  }
5455
- function computeHasScopedStyles(template) {
5456
- const { stylesheets } = template;
5457
- if (!isUndefined$1(stylesheets)) {
5531
+ function computeHasScopedStylesInStylesheets(stylesheets) {
5532
+ if (hasStyles(stylesheets)) {
5458
5533
  for (let i = 0; i < stylesheets.length; i++) {
5459
5534
  if (isTrue(stylesheets[i][KEY__SCOPED_CSS])) {
5460
5535
  return true;
@@ -5463,6 +5538,15 @@
5463
5538
  }
5464
5539
  return false;
5465
5540
  }
5541
+ function computeHasScopedStyles(template, vm) {
5542
+ const { stylesheets } = template;
5543
+ const vmStylesheets = !isUndefined$1(vm) ? vm.stylesheets : null;
5544
+ return (computeHasScopedStylesInStylesheets(stylesheets) ||
5545
+ computeHasScopedStylesInStylesheets(vmStylesheets));
5546
+ }
5547
+ function hasStyles(stylesheets) {
5548
+ return !isUndefined$1(stylesheets) && !isNull(stylesheets) && stylesheets.length > 0;
5549
+ }
5466
5550
 
5467
5551
  /*
5468
5552
  * Copyright (c) 2018, salesforce.com, inc.
@@ -5778,6 +5862,7 @@
5778
5862
  // Properties set right after VM creation.
5779
5863
  tro: null,
5780
5864
  shadowMode: null,
5865
+ stylesheets: null,
5781
5866
  // Properties set by the LightningElement constructor.
5782
5867
  component: null,
5783
5868
  shadowRoot: null,
@@ -5790,6 +5875,7 @@
5790
5875
  if (process.env.NODE_ENV !== 'production') {
5791
5876
  vm.debugInfo = create(null);
5792
5877
  }
5878
+ vm.stylesheets = computeStylesheets(vm, def.ctor);
5793
5879
  vm.shadowMode = computeShadowMode(vm, renderer);
5794
5880
  vm.tro = getTemplateReactiveObserver(vm);
5795
5881
  if (process.env.NODE_ENV !== 'production') {
@@ -5808,6 +5894,42 @@
5808
5894
  }
5809
5895
  return vm;
5810
5896
  }
5897
+ function validateComponentStylesheets(vm, stylesheets) {
5898
+ let valid = true;
5899
+ const validate = arrayOrStylesheet => {
5900
+ if (isArray$1(arrayOrStylesheet)) {
5901
+ for (let i = 0; i < arrayOrStylesheet.length; i++) {
5902
+ validate(arrayOrStylesheet[i]);
5903
+ }
5904
+ } else if (!isFunction$1(arrayOrStylesheet)) {
5905
+ // function assumed to be a stylesheet factory
5906
+ valid = false;
5907
+ }
5908
+ };
5909
+ if (!isArray$1(stylesheets)) {
5910
+ valid = false;
5911
+ } else {
5912
+ validate(stylesheets);
5913
+ }
5914
+ return valid;
5915
+ }
5916
+ // Validate and flatten any stylesheets defined as `static stylesheets`
5917
+ function computeStylesheets(vm, ctor) {
5918
+ if (lwcRuntimeFlags.ENABLE_PROGRAMMATIC_STYLESHEETS) {
5919
+ const {
5920
+ stylesheets
5921
+ } = ctor;
5922
+ if (!isUndefined$1(stylesheets)) {
5923
+ const valid = validateComponentStylesheets(vm, stylesheets);
5924
+ if (valid) {
5925
+ return flattenStylesheets(stylesheets);
5926
+ } else if (process.env.NODE_ENV !== 'production') {
5927
+ logError(`static stylesheets must be an array of CSS stylesheets. Found invalid stylesheets on <${vm.tagName}>`, vm);
5928
+ }
5929
+ }
5930
+ }
5931
+ return null;
5932
+ }
5811
5933
  function computeShadowMode(vm, renderer) {
5812
5934
  const {
5813
5935
  def
@@ -7126,7 +7248,7 @@
7126
7248
  }
7127
7249
  return ctor;
7128
7250
  }
7129
- /* version: 2.33.0 */
7251
+ /* version: 2.34.0 */
7130
7252
 
7131
7253
  /*
7132
7254
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7233,7 +7355,9 @@
7233
7355
  //
7234
7356
  // Test utilities
7235
7357
  //
7236
- if (process.env.NODE_ENV === 'development') {
7358
+ // Only used in LWC's Karma tests
7359
+ // @ts-ignore
7360
+ if (process.env.NODE_ENV !== 'production' && typeof __karma__ !== 'undefined') {
7237
7361
  // @ts-ignore
7238
7362
  window.__lwcResetGlobalStylesheets = () => {
7239
7363
  stylesheetCache.clear();
@@ -8099,7 +8223,7 @@
8099
8223
  function isNull(obj) {
8100
8224
  return obj === null;
8101
8225
  }
8102
- /** version: 2.33.0 */
8226
+ /** version: 2.34.0 */
8103
8227
 
8104
8228
  /*
8105
8229
  * Copyright (c) 2018, salesforce.com, inc.
@@ -8660,7 +8784,7 @@
8660
8784
  });
8661
8785
  freeze(LightningElement);
8662
8786
  seal(LightningElement.prototype);
8663
- /* version: 2.33.0 */
8787
+ /* version: 2.34.0 */
8664
8788
 
8665
8789
  exports.LightningElement = LightningElement;
8666
8790
  exports.__unstable__ProfilerControl = profilerControl;