@lwc/engine-core 6.1.0 → 6.2.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.
package/dist/index.js CHANGED
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * Copyright (c) 2024 Salesforce, Inc.
3
3
  */
4
- import { noop, StringToLowerCase, isNull, ArrayPush as ArrayPush$1, ArrayJoin, isFrozen, isUndefined as isUndefined$1, defineProperty, ArrayIndexOf, ArraySplice, create, seal, isAPIFeatureEnabled, isArray as isArray$1, isFunction as isFunction$1, keys, hasOwnProperty as hasOwnProperty$1, entries, AriaPropNameToAttrNameMap, getPropertyDescriptor, forEach, defineProperties, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, assign, freeze, isObject, KEY__SYNTHETIC_MODE, isString, assert, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, isFalse, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, getOwnPropertyNames as getOwnPropertyNames$1, getOwnPropertyDescriptors, htmlPropertyToAttribute, ArraySlice, ArrayMap, KEY__SCOPED_CSS, kebabCaseToCamelCase, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, StringSlice, ArrayShift, ArrayUnshift, isTrue, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, ArraySome, ArrayPop, isNumber, StringReplace, LOWEST_API_VERSION, KEY__NATIVE_GET_ELEMENT_BY_ID, KEY__NATIVE_QUERY_SELECTOR_ALL, ID_REFERENCING_ATTRIBUTES_SET, KEY__SHADOW_TOKEN, ArrayFilter, StringSplit, arrayEvery, ArrayIncludes, ArrayCopyWithin, ArrayFill, ArraySort, ArrayReverse } from '@lwc/shared';
4
+ import { noop, StringToLowerCase, isNull, ArrayPush as ArrayPush$1, ArrayJoin, isFrozen, isUndefined as isUndefined$1, defineProperty, ArrayIndexOf, ArraySplice, create, isFalse, isFunction as isFunction$1, isObject, seal, isAPIFeatureEnabled, isArray as isArray$1, keys, hasOwnProperty as hasOwnProperty$1, entries, AriaPropNameToAttrNameMap, getPropertyDescriptor, forEach, defineProperties, getPrototypeOf as getPrototypeOf$1, setPrototypeOf, assign, freeze, KEY__SYNTHETIC_MODE, isString, assert, toString as toString$1, getOwnPropertyDescriptor as getOwnPropertyDescriptor$1, LWC_VERSION_COMMENT_REGEX, LWC_VERSION, getOwnPropertyNames as getOwnPropertyNames$1, getOwnPropertyDescriptors, htmlPropertyToAttribute, ArraySlice, ArrayMap, KEY__SCOPED_CSS, kebabCaseToCamelCase, StringCharCodeAt, XML_NAMESPACE, XLINK_NAMESPACE, StringSlice, ArrayShift, ArrayUnshift, isTrue, SVG_NAMESPACE, KEY__SHADOW_STATIC, KEY__SHADOW_RESOLVER, ArraySome, ArrayPop, isNumber, StringReplace, LOWEST_API_VERSION, KEY__NATIVE_GET_ELEMENT_BY_ID, KEY__NATIVE_QUERY_SELECTOR_ALL, ID_REFERENCING_ATTRIBUTES_SET, KEY__SHADOW_TOKEN, ArrayFilter, StringSplit, arrayEvery, ArrayIncludes, ArrayCopyWithin, ArrayFill, ArraySort, ArrayReverse } from '@lwc/shared';
5
5
  export { setFeatureFlag, setFeatureFlagForTest } from '@lwc/features';
6
6
 
7
7
  /*
@@ -232,6 +232,7 @@ class ReactiveObserver {
232
232
  }
233
233
  observe(job) {
234
234
  const inceptionReactiveRecord = currentReactiveObserver;
235
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
235
236
  currentReactiveObserver = this;
236
237
  let error;
237
238
  try {
@@ -281,6 +282,80 @@ class ReactiveObserver {
281
282
  // we keep track of observing records where the observing record was added to so we can do some clean up later on
282
283
  ArrayPush$1.call(this.listeners, reactiveObservers);
283
284
  }
285
+ isObserving() {
286
+ return currentReactiveObserver === this;
287
+ }
288
+ }
289
+
290
+ /*
291
+ * Copyright (c) 2024, salesforce.com, inc.
292
+ * All rights reserved.
293
+ * SPDX-License-Identifier: MIT
294
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
295
+ */
296
+ /**
297
+ * This map keeps track of objects to signals. There is an assumption that the signal is strongly referenced
298
+ * on the object which allows the SignalTracker to be garbage collected along with the object.
299
+ */
300
+ const TargetToSignalTrackerMap = new WeakMap();
301
+ function getSignalTracker(target) {
302
+ let signalTracker = TargetToSignalTrackerMap.get(target);
303
+ if (isUndefined$1(signalTracker)) {
304
+ signalTracker = new SignalTracker();
305
+ TargetToSignalTrackerMap.set(target, signalTracker);
306
+ }
307
+ return signalTracker;
308
+ }
309
+ function subscribeToSignal(target, signal, update) {
310
+ const signalTracker = getSignalTracker(target);
311
+ if (isFalse(signalTracker.seen(signal))) {
312
+ signalTracker.subscribeToSignal(signal, update);
313
+ }
314
+ }
315
+ function unsubscribeFromSignals(target) {
316
+ if (TargetToSignalTrackerMap.has(target)) {
317
+ const signalTracker = getSignalTracker(target);
318
+ signalTracker.unsubscribeFromSignals();
319
+ signalTracker.reset();
320
+ }
321
+ }
322
+ /**
323
+ * This class is used to keep track of the signals associated to a given object.
324
+ * It is used to prevent the LWC engine from subscribing duplicate callbacks multiple times
325
+ * to the same signal. Additionally, it keeps track of all signal unsubscribe callbacks, handles invoking
326
+ * them when necessary and discarding them.
327
+ */
328
+ class SignalTracker {
329
+ constructor() {
330
+ this.signalToUnsubscribeMap = new Map();
331
+ }
332
+ seen(signal) {
333
+ return this.signalToUnsubscribeMap.has(signal);
334
+ }
335
+ subscribeToSignal(signal, update) {
336
+ try {
337
+ const unsubscribe = signal.subscribe(update);
338
+ if (isFunction$1(unsubscribe)) {
339
+ // TODO [#3978]: Evaluate how we should handle the case when unsubscribe is not a function.
340
+ // Long term we should throw an error or log a warning.
341
+ this.signalToUnsubscribeMap.set(signal, unsubscribe);
342
+ }
343
+ }
344
+ catch (err) {
345
+ logWarnOnce(`Attempted to subscribe to an object that has the shape of a signal but received the following error: ${err?.stack ?? err}`);
346
+ }
347
+ }
348
+ unsubscribeFromSignals() {
349
+ try {
350
+ this.signalToUnsubscribeMap.forEach((unsubscribe) => unsubscribe());
351
+ }
352
+ catch (err) {
353
+ logWarnOnce(`Attempted to call a signal's unsubscribe callback but received the following error: ${err?.stack ?? err}`);
354
+ }
355
+ }
356
+ reset() {
357
+ this.signalToUnsubscribeMap.clear();
358
+ }
284
359
  }
