@lwc/engine-core 6.1.1 → 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.cjs.js CHANGED
@@ -236,6 +236,7 @@ class ReactiveObserver {
236
236
  }
237
237
  observe(job) {
238
238
  const inceptionReactiveRecord = currentReactiveObserver;
239
+ // eslint-disable-next-line @typescript-eslint/no-this-alias
239
240
  currentReactiveObserver = this;
240
241
  let error;
241
242
  try {
@@ -285,6 +286,80 @@ class ReactiveObserver {
285
286
  // we keep track of observing records where the observing record was added to so we can do some clean up later on
286
287
  shared.ArrayPush.call(this.listeners, reactiveObservers);
287
288
  }
289
+ isObserving() {
290
+ return currentReactiveObserver === this;
291
+ }
292
+ }
293
+
294
+ /*
295
+ * Copyright (c) 2024, salesforce.com, inc.
296
+ * All rights reserved.
297
+ * SPDX-License-Identifier: MIT
298
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
299
+ */
300
+ /**
301
+ * This map keeps track of objects to signals. There is an assumption that the signal is strongly referenced
302
+ * on the object which allows the SignalTracker to be garbage collected along with the object.
303
+ */
304
+ const TargetToSignalTrackerMap = new WeakMap();
305
+ function getSignalTracker(target) {
306
+ let signalTracker = TargetToSignalTrackerMap.get(target);
307
+ if (shared.isUndefined(signalTracker)) {
308
+ signalTracker = new SignalTracker();
309
+ TargetToSignalTrackerMap.set(target, signalTracker);
310
+ }
311
+ return signalTracker;
312
+ }
313
+ function subscribeToSignal(target, signal, update) {
314
+ const signalTracker = getSignalTracker(target);
315
+ if (shared.isFalse(signalTracker.seen(signal))) {
316
+ signalTracker.subscribeToSignal(signal, update);
317
+ }
318
+ }
319
+ function unsubscribeFromSignals(target) {
320
+ if (TargetToSignalTrackerMap.has(target)) {
321
+ const signalTracker = getSignalTracker(target);
322
+ signalTracker.unsubscribeFromSignals();
323
+ signalTracker.reset();
324
+ }
325
+ }
326
+ /**
327
+ * This class is used to keep track of the signals associated to a given object.
328
+ * It is used to prevent the LWC engine from subscribing duplicate callbacks multiple times
329
+ * to the same signal. Additionally, it keeps track of all signal unsubscribe callbacks, handles invoking
330
+ * them when necessary and discarding them.
331
+ */
332
+ class SignalTracker {
333
+ constructor() {
334
+ this.signalToUnsubscribeMap = new Map();
335
+ }
336
+ seen(signal) {
337
+ return this.signalToUnsubscribeMap.has(signal);
338
+ }
339
+ subscribeToSignal(signal, update) {
340
+ try {
341
+ const unsubscribe = signal.subscribe(update);
342
+ if (shared.isFunction(unsubscribe)) {
343
+ // TODO [#3978]: Evaluate how we should handle the case when unsubscribe is not a function.
344
+ // Long term we should throw an error or log a warning.
345
+ this.signalToUnsubscribeMap.set(signal, unsubscribe);
346
+ }
347
+ }
348
+ catch (err) {
349
+ logWarnOnce(`Attempted to subscribe to an object that has the shape of a signal but received the following error: ${err?.stack ?? err}`);
350
+ }
351
+ }
352
+ unsubscribeFromSignals() {
353
+ try {
354
+ this.signalToUnsubscribeMap.forEach((unsubscribe) => unsubscribe());
355
+ }
356
+ catch (err) {
357
+ logWarnOnce(`Attempted to call a signal's unsubscribe callback but received the following error: ${err?.stack ?? err}`);
358
+ }
359
+ }
360
+ reset() {
361
+ this.signalToUnsubscribeMap.clear();
362
+ }
288
363
  }
289
364
 
290
365
  /*
@@ -306,10 +381,26 @@ function componentValueMutated(vm, key) {
306
381
  valueMutated(vm.component, key);
307
382
  }
308
383
  }
309
- function componentValueObserved(vm, key) {
384
+ function componentValueObserved(vm, key, target = {}) {
385
+ const { component, tro } = vm;
310
386
  // On the server side, we don't need mutation tracking. Skipping it improves performance.
311
387
  if (process.env.IS_BROWSER) {
312
- valueObserved(vm.component, key);
388
+ valueObserved(component, key);
389
+ }
390
+ // The portion of reactivity that's exposed to signals is to subscribe a callback to re-render the VM (templates).
391
+ // We check check the following to ensure re-render is subscribed at the correct time.
392
+ // 1. The template is currently being rendered (there is a template reactive observer)
393
+ // 2. There was a call to a getter to access the signal (happens during vnode generation)
394
+ if (lwcRuntimeFlags.ENABLE_EXPERIMENTAL_SIGNALS &&
395
+ shared.isObject(target) &&
396
+ !shared.isNull(target) &&
397
+ 'value' in target &&
398
+ 'subscribe' in target &&
399
+ shared.isFunction(target.subscribe) &&
400
+ // Only subscribe if a template is being rendered by the engine
401
+ tro.isObserving()) {
402
+ // Subscribe the template reactive observer's notify method, which will mark the vm as dirty and schedule hydration.
403
+ subscribeToSignal(component, target, tro.notify.bind(tro));
313
404
  }
314
405
  }
315
406
  function createReactiveObserver(callback) {
@@ -346,6 +437,7 @@ function addCallbackToNextTick(callback) {
346
437
  }
347
438
  }
348
439
  if (nextTickCallbackQueue.length === 0) {
440
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
349
441
  Promise.resolve().then(flushCallbackQueue);
350
442
  }
351
443
  shared.ArrayPush.call(nextTickCallbackQueue, callback);
@@ -427,7 +519,11 @@ function applyTemporaryCompilerV5SlotFix(data) {
427
519
  if (!shared.isUndefined(attrs)) {
428
520
  const { slot } = attrs;
429
521
  if (!shared.isUndefined(slot) && !shared.isNull(slot)) {
430
- return Object.assign(Object.assign({}, data), { attrs: cloneAndOmitKey(attrs, 'slot'), slotAssignment: String(slot) });
522
+ return {
523
+ ...data,
524
+ attrs: cloneAndOmitKey(attrs, 'slot'),
525
+ slotAssignment: String(slot),
526
+ };
431
527
  }
432
528
  }
433
529
  return data;
@@ -441,15 +537,20 @@ function applyTemporaryCompilerV5SlotFix(data) {
441
537
  */
442
538
  function resolveCircularModuleDependency(fn) {
443
539
  const module = fn();
444
- return (module === null || module === void 0 ? void 0 : module.__esModule) ? module.default : module;
540
+ return module?.__esModule ? module.default : module;
445
541
  }
446
542
  function isCircularModuleDependency(obj) {
447
543
  return shared.isFunction(obj) && shared.hasOwnProperty.call(obj, '__circular__');
448
544
  }
449
545
 
450
- var _a, _b;
451
- const instrumentDef = (_a = globalThis.__lwc_instrument_cmp_def) !== null && _a !== void 0 ? _a : shared.noop;
452
- const instrumentInstance = (_b = globalThis.__lwc_instrument_cmp_instance) !== null && _b !== void 0 ? _b : shared.noop;
546
+ /*
547
+ * Copyright (c) 2023, salesforce.com, inc.
548
+ * All rights reserved.
549
+ * SPDX-License-Identifier: MIT
550
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
551
+ */
552
+ const instrumentDef = globalThis.__lwc_instrument_cmp_def ?? shared.noop;
553
+ const instrumentInstance = globalThis.__lwc_instrument_cmp_instance ?? shared.noop;
453
554
 
454
555
  /*
455
556
  * Copyright (c) 2018, salesforce.com, inc.
@@ -1401,6 +1502,7 @@ function initGlobalStylesheet() {
1401
1502
  }
1402
1503
  return promise;
1403
1504
  });
1505
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
1404
1506
  Promise.all(promises).then((stylesheetTexts) => {
1405
1507
  // When replaceSync() is called, the entire contents of the constructable stylesheet are replaced
1406
1508
  // with the copied+concatenated styles. This means that any shadow root's adoptedStyleSheets that
@@ -1512,7 +1614,6 @@ const LightningElement = function () {
1512
1614
  const { assertInstanceOfHTMLElement } = vm.renderer;
1513
1615
  assertInstanceOfHTMLElement(vm.elm, `Component creation requires a DOM element to be associated to ${vm}.`);
1514
1616
  }
1515
- const component = this;
1516
1617
  shared.setPrototypeOf(elm, bridge.prototype);
1517
1618
  vm.component = this;
1518
1619
  // Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
@@ -1527,7 +1628,7 @@ const LightningElement = function () {
1527
1628
  }
1528
1629
  markLockerLiveObject(this);
1529
1630
  // Linking elm, shadow root and component with the VM.
1530
- associateVM(component, vm);
1631
+ associateVM(this, vm);
1531
1632
  associateVM(elm, vm);
1532
1633
  if (vm.renderMode === 1 /* RenderMode.Shadow */) {
1533
1634
  vm.renderRoot = doAttachShadow(vm);
@@ -1951,8 +2052,9 @@ function createObservedFieldPropertyDescriptor(key) {
1951
2052
  return {
1952
2053
  get() {
1953
2054
  const vm = getAssociatedVM(this);
1954
- componentValueObserved(vm, key);
1955
- return vm.cmpFields[key];
2055
+ const val = vm.cmpFields[key];
2056
+ componentValueObserved(vm, key, val);
2057
+ return val;
1956
2058
  },
1957
2059
  set(newValue) {
1958
2060
  const vm = getAssociatedVM(this);
@@ -2063,6 +2165,7 @@ function createConfigWatcher(component, configCallback, callbackWhenConfigIsRead
2063
2165
  if (hasPendingConfig === false) {
2064
2166
  hasPendingConfig = true;
2065
2167
  // collect new config in the micro-task
2168
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
2066
2169
  Promise.resolve().then(() => {
2067
2170
  hasPendingConfig = false;
2068
2171
  // resetting current reactive params
@@ -2205,6 +2308,7 @@ function installWireAdapters(vm) {
2205
2308
  connector.connect();
2206
2309
  if (!lwcRuntimeFlags.ENABLE_WIRE_SYNC_EMIT) {
2207
2310
  if (hasDynamicParams) {
2311
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
2208
2312
  Promise.resolve().then(computeConfigAndUpdate);
2209
2313
  return;
2210
2314
  }
@@ -2256,8 +2360,9 @@ function createPublicPropertyDescriptor(key) {
2256
2360
  }
2257
2361
  return;
2258
2362
  }
2259
- componentValueObserved(vm, key);
2260
- return vm.cmpProps[key];
2363
+ const val = vm.cmpProps[key];
2364
+ componentValueObserved(vm, key, val);
2365
+ return val;
2261
2366
  },
2262
2367
  set(newValue) {
2263
2368
  const vm = getAssociatedVM(this);
@@ -2330,8 +2435,9 @@ function internalTrackDecorator(key) {
2330
2435
  return {
2331
2436
  get() {
2332
2437
  const vm = getAssociatedVM(this);
2333
- componentValueObserved(vm, key);
2334
- return vm.cmpFields[key];
2438
+ const val = vm.cmpFields[key];
2439
+ componentValueObserved(vm, key, val);
2440
+ return val;
2335
2441
  },
2336
2442
  set(newValue) {
2337
2443
  const vm = getAssociatedVM(this);
@@ -3205,6 +3311,14 @@ function createComponentDef(Ctor) {
3205
3311
  let shadowSupportMode = superDef.shadowSupportMode;
3206
3312
  if (!shared.isUndefined(ctorShadowSupportMode)) {
3207
3313
  shadowSupportMode = ctorShadowSupportMode;
3314
+ if (isReportingEnabled() &&
3315
+ (shadowSupportMode === "any" /* ShadowSupportMode.Any */ ||
3316
+ shadowSupportMode === "native" /* ShadowSupportMode.Native */)) {
3317
+ report("ShadowSupportModeUsage" /* ReportingEventId.ShadowSupportModeUsage */, {
3318
+ tagName: Ctor.name,
3319
+ mode: shadowSupportMode,
3320
+ });
3321
+ }
3208
3322
  }
3209
3323
  let renderMode = superDef.renderMode;
3210
3324
  if (!shared.isUndefined(ctorRenderMode)) {
@@ -3524,7 +3638,7 @@ function getNearestShadowComponent(vm) {
3524
3638
  function getScopeTokenClass(owner, legacy) {
3525
3639
  const { cmpTemplate, context } = owner;
3526
3640
  return ((context.hasScopedStyles &&
3527
- (legacy ? cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.legacyStylesheetToken : cmpTemplate === null || cmpTemplate === void 0 ? void 0 : cmpTemplate.stylesheetToken)) ||
3641
+ (legacy ? cmpTemplate?.legacyStylesheetToken : cmpTemplate?.stylesheetToken)) ||
3528
3642
  null);
3529
3643
  }
3530
3644
  /**
@@ -3651,7 +3765,7 @@ function patchAttributes(oldVnode, vnode, renderer) {
3651
3765
  }
3652
3766
  function patchSlotAssignment(oldVnode, vnode, renderer) {
3653
3767
  const { slotAssignment } = vnode;
3654
- if ((oldVnode === null || oldVnode === void 0 ? void 0 : oldVnode.slotAssignment) === slotAssignment) {
3768
+ if (oldVnode?.slotAssignment === slotAssignment) {
3655
3769
  return;
3656
3770
  }
3657
3771
  const { elm } = vnode;
@@ -3728,6 +3842,8 @@ function getMapFromClassName(className) {
3728
3842
  return EmptyObject;
3729
3843
  }
3730
3844
  // computed class names must be string
3845
+ // This will throw if className is a symbol or null-prototype object
3846
+ // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
3731
3847
  className = shared.isString(className) ? className : className + '';
3732
3848
  let map = classNameToClassMap[className];
3733
3849
  if (map) {
@@ -3808,9 +3924,8 @@ function patchStyleAttribute(oldVnode, vnode, renderer) {
3808
3924
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3809
3925
  */
3810
3926
  function applyEventListeners(vnode, renderer) {
3811
- var _a;
3812
3927
  const { elm } = vnode;
3813
- const on = (_a = vnode.data) === null || _a === void 0 ? void 0 : _a.on;
3928
+ const on = vnode.data?.on;
3814
3929
  if (shared.isUndefined(on)) {
3815
3930
  return;
3816
3931
  }
@@ -3945,7 +4060,7 @@ function traverseAndSetElements(root, parts, renderer) {
3945
4060
  * @param renderer - the renderer to use
3946
4061
  * @param mount - true this is a first (mount) render as opposed to a subsequent (patch) render
3947
4062
  */
3948
- function applyStaticParts(root, vnode, renderer, mount) {
4063
+ function mountStaticParts(root, vnode, renderer) {
3949
4064
  // On the server, we don't support ref (because it relies on renderedCallback), nor do we
3950
4065
  // support event listeners (no interactivity), so traversing parts makes no sense
3951
4066
  if (!process.env.IS_BROWSER) {
@@ -3955,20 +4070,46 @@ function applyStaticParts(root, vnode, renderer, mount) {
3955
4070
  if (shared.isUndefined(parts)) {
3956
4071
  return;
3957
4072
  }
3958
- // This adds `part.elm` to each `part`. We have to do this on every mount/patch because the `parts`
4073
+ // This adds `part.elm` to each `part`. We have to do this on every mount because the `parts`
3959
4074
  // array is recreated from scratch every time, so each `part.elm` is now undefined.
3960
- // TODO [#3800]: avoid calling traverseAndSetElements on every re-render
3961
4075
  traverseAndSetElements(root, parts, renderer);
3962
4076
  // Currently only event listeners and refs are supported for static vnodes
3963
4077
  for (const part of parts) {
3964
- if (mount) {
3965
- // Event listeners only need to be applied once when mounting
3966
- applyEventListeners(part, renderer);
3967
- }
4078
+ // Event listeners only need to be applied once when mounting
4079
+ applyEventListeners(part, renderer);
3968
4080
  // Refs must be updated after every render due to refVNodes getting reset before every render
3969
4081
  applyRefs(part, owner);
3970
4082
  }
3971
4083
  }
4084
+ /**
4085
+ * Mounts elements to the newly generated VStatic node
4086
+ *
4087
+ * @param n1 - the previous VStatic vnode
4088
+ * @param n2 - the current VStatic vnode
4089
+ */
4090
+ function patchStaticParts(n1, n2) {
4091
+ // On the server, we don't support ref (because it relies on renderedCallback), nor do we
4092
+ // support event listeners (no interactivity), so traversing parts makes no sense
4093
+ if (!process.env.IS_BROWSER) {
4094
+ return;
4095
+ }
4096
+ const { parts: currParts, owner: currPartsOwner } = n2;
4097
+ if (shared.isUndefined(currParts)) {
4098
+ return;
4099
+ }
4100
+ const { parts: prevParts } = n1;
4101
+ if (process.env.NODE_ENV !== 'production') {
4102
+ shared.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.');
4103
+ }
4104
+ for (let i = 0; i < currParts.length; i++) {
4105
+ const part = currParts[i];
4106
+ // Patch only occurs if the vnode is newly generated, which means the part.elm is always undefined
4107
+ // Since the vnode and elements are the same we can safely assume that prevParts[i].elm is defined.
4108
+ part.elm = prevParts[i].elm;
4109
+ // Refs must be updated after every render due to refVNodes getting reset before every render
4110
+ applyRefs(part, currPartsOwner);
4111
+ }
4112
+ }
3972
4113
 
3973
4114
  /*
3974
4115
  * Copyright (c) 2018, salesforce.com, inc.
@@ -3985,7 +4126,6 @@ function patchChildren(c1, c2, parent, renderer) {
3985
4126
  }
3986
4127
  }
3987
4128
  function patch(n1, n2, parent, renderer) {
3988
- var _a, _b;
3989
4129
  if (n1 === n2) {
3990
4130
  return;
3991
4131
  }
@@ -4018,15 +4158,14 @@ function patch(n1, n2, parent, renderer) {
4018
4158
  patchFragment(n1, n2, parent, renderer);
4019
4159
  break;
4020
4160
  case 2 /* VNodeType.Element */:
4021
- patchElement(n1, n2, (_a = n2.data.renderer) !== null && _a !== void 0 ? _a : renderer);
4161
+ patchElement(n1, n2, n2.data.renderer ?? renderer);
4022
4162
  break;
4023
4163
  case 3 /* VNodeType.CustomElement */:
4024
- patchCustomElement(n1, n2, parent, (_b = n2.data.renderer) !== null && _b !== void 0 ? _b : renderer);
4164
+ patchCustomElement(n1, n2, parent, n2.data.renderer ?? renderer);
4025
4165
  break;
4026
4166
  }
4027
4167
  }
4028
4168
  function mount(node, parent, renderer, anchor) {
4029
- var _a, _b;
4030
4169
  switch (node.type) {
4031
4170
  case 0 /* VNodeType.Text */:
4032
4171
  // VText has no special capability, fallback to the owner's renderer
@@ -4045,11 +4184,11 @@ function mount(node, parent, renderer, anchor) {
4045
4184
  break;
4046
4185
  case 2 /* VNodeType.Element */:
4047
4186
  // If the vnode data has a renderer override use it, else fallback to owner's renderer
4048
- mountElement(node, parent, anchor, (_a = node.data.renderer) !== null && _a !== void 0 ? _a : renderer);
4187
+ mountElement(node, parent, anchor, node.data.renderer ?? renderer);
4049
4188
  break;
4050
4189
  case 3 /* VNodeType.CustomElement */:
4051
4190
  // If the vnode data has a renderer override use it, else fallback to owner's renderer
4052
- mountCustomElement(node, parent, anchor, (_b = node.data.renderer) !== null && _b !== void 0 ? _b : renderer);
4191
+ mountCustomElement(node, parent, anchor, node.data.renderer ?? renderer);
4053
4192
  break;
4054
4193
  }
4055
4194
  }
@@ -4111,11 +4250,11 @@ function mountElement(vnode, parent, anchor, renderer) {
4111
4250
  mountVNodes(vnode.children, elm, renderer, null);
4112
4251
  }
4113
4252
  function patchStatic(n1, n2, renderer) {
4114
- const elm = (n2.elm = n1.elm);
4253
+ n2.elm = n1.elm;
4115
4254
  // slotAssignments can only apply to the top level element, never to a static part.
4116
4255
  patchSlotAssignment(n1, n2, renderer);
4117
4256
  // The `refs` object is blown away in every re-render, so we always need to re-apply them
4118
- applyStaticParts(elm, n2, renderer, false);
4257
+ patchStaticParts(n1, n2);
4119
4258
  }
4120
4259
  function patchElement(n1, n2, renderer) {
4121
4260
  const elm = (n2.elm = n1.elm);
@@ -4138,7 +4277,7 @@ function mountStatic(vnode, parent, anchor, renderer) {
4138
4277
  // slotAssignments can only apply to the top level element, never to a static part.
4139
4278
  patchSlotAssignment(null, vnode, renderer);
4140
4279
  insertNode(elm, parent, anchor, renderer);
4141
- applyStaticParts(elm, vnode, renderer, true);
4280
+ mountStaticParts(elm, vnode, renderer);
4142
4281
  }
4143
4282
  function mountCustomElement(vnode, parent, anchor, renderer) {
4144
4283
  const { sel, owner, ctor } = vnode;
@@ -4400,17 +4539,15 @@ function applyStyleScoping(elm, owner, renderer) {
4400
4539
  }
4401
4540
  }
4402
4541
  function applyDomManual(elm, vnode) {
4403
- var _a;
4404
4542
  const { owner, data: { context }, } = vnode;
4405
- 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 */) {
4543
+ if (owner.shadowMode === 1 /* ShadowMode.Synthetic */ && context?.lwc?.dom === "manual" /* LwcDomMode.Manual */) {
4406
4544
  elm.$domManual$ = true;
4407
4545
  }
4408
4546
  }
4409
4547
  function applyElementRestrictions(elm, vnode) {
4410
- var _a, _b;
4411
4548
  if (process.env.NODE_ENV !== 'production') {
4412
4549
  const isSynthetic = vnode.owner.shadowMode === 1 /* ShadowMode.Synthetic */;
4413
- 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 */;
4550
+ const isPortal = vnode.type === 2 /* VNodeType.Element */ && vnode.data.context?.lwc?.dom === "manual" /* LwcDomMode.Manual */;
4414
4551
  const isLight = vnode.owner.renderMode === 0 /* RenderMode.Light */;
4415
4552
  patchElementWithRestrictions(elm, {
4416
4553
  isPortal,
@@ -4517,7 +4654,6 @@ function createViewModelHook(elm, vnode, renderer) {
4517
4654
  return vm;
4518
4655
  }
4519
4656
  function allocateInSlot(vm, children, owner) {
4520
- var _a;
4521
4657
  const { cmpSlots: { slotAssignments: oldSlotsMapping }, } = vm;
4522
4658
  const cmpSlotsMapping = shared.create(null);
4523
4659
  // Collect all slots into cmpSlotsMapping
@@ -4528,7 +4664,7 @@ function allocateInSlot(vm, children, owner) {
4528
4664
  }
4529
4665
  let slotName = '';
4530
4666
  if (isVBaseElement(vnode) || isVStatic(vnode)) {
4531
- slotName = (_a = vnode.slotAssignment) !== null && _a !== void 0 ? _a : '';
4667
+ slotName = vnode.slotAssignment ?? '';
4532
4668
  }
4533
4669
  else if (isVScopedSlotFragment(vnode)) {
4534
4670
  slotName = vnode.slotName;
@@ -4537,6 +4673,7 @@ function allocateInSlot(vm, children, owner) {
4537
4673
  // but elm.setAttribute('slot', Symbol(1)) is an error.
4538
4674
  // the following line also throws same error for symbols
4539
4675
  // Similar for Object.create(null)
4676
+ // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
4540
4677
  const normalizedSlotName = '' + slotName;
4541
4678
  const vnodes = (cmpSlotsMapping[normalizedSlotName] =
4542
4679
  cmpSlotsMapping[normalizedSlotName] || []);
@@ -4934,11 +5071,11 @@ function s(slotName, data, children, slotset) {
4934
5071
  // to the vnode because the current way the diffing algo works, it will replace the original reference
4935
5072
  // to the host element with a new one. This means the new element will be mounted and immediately unmounted.
4936
5073
  // Creating a copy of the vnode to preserve a reference to the previous host element.
4937
- clonedVNode = Object.assign(Object.assign({}, vnode), { slotAssignment: data.slotAssignment });
5074
+ clonedVNode = { ...vnode, slotAssignment: data.slotAssignment };
4938
5075
  }
4939
5076
  // If the slot content is standard type, the content is static, no additional
4940
5077
  // processing needed on the vnode
4941
- shared.ArrayPush.call(newChildren, clonedVNode !== null && clonedVNode !== void 0 ? clonedVNode : vnode);
5078
+ shared.ArrayPush.call(newChildren, clonedVNode ?? vnode);
4942
5079
  }
4943
5080
  }
4944
5081
  }
@@ -5397,7 +5534,7 @@ function logGlobalOperationStart(opId, vm) {
5397
5534
  start(markName);
5398
5535
  }
5399
5536
  if (isProfilerEnabled) {
5400
- 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);
5537
+ currentDispatcher(opId, 0 /* Phase.Start */, vm?.tagName, vm?.idx, vm?.renderMode, vm?.shadowMode);
5401
5538
  }
5402
5539
  }
5403
5540
  function logGlobalOperationEnd(opId, vm) {
@@ -5407,7 +5544,7 @@ function logGlobalOperationEnd(opId, vm) {
5407
5544
  end(opName, markName);
5408
5545
  }
5409
5546
  if (isProfilerEnabled) {
5410
- 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);
5547
+ currentDispatcher(opId, 1 /* Phase.Stop */, vm?.tagName, vm?.idx, vm?.renderMode, vm?.shadowMode);
5411
5548
  }
5412
5549
  }
5413
5550
 
@@ -5429,7 +5566,6 @@ function validateSlots(vm) {
5429
5566
  assertNotProd(); // this method should never leak to prod
5430
5567
  const { cmpSlots } = vm;
5431
5568
  for (const slotName in cmpSlots.slotAssignments) {
5432
- // eslint-disable-next-line @lwc/lwc-internal/no-production-assert
5433
5569
  shared.assert.isTrue(shared.isArray(cmpSlots.slotAssignments[slotName]), `Slots can only be set to an array, instead received ${shared.toString(cmpSlots.slotAssignments[slotName])} for slot "${slotName}" in ${vm}.`);
5434
5570
  }
5435
5571
  }
@@ -5727,16 +5863,14 @@ Ctor, metadata) {
5727
5863
  return Ctor;
5728
5864
  }
5729
5865
  function getComponentRegisteredTemplate(Ctor) {
5730
- var _a;
5731
- return (_a = registeredComponentMap.get(Ctor)) === null || _a === void 0 ? void 0 : _a.tmpl;
5866
+ return registeredComponentMap.get(Ctor)?.tmpl;
5732
5867
  }
5733
5868
  function getComponentRegisteredName(Ctor) {
5734
- var _a;
5735
- return (_a = registeredComponentMap.get(Ctor)) === null || _a === void 0 ? void 0 : _a.sel;
5869
+ return registeredComponentMap.get(Ctor)?.sel;
5736
5870
  }
5737
5871
  function getComponentAPIVersion(Ctor) {
5738
5872
  const metadata = registeredComponentMap.get(Ctor);
5739
- const apiVersion = metadata === null || metadata === void 0 ? void 0 : metadata.apiVersion;
5873
+ const apiVersion = metadata?.apiVersion;
5740
5874
  if (shared.isUndefined(apiVersion)) {
5741
5875
  // This should only occur in our Karma tests; in practice every component
5742
5876
  // is registered, and so this code path should not get hit. But to be safe,
@@ -5754,11 +5888,27 @@ function getTemplateReactiveObserver(vm) {
5754
5888
  }
5755
5889
  });
5756
5890
  }
5891
+ function resetTemplateObserverAndUnsubscribe(vm) {
5892
+ const { tro, component } = vm;
5893
+ tro.reset();
5894
+ // Unsubscribe every time the template reactive observer is reset.
5895
+ if (lwcRuntimeFlags.ENABLE_EXPERIMENTAL_SIGNALS) {
5896
+ unsubscribeFromSignals(component);
5897
+ }
5898
+ }
5757
5899
  function renderComponent(vm) {
5758
5900
  if (process.env.NODE_ENV !== 'production') {
5759
5901
  shared.assert.invariant(vm.isDirty, `${vm} is not dirty.`);
5760
5902
  }
5761
- vm.tro.reset();
5903
+ // The engine should only hold a subscription to a signal if it is rendered in the template.
5904
+ // Because of the potential presence of conditional rendering logic, we unsubscribe on each render
5905
+ // in the scenario where it is present in one condition but not the other.
5906
+ // For example:
5907
+ // 1. There is an lwc:if=true conditional where the signal is present on the template.
5908
+ // 2. The lwc:if changes to false and the signal is no longer present on the template.
5909
+ // If the signal is still subscribed to, the template will re-render when it receives a notification
5910
+ // from the signal, even though we won't be using the new value.
5911
+ resetTemplateObserverAndUnsubscribe(vm);
5762
5912
  const vnodes = invokeComponentRenderMethod(vm);
5763
5913
  vm.isDirty = false;
5764
5914
  vm.isScheduled = false;
@@ -5833,9 +5983,8 @@ function appendVM(vm) {
5833
5983
  function resetComponentStateWhenRemoved(vm) {
5834
5984
  const { state } = vm;
5835
5985
  if (state !== 2 /* VMState.disconnected */) {
5836
- const { tro } = vm;
5837
5986
  // Making sure that any observing record will not trigger the rehydrated on this vm
5838
- tro.reset();
5987
+ resetTemplateObserverAndUnsubscribe(vm);
5839
5988
  runDisconnectedCallback(vm);
5840
5989
  // Spec: https://dom.spec.whatwg.org/#concept-node-remove (step 14-15)
5841
5990
  runChildNodesDisconnectedCallback(vm);
@@ -6148,7 +6297,7 @@ function flushRehydrationQueue() {
6148
6297
  logGlobalOperationEnd(8 /* OperationId.GlobalRehydrate */);
6149
6298
  // re-throwing the original error will break the current tick, but since the next tick is
6150
6299
  // already scheduled, it should continue patching the rest.
6151
- throw error; // eslint-disable-line no-unsafe-finally
6300
+ throw error;
6152
6301
  }
6153
6302
  }
6154
6303
  logGlobalOperationEnd(8 /* OperationId.GlobalRehydrate */);
@@ -6621,7 +6770,7 @@ function checkAndReportViolation(elm, prop, isSetter, setValue) {
6621
6770
  setValueType = shared.isNull(setValue) ? 'null' : typeof setValue;
6622
6771
  }
6623
6772
  report("NonStandardAriaReflection" /* ReportingEventId.NonStandardAriaReflection */, {
6624
- tagName: vm === null || vm === void 0 ? void 0 : vm.tagName,
6773
+ tagName: vm?.tagName,
6625
6774
  propertyName: prop,
6626
6775
  isSetter,
6627
6776
  setValueType,
@@ -6699,7 +6848,6 @@ function hydrateVM(vm) {
6699
6848
  runRenderedCallback(vm);
6700
6849
  }
6701
6850
  function hydrateNode(node, vnode, renderer) {
6702
- var _a, _b;
6703
6851
  let hydratedNode;
6704
6852
  switch (vnode.type) {
6705
6853
  case 0 /* VNodeType.Text */:
@@ -6719,10 +6867,10 @@ function hydrateNode(node, vnode, renderer) {
6719
6867
  hydratedNode = hydrateFragment(node, vnode, renderer);
6720
6868
  break;
6721
6869
  case 2 /* VNodeType.Element */:
6722
- hydratedNode = hydrateElement(node, vnode, (_a = vnode.data.renderer) !== null && _a !== void 0 ? _a : renderer);
6870
+ hydratedNode = hydrateElement(node, vnode, vnode.data.renderer ?? renderer);
6723
6871
  break;
6724
6872
  case 3 /* VNodeType.CustomElement */:
6725
- hydratedNode = hydrateCustomElement(node, vnode, (_b = vnode.data.renderer) !== null && _b !== void 0 ? _b : renderer);
6873
+ hydratedNode = hydrateCustomElement(node, vnode, vnode.data.renderer ?? renderer);
6726
6874
  break;
6727
6875
  }
6728
6876
  return renderer.nextSibling(hydratedNode);
@@ -6765,7 +6913,6 @@ function getValidationPredicate(optOutStaticProp) {
6765
6913
  return (_attrName) => true;
6766
6914
  }
6767
6915
  function hydrateText(node, vnode, renderer) {
6768
- var _a;
6769
6916
  if (!hasCorrectNodeType(vnode, node, 3 /* EnvNodeTypes.TEXT */, renderer)) {
6770
6917
  return handleMismatch(node, vnode, renderer);
6771
6918
  }
@@ -6775,12 +6922,11 @@ function hydrateText(node, vnode, renderer) {
6775
6922
  }
6776
6923
  }
6777
6924
  const { setText } = renderer;
6778
- setText(node, (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
6925
+ setText(node, vnode.text ?? null);
6779
6926
  vnode.elm = node;
6780
6927
  return node;
6781
6928
  }
6782
6929
  function hydrateComment(node, vnode, renderer) {
6783
- var _a;
6784
6930
  if (!hasCorrectNodeType(vnode, node, 8 /* EnvNodeTypes.COMMENT */, renderer)) {
6785
6931
  return handleMismatch(node, vnode, renderer);
6786
6932
  }
@@ -6792,7 +6938,7 @@ function hydrateComment(node, vnode, renderer) {
6792
6938
  }
6793
6939
  }
6794
6940
  const { setProperty } = renderer;
6795
- setProperty(node, NODE_VALUE_PROP, (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
6941
+ setProperty(node, NODE_VALUE_PROP, vnode.text ?? null);
6796
6942
  vnode.elm = node;
6797
6943
  return node;
6798
6944
  }
@@ -6802,7 +6948,7 @@ function hydrateStaticElement(elm, vnode, renderer) {
6802
6948
  return handleMismatch(elm, vnode, renderer);
6803
6949
  }
6804
6950
  vnode.elm = elm;
6805
- applyStaticParts(elm, vnode, renderer, true);
6951
+ mountStaticParts(elm, vnode, renderer);
6806
6952
  return elm;
6807
6953
  }
6808
6954
  function hydrateFragment(elm, vnode, renderer) {
@@ -6827,7 +6973,10 @@ function hydrateElement(elm, vnode, renderer) {
6827
6973
  if (!shared.isUndefined(props) && !shared.isUndefined(props.innerHTML)) {
6828
6974
  if (getProperty(elm, 'innerHTML') === props.innerHTML) {
6829
6975
  // Do a shallow clone since VNodeData may be shared across VNodes due to hoist optimization
6830
- vnode.data = Object.assign(Object.assign({}, vnode.data), { props: cloneAndOmitKey(props, 'innerHTML') });
6976
+ vnode.data = {
6977
+ ...vnode.data,
6978
+ props: cloneAndOmitKey(props, 'innerHTML'),
6979
+ };
6831
6980
  }
6832
6981
  else {
6833
6982
  if (process.env.NODE_ENV !== 'production') {
@@ -7039,7 +7188,11 @@ function validateClassAttr(vnode, elm, renderer) {
7039
7188
  className = shared.ArrayJoin.call(classNames, ' ');
7040
7189
  }
7041
7190
  else if (!shared.isUndefined(classMap)) {
7042
- classMap = Object.assign(Object.assign(Object.assign({}, classMap), (!shared.isNull(scopedToken) ? { [scopedToken]: true } : {})), (!shared.isNull(stylesheetTokenHost) ? { [stylesheetTokenHost]: true } : {}));
7191
+ classMap = {
7192
+ ...classMap,
7193
+ ...(!shared.isNull(scopedToken) ? { [scopedToken]: true } : {}),
7194
+ ...(!shared.isNull(stylesheetTokenHost) ? { [stylesheetTokenHost]: true } : {}),
7195
+ };
7043
7196
  }
7044
7197
  else {
7045
7198
  // The order of the className should be scopedToken stylesheetTokenHost
@@ -7475,5 +7628,5 @@ exports.swapTemplate = swapTemplate;
7475
7628
  exports.track = track;
7476
7629
  exports.unwrap = unwrap;
7477
7630
  exports.wire = wire;
7478
- /** version: 6.1.1 */
7631
+ /** version: 6.2.0 */
7479
7632
  //# sourceMappingURL=index.cjs.js.map