285
360
 
286
361
  /*
@@ -302,10 +377,26 @@ function componentValueMutated(vm, key) {
302
377
  valueMutated(vm.component, key);
303
378
  }
304
379
  }
305
- function componentValueObserved(vm, key) {
380
+ function componentValueObserved(vm, key, target = {}) {
381
+ const { component, tro } = vm;
306
382
  // On the server side, we don't need mutation tracking. Skipping it improves performance.
307
383
  if (process.env.IS_BROWSER) {
308
- valueObserved(vm.component, key);
384
+ valueObserved(component, key);
385
+ }
386
+ // The portion of reactivity that's exposed to signals is to subscribe a callback to re-render the VM (templates).
387
+ // We check check the following to ensure re-render is subscribed at the correct time.
388
+ // 1. The template is currently being rendered (there is a template reactive observer)
389
+ // 2. There was a call to a getter to access the signal (happens during vnode generation)
390
+ if (lwcRuntimeFlags.ENABLE_EXPERIMENTAL_SIGNALS &&
391
+ isObject(target) &&
392
+ !isNull(target) &&
393
+ 'value' in target &&
394
+ 'subscribe' in target &&
395
+ isFunction$1(target.subscribe) &&
396
+ // Only subscribe if a template is being rendered by the engine
397
+ tro.isObserving()) {
398
+ // Subscribe the template reactive observer's notify method, which will mark the vm as dirty and schedule hydration.
399
+ subscribeToSignal(component, target, tro.notify.bind(tro));
309
400
  }
310
401
  }
311
402
  function createReactiveObserver(callback) {
@@ -342,6 +433,7 @@ function addCallbackToNextTick(callback) {
342
433
  }
343
434
  }
344
435
  if (nextTickCallbackQueue.length === 0) {
436
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
345
437
  Promise.resolve().then(flushCallbackQueue);
346
438
  }
347
439
  ArrayPush$1.call(nextTickCallbackQueue, callback);
@@ -409,6 +501,29 @@ function assertNotProd() {
409
501
  throw new ReferenceError();
410
502
  }
411
503
  }
504
+ // Temporary fix for when the LWC v5 compiler is used in conjunction with a v6+ engine
505
+ // The old compiler format used the "slot" attribute in the `data` bag, whereas the new
506
+ // format uses the special `slotAssignment` key.
507
+ // This should be removed when the LWC v5 compiler is not used anywhere where it could be mismatched
508
+ // with another LWC engine version.
509
+ // TODO [#3974]: remove temporary logic to support v5 compiler + v6+ engine
510
+ function applyTemporaryCompilerV5SlotFix(data) {
511
+ if (lwcRuntimeFlags.DISABLE_TEMPORARY_V5_COMPILER_SUPPORT) {
512
+ return data;
513
+ }
514
+ const { attrs } = data;
515
+ if (!isUndefined$1(attrs)) {
516
+ const { slot } = attrs;
517
+ if (!isUndefined$1(slot) && !isNull(slot)) {
518
+ return {
519
+ ...data,
520
+ attrs: cloneAndOmitKey(attrs, 'slot'),
521
+ slotAssignment: String(slot),
522
+ };
523
+ }
524
+ }
525
+ return data;
526
+ }
412
527
 
413
528
  /*
414
529
  * Copyright (c) 2020, salesforce.com, inc.
@@ -418,15 +533,20 @@ function assertNotProd() {
418
533
  */
419
534
  function resolveCircularModuleDependency(fn) {
420
535
  const module = fn();
421
- return (module === null || module === void 0 ? void 0 : module.__esModule) ? module.default : module;
536
+ return module?.__esModule ? module.default : module;
422
537
  }
423
538
  function isCircularModuleDependency(obj) {
424
539
  return isFunction$1(obj) && hasOwnProperty$1.call(obj, '__circular__');
425
540
  }
426
541
 
427
- var _a, _b;
428
- const instrumentDef = (_a = globalThis.__lwc_instrument_cmp_def) !== null && _a !== void 0 ? _a : noop;
429
- const instrumentInstance = (_b = globalThis.__lwc_instrument_cmp_instance) !== null && _b !== void 0 ? _b : noop;
542
+ /*
543
+ * Copyright (c) 2023, salesforce.com, inc.
544
+ * All rights reserved.
545
+ * SPDX-License-Identifier: MIT
546
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
547
+ */
548
+ const instrumentDef = globalThis.__lwc_instrument_cmp_def ?? noop;
549
+ const instrumentInstance = globalThis.__lwc_instrument_cmp_instance ?? noop;
430
550
 
431
551
  /*
432
552
  * Copyright (c) 2018, salesforce.com, inc.
@@ -1378,6 +1498,7 @@ function initGlobalStylesheet() {
1378
1498
  }
1379
1499
  return promise;
1380
1500
  });
1501
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
1381
1502
  Promise.all(promises).then((stylesheetTexts) => {
1382
1503
  // When replaceSync() is called, the entire contents of the constructable stylesheet are replaced
1383
1504
  // with the copied+concatenated styles. This means that any shadow root's adoptedStyleSheets that
@@ -1489,7 +1610,6 @@ const LightningElement = function () {
1489
1610
  const { assertInstanceOfHTMLElement } = vm.renderer;
1490
1611
  assertInstanceOfHTMLElement(vm.elm, `Component creation requires a DOM element to be associated to ${vm}.`);
1491
1612
  }
1492
- const component = this;
1493
1613
  setPrototypeOf(elm, bridge.prototype);
1494
1614
  vm.component = this;
1495
1615
  // Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
@@ -1504,7 +1624,7 @@ const LightningElement = function () {
1504
1624
  }
1505
1625
  markLockerLiveObject(this);
1506
1626
  // Linking elm, shadow root and component with the VM.
1507
- associateVM(component, vm);
1627
+ associateVM(this, vm);
1508
1628
  associateVM(elm, vm);
1509
1629
  if (vm.renderMode === 1 /* RenderMode.Shadow */) {
1510
1630
  vm.renderRoot = doAttachShadow(vm);
@@ -1928,8 +2048,9 @@ function createObservedFieldPropertyDescriptor(key) {
1928
2048
  return {
1929
2049
  get() {
1930
2050
  const vm = getAssociatedVM(this);
1931
- componentValueObserved(vm, key);
1932
- return vm.cmpFields[key];
2051
+ const val = vm.cmpFields[key];
2052
+ componentValueObserved(vm, key, val);
2053
+ return val;
1933
2054
  },
1934
2055
  set(newValue) {
1935
2056
  const vm = getAssociatedVM(this);
@@ -2040,6 +2161,7 @@ function createConfigWatcher(component, configCallback, callbackWhenConfigIsRead
2040
2161
  if (hasPendingConfig === false) {
2041
2162
  hasPendingConfig = true;
2042
2163
  // collect new config in the micro-task
2164
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
2043
2165
  Promise.resolve().then(() => {
2044
2166
  hasPendingConfig = false;
2045
2167
  // resetting current reactive params
@@ -2182,6 +2304,7 @@ function installWireAdapters(vm) {
2182
2304
  connector.connect();
2183
2305
  if (!lwcRuntimeFlags.ENABLE_WIRE_SYNC_EMIT) {
2184
2306
  if (hasDynamicParams) {
2307
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
2185
2308
  Promise.resolve().then(computeConfigAndUpdate);
2186
2309
  return;
2187
2310
  }
@@ -2233,8 +2356,9 @@ function createPublicPropertyDescriptor(key) {
2233
2356
  }
2234
2357
  return;
2235
2358
  }
2236
- componentValueObserved(vm, key);
2237
- return vm.cmpProps[key];
2359
+ const val = vm.cmpProps[key];
2360
+ componentValueObserved(vm, key, val);
2361
+ return val;
2238
2362
  },
2239
2363
  set(newValue) {
2240
2364
  const vm = getAssociatedVM(this);
@@ -2307,8 +2431,9 @@ function internalTrackDecorator(key) {
2307
2431
  return {
2308
2432
  get() {
2309
2433
  const vm = getAssociatedVM(this);
2310
- componentValueObserved(vm, key);
2311
- return vm.cmpFields[key];
2434
+ const val = vm.cmpFields[key];
2435
+ componentValueObserved(vm, key, val);
2436
+ return val;
2312
2437
  },
2313
2438
  set(newValue) {
2314
2439
  const vm = getAssociatedVM(this);
@@ -3143,10 +3268,15 @@ function createComponentDef(Ctor) {
3143
3268
  logError(`Missing ${ctorName}.constructor, ${ctorName} should have a "constructor" property.`);
3144
3269
  }
3145
3270
  if (!isUndefined$1(ctorShadowSupportMode) &&
3271
+ ctorShadowSupportMode !== "any" /* ShadowSupportMode.Any */ &&
3146
3272
  ctorShadowSupportMode !== "reset" /* ShadowSupportMode.Default */ &&
3147
3273
  ctorShadowSupportMode !== "native" /* ShadowSupportMode.Native */) {
3148
3274
  logError(`Invalid value for static property shadowSupportMode: '${ctorShadowSupportMode}'`);
3149
3275
  }
3276
+ // TODO [#3971]: Completely remove shadowSupportMode "any"
3277
+ if (ctorShadowSupportMode === "any" /* ShadowSupportMode.Any */) {
3278
+ logWarn(`Invalid value 'any' for static property shadowSupportMode. 'any' is deprecated and will be removed in a future release--use 'native' instead.`);
3279
+ }
3150
3280
  if (!isUndefined$1(ctorRenderMode) &&
3151
3281
  ctorRenderMode !== 'light' &&
3152
3282
  ctorRenderMode !== 'shadow') {
@@ -3177,6 +3307,14 @@ function createComponentDef(Ctor) {
3177
3307
  let shadowSupportMode = superDef.shadowSupportMode;
3178
3308
  if (!isUndefined$1(ctorShadowSupportMode)) {
3179
3309
  shadowSupportMode = ctorShadowSupportMode;
3310
+ if (isReportingEnabled() &&
3311
+ (shadowSupportMode === "any" /* ShadowSupportMode.Any */ ||
3312
+ shadowSupportMode === "native" /* ShadowSupportMode.Native */)) {
3313
+ report("ShadowSupportModeUsage" /* ReportingEventId.ShadowSupportModeUsage */, {
3314
+ tagName: Ctor.name,
3315
+ mode: shadowSupportMode,
3316
+ });
3317
+ }
3180
3318
  }
3181
3319
  let renderMode = superDef.renderMode;
3182
3320
  if (!isUndefined$1(ctorRenderMode)) {
@@ -3496,7 +3634,7 @@ function getNearestShadowComponent(vm) {
3496
3634
  function getScopeTokenClass(owner, legacy) {
3497
3635
  const { cmpTemplate, context } = owner;
3498
3636
  return ((context.hasScopedStyles &&
3499
- (legacy ? cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.legacyStylesheetToken : cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken)) ||
3637
+ (legacy ? cmpTemplate?.legacyStylesheetToken : cmpTemplate?.stylesheetToken)) ||
3500
3638
  null);
3501
3639
  }
3502
3640
  /**
@@ -3623,7 +3761,7 @@ function patchAttributes(oldVnode, vnode, renderer) {
3623
3761
  }
3624
3762
  function patchSlotAssignment(oldVnode, vnode, renderer) {
3625
3763
  const { slotAssignment } = vnode;
3626
- if ((oldVnode === null || oldVnode === void 0 ? void 0 : oldVnode.slotAssignment) === slotAssignment) {
3764
+ if (oldVnode?.slotAssignment === slotAssignment) {
3627
3765
  return;
3628
3766
  }
3629
3767
  const { elm } = vnode;
@@ -3700,6 +3838,8 @@ function getMapFromClassName(className) {
3700
3838
  return EmptyObject;
3701
3839
  }
3702
3840
  // computed class names must be string
3841
+ // This will throw if className is a symbol or null-prototype object
3842
+ // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
3703
3843
  className = isString(className) ? className : className + '';
3704
3844
  let map = classNameToClassMap[className];
3705
3845
  if (map) {
@@ -3780,9 +3920,8 @@ function patchStyleAttribute(oldVnode, vnode, renderer) {
3780
3920
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3781
3921
  */
3782
3922
  function applyEventListeners(vnode, renderer) {
3783
- var _a;
3784
3923
  const { elm } = vnode;
3785
- const on = (_a = vnode.data) === null || _a === void 0 ? void 0 : _a.on;
3924
+ const on = vnode.data?.on;
3786
3925
  if (isUndefined$1(on)) {
3787
3926
  return;
3788
3927
  }
@@ -3917,7 +4056,7 @@ function traverseAndSetElements(root, parts, renderer) {
3917
4056
  * @param renderer - the renderer to use
3918
4057
  * @param mount - true this is a first (mount) render as opposed to a subsequent (patch) render
3919
4058
  */
3920
- function applyStaticParts(root, vnode, renderer, mount) {
4059
+ function mountStaticParts(root, vnode, renderer) {
3921
4060
  // On the server, we don't support ref (because it relies on renderedCallback), nor do we
3922
4061
  // support event listeners (no interactivity), so traversing parts makes no sense
3923
4062
  if (!process.env.IS_BROWSER) {
@@ -3927,20 +4066,46 @@ function applyStaticParts(root, vnode, renderer, mount) {
3927
4066
  if (isUndefined$1(parts)) {
3928
4067
  return;
3929
4068
  }
3930
- // This adds `part.elm` to each `part`. We have to do this on every mount/patch because the `parts`
4069
+ // This adds `part.elm` to each `part`. We have to do this on every mount because the `parts`
3931
4070
  // array is recreated from scratch every time, so each `part.elm` is now undefined.
3932
- // TODO [#3800]: avoid calling traverseAndSetElements on every re-render
3933
4071
  traverseAndSetElements(root, parts, renderer);
3934
4072
  // Currently only event listeners and refs are supported for static vnodes
3935
4073
  for (const part of parts) {
3936
- if (mount) {
3937
- // Event listeners only need to be applied once when mounting
3938
- applyEventListeners(part, renderer);
3939
- }
4074
+ // Event listeners only need to be applied once when mounting
4075
+ applyEventListeners(part, renderer);
3940
4076
  // Refs must be updated after every render due to refVNodes getting reset before every render
3941
4077
  applyRefs(part, owner);
3942
4078
  }
3943
4079
  }
4080
+ /**
4081
+ * Mounts elements to the newly generated VStatic node
4082
+ *
4083
+ * @param n1 - the previous VStatic vnode
4084
+ * @param n2 - the current VStatic vnode
4085
+ */
4086
+ function patchStaticParts(n1, n2) {
4087
+ // On the server, we don't support ref (because it relies on renderedCallback), nor do we
4088
+ // support event listeners (no interactivity), so traversing parts makes no sense
4089
+ if (!process.env.IS_BROWSER) {
4090
+ return;
4091
+ }
4092
+ const { parts: currParts, owner: currPartsOwner } = n2;
4093
+ if (isUndefined$1(currParts)) {
4094
+ return;
4095
+ }
4096
+ const { parts: prevParts } = n1;
4097
+ if (process.env.NODE_ENV !== 'production') {
4098
+ assert.isTrue(currParts.length === prevParts?.length, 'Expected static parts to be the same for the same element. This is an error with the LWC framework itself.');
4099
+ }
4100
+ for (let i = 0; i < currParts.length; i++) {
4101
+ const part = currParts[i];
4102
+ // Patch only occurs if the vnode is newly generated, which means the part.elm is always undefined
4103
+ // Since the vnode and elements are the same we can safely assume that prevParts[i].elm is defined.
4104
+ part.elm = prevParts[i].elm;
4105
+ // Refs must be updated after every render due to refVNodes getting reset before every render
4106
+ applyRefs(part, currPartsOwner);
4107
+ }
4108
+ }
3944
4109
 
3945
4110
  /*
3946
4111
  * Copyright (c) 2018, salesforce.com, inc.
@@ -3957,7 +4122,6 @@ function patchChildren(c1, c2, parent, renderer) {
3957
4122
  }
3958
4123
  }
3959
4124
  function patch(n1, n2, parent, renderer) {
3960
- var _a, _b;
3961
4125
  if (n1 === n2) {
3962
4126
  return;
3963
4127
  }
@@ -3990,15 +4154,14 @@ function patch(n1, n2, parent, renderer) {
3990
4154
  patchFragment(n1, n2, parent, renderer);
3991
4155
  break;
3992
4156
  case 2 /* VNodeType.Element */:
3993
- patchElement(n1, n2, (_a = n2.data.renderer) !== null && _a !== void 0 ? _a : renderer);
4157
+ patchElement(n1, n2, n2.data.renderer ?? renderer);
3994
4158
  break;
3995
4159
  case 3 /* VNodeType.CustomElement */:
3996
- patchCustomElement(n1, n2, parent, (_b = n2.data.renderer) !== null && _b !== void 0 ? _b : renderer);
4160
+ patchCustomElement(n1, n2, parent, n2.data.renderer ?? renderer);
3997
4161
  break;
3998
4162
  }
3999
4163
  }
4000
4164
  function mount(node, parent, renderer, anchor) {
4001
- var _a, _b;
4002
4165
  switch (node.type) {
4003
4166
  case 0 /* VNodeType.Text */:
4004
4167
  // VText has no special capability, fallback to the owner's renderer
@@ -4017,11 +4180,11 @@ function mount(node, parent, renderer, anchor) {
4017
4180
  break;
4018
4181
  case 2 /* VNodeType.Element */:
4019
4182
  // If the vnode data has a renderer override use it, else fallback to owner's renderer
4020
- mountElement(node, parent, anchor, (_a = node.data.renderer) !== null && _a !== void 0 ? _a : renderer);
4183
+ mountElement(node, parent, anchor, node.data.renderer ?? renderer);
4021
4184
  break;
4022
4185
  case 3 /* VNodeType.CustomElement */:
4023
4186
  // If the vnode data has a renderer override use it, else fallback to owner's renderer
4024
- mountCustomElement(node, parent, anchor, (_b = node.data.renderer) !== null && _b !== void 0 ? _b : renderer);
4187
+ mountCustomElement(node, parent, anchor, node.data.renderer ?? renderer);
4025
4188
  break;
4026
4189
  }
4027
4190
  }
@@ -4083,11 +4246,11 @@ function mountElement(vnode, parent, anchor, renderer) {
4083
4246
  mountVNodes(vnode.children, elm, renderer, null);
4084
4247
  }
4085
4248
  function patchStatic(n1, n2, renderer) {
4086
- const elm = (n2.elm = n1.elm);
4249
+ n2.elm = n1.elm;
4087
4250
  // slotAssignments can only apply to the top level element, never to a static part.
4088
4251
  patchSlotAssignment(n1, n2, renderer);
4089
4252
  // The `refs` object is blown away in every re-render, so we always need to re-apply them
4090
- applyStaticParts(elm, n2, renderer, false);
4253
+ patchStaticParts(n1, n2);
4091
4254
  }
4092
4255
  function patchElement(n1, n2, renderer) {
4093
4256
  const elm = (n2.elm = n1.elm);
@@ -4110,7 +4273,7 @@ function mountStatic(vnode, parent, anchor, renderer) {
4110
4273
  // slotAssignments can only apply to the top level element, never to a static part.
4111
4274
  patchSlotAssignment(null, vnode, renderer);
4112
4275
  insertNode(elm, parent, anchor, renderer);
4113
- applyStaticParts(elm, vnode, renderer, true);
4276
+ mountStaticParts(elm, vnode, renderer);
4114
4277
  }
4115
4278
  function mountCustomElement(vnode, parent, anchor, renderer) {
4116
4279
  const { sel, owner, ctor } = vnode;
@@ -4372,17 +4535,15 @@ function applyStyleScoping(elm, owner, renderer) {
4372
4535
  }
4373
4536
  }
4374
4537
  function applyDomManual(elm, vnode) {
4375
- var _a;
4376
4538
  const { owner, data: { context }, } = vnode;
4377
- if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && ((_a = context === null || context === void 0 ? void 0 : context.lwc) === null || _a === void 0 ? void 0 : _a.dom) === "manual" /* LwcDomMode.Manual */) {
4539
+ if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && context?.lwc?.dom === "manual" /* LwcDomMode.Manual */) {
4378
4540
  elm.$domManual$ = true;
4379
4541
  }
4380
4542
  }
4381
4543
  function applyElementRestrictions(elm, vnode) {
4382
- var _a, _b;
4383
4544
  if (process.env.NODE_ENV !== 'production') {
4384
4545
  const isSynthetic = vnode.owner.shadowMode === 1 /* ShadowMode.Synthetic */;
4385
- const isPortal = vnode.type === 2 /* VNodeType.Element */ && ((_b = (_a = vnode.data.context) === null || _a === void 0 ? void 0 : _a.lwc) === null || _b === void 0 ? void 0 : _b.dom) === "manual" /* LwcDomMode.Manual */;
4546
+ const isPortal = vnode.type === 2 /* VNodeType.Element */ && vnode.data.context?.lwc?.dom === "manual" /* LwcDomMode.Manual */;
4386
4547
  const isLight = vnode.owner.renderMode === 0 /* RenderMode.Light */;
4387
4548
  patchElementWithRestrictions(elm, {
4388
4549
  isPortal,
@@ -4489,7 +4650,6 @@ function createViewModelHook(elm, vnode, renderer) {
4489
4650
  return vm;
4490
4651
  }
4491
4652
  function allocateInSlot(vm, children, owner) {
4492
- var _a;
4493
4653
  const { cmpSlots: { slotAssignments: oldSlotsMapping }, } = vm;
4494
4654
  const cmpSlotsMapping = create(null);
4495
4655
  // Collect all slots into cmpSlotsMapping
@@ -4500,7 +4660,7 @@ function allocateInSlot(vm, children, owner) {
4500
4660
  }
4501
4661
  let slotName = '';
4502
4662
  if (isVBaseElement(vnode) || isVStatic(vnode)) {
4503
- slotName = (_a = vnode.slotAssignment) !== null && _a !== void 0 ? _a : '';
4663
+ slotName = vnode.slotAssignment ?? '';
4504
4664
  }
4505
4665
  else if (isVScopedSlotFragment(vnode)) {
4506
4666
  slotName = vnode.slotName;
@@ -4509,6 +4669,7 @@ function allocateInSlot(vm, children, owner) {
4509
4669
  // but elm.setAttribute('slot', Symbol(1)) is an error.
4510
4670
  // the following line also throws same error for symbols
4511
4671
  // Similar for Object.create(null)
4672
+ // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
4512
4673
  const normalizedSlotName = '' + slotName;
4513
4674
  const vnodes = (cmpSlotsMapping[normalizedSlotName] =
4514
4675
  cmpSlotsMapping[normalizedSlotName] || []);
@@ -4815,6 +4976,8 @@ function h(sel, data, children = EmptyArray) {
4815
4976
  }
4816
4977
  });
4817
4978
  }
4979
+ // TODO [#3974]: remove temporary logic to support v5 compiler + v6+ engine
4980
+ data = applyTemporaryCompilerV5SlotFix(data);
4818
4981
  const { key, slotAssignment } = data;
4819
4982
  const vnode = {
4820
4983
  type: 2 /* VNodeType.Element */,
@@ -4851,6 +5014,8 @@ function s(slotName, data, children, slotset) {
4851
5014
  }
4852
5015
  const vmBeingRendered = getVMBeingRendered();
4853
5016
  const { renderMode, apiVersion } = vmBeingRendered;
5017
+ // TODO [#3974]: remove temporary logic to support v5 compiler + v6+ engine
5018
+ data = applyTemporaryCompilerV5SlotFix(data);
4854
5019
  if (!isUndefined$1(slotset) &&
4855
5020
  !isUndefined$1(slotset.slotAssignments) &&
4856
5021
  !isUndefined$1(slotset.slotAssignments[slotName]) &&
@@ -4902,11 +5067,11 @@ function s(slotName, data, children, slotset) {
4902
5067
  // to the vnode because the current way the diffing algo works, it will replace the original reference
4903
5068
  // to the host element with a new one. This means the new element will be mounted and immediately unmounted.
4904
5069
  // Creating a copy of the vnode to preserve a reference to the previous host element.
4905
- clonedVNode = Object.assign(Object.assign({}, vnode), { slotAssignment: data.slotAssignment });
5070
+ clonedVNode = { ...vnode, slotAssignment: data.slotAssignment };
4906
5071
  }
4907
5072
  // If the slot content is standard type, the content is static, no additional
4908
5073
  // processing needed on the vnode
4909
- ArrayPush$1.call(newChildren, clonedVNode !== null && clonedVNode !== void 0 ? clonedVNode : vnode);
5074
+ ArrayPush$1.call(newChildren, clonedVNode ?? vnode);
4910
5075
  }
4911
5076
  }
4912
5077
  }
@@ -4954,6 +5119,8 @@ function c(sel, Ctor, data, children = EmptyArray) {
4954
5119
  });
4955
5120
  }
4956
5121
  }
5122
+ // TODO [#3974]: remove temporary logic to support v5 compiler + v6+ engine
5123
+ data = applyTemporaryCompilerV5SlotFix(data);
4957
5124
  const { key, slotAssignment } = data;
4958
5125
  let elm, aChildren, vm;
4959
5126
  const vnode = {
@@ -5363,7 +5530,7 @@ function logGlobalOperationStart(opId, vm) {
5363
5530
  start(markName);
5364
5531
  }
5365
5532
  if (isProfilerEnabled) {
5366
- currentDispatcher(opId, 0 /* Phase.Start */, vm === null || vm === void 0 ? void 0 : vm.tagName, vm === null || vm === void 0 ? void 0 : vm.idx, vm === null || vm === void 0 ? void 0 : vm.renderMode, vm === null || vm === void 0 ? void 0 : vm.shadowMode);
5533
+ currentDispatcher(opId, 0 /* Phase.Start */, vm?.tagName, vm?.idx, vm?.renderMode, vm?.shadowMode);
5367
5534
  }
5368
5535
  }
5369
5536
  function logGlobalOperationEnd(opId, vm) {
@@ -5373,7 +5540,7 @@ function logGlobalOperationEnd(opId, vm) {
5373
5540
  end(opName, markName);
5374
5541
  }
5375
5542
  if (isProfilerEnabled) {
5376
- currentDispatcher(opId, 1 /* Phase.Stop */, vm === null || vm === void 0 ? void 0 : vm.tagName, vm === null || vm === void 0 ? void 0 : vm.idx, vm === null || vm === void 0 ? void 0 : vm.renderMode, vm === null || vm === void 0 ? void 0 : vm.shadowMode);
5543
+ currentDispatcher(opId, 1 /* Phase.Stop */, vm?.tagName, vm?.idx, vm?.renderMode, vm?.shadowMode);
5377
5544
  }
5378
5545
  }
5379
5546
 
@@ -5395,7 +5562,6 @@ function validateSlots(vm) {
5395
5562
  assertNotProd(); // this method should never leak to prod
5396
5563
  const { cmpSlots } = vm;
5397
5564
  for (const slotName in cmpSlots.slotAssignments) {
5398
- // eslint-disable-next-line @lwc/lwc-internal/no-production-assert
5399
5565
  assert.isTrue(isArray$1(cmpSlots.slotAssignments[slotName]), `Slots can only be set to an array, instead received ${toString$1(cmpSlots.slotAssignments[slotName])} for slot "${slotName}" in ${vm}.`);
5400
5566
  }
5401
5567
  }
@@ -5693,16 +5859,14 @@ Ctor, metadata) {
5693
5859
  return Ctor;
5694
5860
  }
5695
5861
  function getComponentRegisteredTemplate(Ctor) {
5696
- var _a;
5697
- return (_a = registeredComponentMap.get(Ctor)) === null || _a === void 0 ? void 0 : _a.tmpl;
5862
+ return registeredComponentMap.get(Ctor)?.tmpl;
5698
5863
  }
5699
5864
  function getComponentRegisteredName(Ctor) {
5700
- var _a;
5701
- return (_a = registeredComponentMap.get(Ctor)) === null || _a === void 0 ? void 0 : _a.sel;
5865
+ return registeredComponentMap.get(Ctor)?.sel;
5702
5866
  }
5703
5867
  function getComponentAPIVersion(Ctor) {
5704
5868
  const metadata = registeredComponentMap.get(Ctor);
5705
- const apiVersion = metadata === null || metadata === void 0 ? void 0 : metadata.apiVersion;
5869
+ const apiVersion = metadata?.apiVersion;
5706
5870
  if (isUndefined$1(apiVersion)) {
5707
5871
  // This should only occur in our Karma tests; in practice every component
5708
5872
  // is registered, and so this code path should not get hit. But to be safe,
@@ -5720,11 +5884,27 @@ function getTemplateReactiveObserver(vm) {
5720
5884
  }
5721
5885
  });
5722
5886
  }
5887
+ function resetTemplateObserverAndUnsubscribe(vm) {
5888
+ const { tro, component } = vm;
5889
+ tro.reset();
5890
+ // Unsubscribe every time the template reactive observer is reset.
5891
+ if (lwcRuntimeFlags.ENABLE_EXPERIMENTAL_SIGNALS) {
5892
+ unsubscribeFromSignals(component);
5893
+ }
5894
+ }
5723
5895
  function renderComponent(vm) {
5724
5896
  if (process.env.NODE_ENV !== 'production') {
5725
5897
  assert.invariant(vm.isDirty, `${vm} is not dirty.`);
5726
5898
  }
5727
- vm.tro.reset();
5899
+ // The engine should only hold a subscription to a signal if it is rendered in the template.
5900
+ // Because of the potential presence of conditional rendering logic, we unsubscribe on each render
5901
+ // in the scenario where it is present in one condition but not the other.
5902
+ // For example:
5903
+ // 1. There is an lwc:if=true conditional where the signal is present on the template.
5904
+ // 2. The lwc:if changes to false and the signal is no longer present on the template.
5905
+ // If the signal is still subscribed to, the template will re-render when it receives a notification
5906
+ // from the signal, even though we won't be using the new value.
5907
+ resetTemplateObserverAndUnsubscribe(vm);
5728
5908
  const vnodes = invokeComponentRenderMethod(vm);
5729
5909
  vm.isDirty = false;
5730
5910
  vm.isScheduled = false;
@@ -5799,9 +5979,8 @@ function appendVM(vm) {
5799
5979
  function resetComponentStateWhenRemoved(vm) {
5800
5980
  const { state } = vm;
5801
5981
  if (state !== 2 /* VMState.disconnected */) {
5802
- const { tro } = vm;
5803
5982
  // Making sure that any observing record will not trigger the rehydrated on this vm
5804
- tro.reset();
5983
+ resetTemplateObserverAndUnsubscribe(vm);
5805
5984
  runDisconnectedCallback(vm);
5806
5985
  // Spec: https://dom.spec.whatwg.org/#concept-node-remove (step 14-15)
5807
5986
  runChildNodesDisconnectedCallback(vm);
@@ -5885,7 +6064,7 @@ function createVM(elm, ctor, renderer, options) {
5885
6064
  vm.debugInfo = create(null);
5886
6065
  }
5887
6066
  vm.stylesheets = computeStylesheets(vm, def.ctor);
5888
- const computedShadowMode = computeShadowMode(def, vm.owner, renderer);
6067
+ const computedShadowMode = computeShadowMode(def, vm.owner, renderer, hydrated);
5889
6068
  if (lwcRuntimeFlags.ENABLE_FORCE_SHADOW_MIGRATE_MODE) {
5890
6069
  vm.shadowMode = 0 /* ShadowMode.Native */;
5891
6070
  vm.shadowMigrateMode = computedShadowMode === 1 /* ShadowMode.Synthetic */;
@@ -5972,16 +6151,21 @@ function computeShadowAndRenderMode(Ctor, renderer) {
5972
6151
  const def = getComponentInternalDef(Ctor);
5973
6152
  const { renderMode } = def;
5974
6153
  // Assume null `owner` - this is what happens in hydration cases anyway
5975
- const shadowMode = computeShadowMode(def, /* owner */ null, renderer);
6154
+ // Also assume we are not in hydration mode for this exported API
6155
+ const shadowMode = computeShadowMode(def, /* owner */ null, renderer, false);
5976
6156
  return { renderMode, shadowMode };
5977
6157
  }
5978
- function computeShadowMode(def, owner, renderer) {
6158
+ function computeShadowMode(def, owner, renderer, hydrated) {
5979
6159
  // Force the shadow mode to always be native. Used for running tests with synthetic shadow patches
5980
6160
  // on, but components running in actual native shadow mode
5981
6161
  if (process.env.NODE_ENV !== 'production' &&
5982
6162
  lwcRuntimeFlags.ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST) {
5983
6163
  return 0 /* ShadowMode.Native */;
5984
6164
  }
6165
+ if (isTrue(hydrated)) {
6166
+ // hydration only supports native shadow
6167
+ return 0 /* ShadowMode.Native */;
6168
+ }
5985
6169
  const { isSyntheticShadowDefined } = renderer;
5986
6170
  let shadowMode;
5987
6171
  if (isSyntheticShadowDefined || lwcRuntimeFlags.ENABLE_FORCE_SHADOW_MIGRATE_MODE) {
@@ -6109,7 +6293,7 @@ function flushRehydrationQueue() {
6109
6293
  logGlobalOperationEnd(8 /* OperationId.GlobalRehydrate */);
6110
6294
  // re-throwing the original error will break the current tick, but since the next tick is
6111
6295
  // already scheduled, it should continue patching the rest.
6112
- throw error; // eslint-disable-line no-unsafe-finally
6296
+ throw error;
6113
6297
  }
6114
6298
  }
6115
6299
  logGlobalOperationEnd(8 /* OperationId.GlobalRehydrate */);
@@ -6582,7 +6766,7 @@ function checkAndReportViolation(elm, prop, isSetter, setValue) {
6582
6766
  setValueType = isNull(setValue) ? 'null' : typeof setValue;
6583
6767
  }
6584
6768
  report("NonStandardAriaReflection" /* ReportingEventId.NonStandardAriaReflection */, {
6585
- tagName: vm === null || vm === void 0 ? void 0 : vm.tagName,
6769
+ tagName: vm?.tagName,
6586
6770
  propertyName: prop,
6587
6771
  isSetter,
6588
6772
  setValueType,
@@ -6660,7 +6844,6 @@ function hydrateVM(vm) {
6660
6844
  runRenderedCallback(vm);
6661
6845
  }
6662
6846
  function hydrateNode(node, vnode, renderer) {
6663
- var _a, _b;
6664
6847
  let hydratedNode;
6665
6848
  switch (vnode.type) {
6666
6849
  case 0 /* VNodeType.Text */:
@@ -6680,10 +6863,10 @@ function hydrateNode(node, vnode, renderer) {
6680
6863
  hydratedNode = hydrateFragment(node, vnode, renderer);
6681
6864
  break;
6682
6865
  case 2 /* VNodeType.Element */:
6683
- hydratedNode = hydrateElement(node, vnode, (_a = vnode.data.renderer) !== null && _a !== void 0 ? _a : renderer);
6866
+ hydratedNode = hydrateElement(node, vnode, vnode.data.renderer ?? renderer);
6684
6867
  break;
6685
6868
  case 3 /* VNodeType.CustomElement */:
6686
- hydratedNode = hydrateCustomElement(node, vnode, (_b = vnode.data.renderer) !== null && _b !== void 0 ? _b : renderer);
6869
+ hydratedNode = hydrateCustomElement(node, vnode, vnode.data.renderer ?? renderer);
6687
6870
  break;
6688
6871
  }
6689
6872
  return renderer.nextSibling(hydratedNode);
@@ -6726,7 +6909,6 @@ function getValidationPredicate(optOutStaticProp) {
6726
6909
  return (_attrName) => true;
6727
6910
  }
6728
6911
  function hydrateText(node, vnode, renderer) {
6729
- var _a;
6730
6912
  if (!hasCorrectNodeType(vnode, node, 3 /* EnvNodeTypes.TEXT */, renderer)) {
6731
6913
  return handleMismatch(node, vnode, renderer);
6732
6914
  }
@@ -6736,12 +6918,11 @@ function hydrateText(node, vnode, renderer) {
6736
6918
  }
6737
6919
  }
6738
6920
  const { setText } = renderer;
6739
- setText(node, (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
6921
+ setText(node, vnode.text ?? null);
6740
6922
  vnode.elm = node;
6741
6923
  return node;
6742
6924
  }
6743
6925
  function hydrateComment(node, vnode, renderer) {
6744
- var _a;
6745
6926
  if (!hasCorrectNodeType(vnode, node, 8 /* EnvNodeTypes.COMMENT */, renderer)) {
6746
6927
  return handleMismatch(node, vnode, renderer);
6747
6928
  }
@@ -6753,7 +6934,7 @@ function hydrateComment(node, vnode, renderer) {
6753
6934
  }
6754
6935
  }
6755
6936
  const { setProperty } = renderer;
6756
- setProperty(node, NODE_VALUE_PROP, (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
6937
+ setProperty(node, NODE_VALUE_PROP, vnode.text ?? null);
6757
6938
  vnode.elm = node;
6758
6939
  return node;
6759
6940
  }
@@ -6763,7 +6944,7 @@ function hydrateStaticElement(elm, vnode, renderer) {
6763
6944
  return handleMismatch(elm, vnode, renderer);
6764
6945
  }
6765
6946
  vnode.elm = elm;
6766
- applyStaticParts(elm, vnode, renderer, true);
6947
+ mountStaticParts(elm, vnode, renderer);
6767
6948
  return elm;
6768
6949
  }
6769
6950
  function hydrateFragment(elm, vnode, renderer) {
@@ -6788,7 +6969,10 @@ function hydrateElement(elm, vnode, renderer) {
6788
6969
  if (!isUndefined$1(props) && !isUndefined$1(props.innerHTML)) {
6789
6970
  if (getProperty(elm, 'innerHTML') === props.innerHTML) {
6790
6971
  // Do a shallow clone since VNodeData may be shared across VNodes due to hoist optimization
6791
- vnode.data = Object.assign(Object.assign({}, vnode.data), { props: cloneAndOmitKey(props, 'innerHTML') });
6972
+ vnode.data = {
6973
+ ...vnode.data,
6974
+ props: cloneAndOmitKey(props, 'innerHTML'),
6975
+ };
6792
6976
  }
6793
6977
  else {
6794
6978
  if (process.env.NODE_ENV !== 'production') {
@@ -7000,7 +7184,11 @@ function validateClassAttr(vnode, elm, renderer) {
7000
7184
  className = ArrayJoin.call(classNames, ' ');
7001
7185
  }
7002
7186
  else if (!isUndefined$1(classMap)) {
7003
- classMap = Object.assign(Object.assign(Object.assign({}, classMap), (!isNull(scopedToken) ? { [scopedToken]: true } : {})), (!isNull(stylesheetTokenHost) ? { [stylesheetTokenHost]: true } : {}));
7187
+ classMap = {
7188
+ ...classMap,
7189
+ ...(!isNull(scopedToken) ? { [scopedToken]: true } : {}),
7190
+ ...(!isNull(stylesheetTokenHost) ? { [stylesheetTokenHost]: true } : {}),
7191
+ };
7004
7192
  }
7005
7193
  else {
7006
7194
  // The order of the className should be scopedToken stylesheetTokenHost
@@ -7394,5 +7582,5 @@ function readonly(obj) {
7394
7582
  }
7395
7583
 
7396
7584
  export { LightningElement, profilerControl as __unstable__ProfilerControl, reportingControl as __unstable__ReportingControl, api$1 as api, computeShadowAndRenderMode, connectRootElement, createContextProviderWithRegister, createVM, disconnectRootElement, freezeTemplate, getAssociatedVMIfPresent, getComponentAPIVersion, getComponentConstructor, getComponentDef, getComponentHtmlPrototype, hydrateRoot, isComponentConstructor, parseFragment, parseSVGFragment, readonly, registerComponent, registerDecorators, registerTemplate, runFormAssociatedCallback, runFormDisabledCallback, runFormResetCallback, runFormStateRestoreCallback, sanitizeAttribute, setHooks, swapComponent, swapStyle, swapTemplate, track, unwrap, wire };
7397
- /** version: 6.1.0 */
7585
+ /** version: 6.2.0 */
7398
7586
  //# sourceMappingURL=index.js.map