@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.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);
@@ -413,6 +505,29 @@ function assertNotProd() {
413
505
  throw new ReferenceError();
414
506
  }
415
507
  }
508
+ // Temporary fix for when the LWC v5 compiler is used in conjunction with a v6+ engine
509
+ // The old compiler format used the "slot" attribute in the `data` bag, whereas the new
510
+ // format uses the special `slotAssignment` key.
511
+ // This should be removed when the LWC v5 compiler is not used anywhere where it could be mismatched
512
+ // with another LWC engine version.
513
+ // TODO [#3974]: remove temporary logic to support v5 compiler + v6+ engine
514
+ function applyTemporaryCompilerV5SlotFix(data) {
515
+ if (lwcRuntimeFlags.DISABLE_TEMPORARY_V5_COMPILER_SUPPORT) {
516
+ return data;
517
+ }
518
+ const { attrs } = data;
519
+ if (!shared.isUndefined(attrs)) {
520
+ const { slot } = attrs;
521
+ if (!shared.isUndefined(slot) && !shared.isNull(slot)) {
522
+ return {
523
+ ...data,
524
+ attrs: cloneAndOmitKey(attrs, 'slot'),
525
+ slotAssignment: String(slot),
526
+ };
527
+ }
528
+ }
529
+ return data;
530
+ }
416
531
 
417
532
  /*
418
533
  * Copyright (c) 2020, salesforce.com, inc.
@@ -422,15 +537,20 @@ function assertNotProd() {
422
537
  */
423
538
  function resolveCircularModuleDependency(fn) {
424
539
  const module = fn();
425
- return (module === null || module === void 0 ? void 0 : module.__esModule) ? module.default : module;
540
+ return module?.__esModule ? module.default : module;
426
541
  }
427
542
  function isCircularModuleDependency(obj) {
428
543
  return shared.isFunction(obj) && shared.hasOwnProperty.call(obj, '__circular__');
429
544
  }
430
545
 
431
- var _a, _b;
432
- const instrumentDef = (_a = globalThis.__lwc_instrument_cmp_def) !== null && _a !== void 0 ? _a : shared.noop;
433
- 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;
434
554
 
435
555
  /*
436
556
  * Copyright (c) 2018, salesforce.com, inc.
@@ -1382,6 +1502,7 @@ function initGlobalStylesheet() {
1382
1502
  }
1383
1503
  return promise;
1384
1504
  });
1505
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
1385
1506
  Promise.all(promises).then((stylesheetTexts) => {
1386
1507
  // When replaceSync() is called, the entire contents of the constructable stylesheet are replaced
1387
1508
  // with the copied+concatenated styles. This means that any shadow root's adoptedStyleSheets that
@@ -1493,7 +1614,6 @@ const LightningElement = function () {
1493
1614
  const { assertInstanceOfHTMLElement } = vm.renderer;
1494
1615
  assertInstanceOfHTMLElement(vm.elm, `Component creation requires a DOM element to be associated to ${vm}.`);
1495
1616
  }
1496
- const component = this;
1497
1617
  shared.setPrototypeOf(elm, bridge.prototype);
1498
1618
  vm.component = this;
1499
1619
  // Locker hooks assignment. When the LWC engine run with Locker, Locker intercepts all the new
@@ -1508,7 +1628,7 @@ const LightningElement = function () {
1508
1628
  }
1509
1629
  markLockerLiveObject(this);
1510
1630
  // Linking elm, shadow root and component with the VM.
1511
- associateVM(component, vm);
1631
+ associateVM(this, vm);
1512
1632
  associateVM(elm, vm);
1513
1633
  if (vm.renderMode === 1 /* RenderMode.Shadow */) {
1514
1634
  vm.renderRoot = doAttachShadow(vm);
@@ -1932,8 +2052,9 @@ function createObservedFieldPropertyDescriptor(key) {
1932
2052
  return {
1933
2053
  get() {
1934
2054
  const vm = getAssociatedVM(this);
1935
- componentValueObserved(vm, key);
1936
- return vm.cmpFields[key];
2055
+ const val = vm.cmpFields[key];
2056
+ componentValueObserved(vm, key, val);
2057
+ return val;
1937
2058
  },
1938
2059
  set(newValue) {
1939
2060
  const vm = getAssociatedVM(this);
@@ -2044,6 +2165,7 @@ function createConfigWatcher(component, configCallback, callbackWhenConfigIsRead
2044
2165
  if (hasPendingConfig === false) {
2045
2166
  hasPendingConfig = true;
2046
2167
  // collect new config in the micro-task
2168
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
2047
2169
  Promise.resolve().then(() => {
2048
2170
  hasPendingConfig = false;
2049
2171
  // resetting current reactive params
@@ -2186,6 +2308,7 @@ function installWireAdapters(vm) {
2186
2308
  connector.connect();
2187
2309
  if (!lwcRuntimeFlags.ENABLE_WIRE_SYNC_EMIT) {
2188
2310
  if (hasDynamicParams) {
2311
+ // eslint-disable-next-line @typescript-eslint/no-floating-promises
2189
2312
  Promise.resolve().then(computeConfigAndUpdate);
2190
2313
  return;
2191
2314
  }
@@ -2237,8 +2360,9 @@ function createPublicPropertyDescriptor(key) {
2237
2360
  }
2238
2361
  return;
2239
2362
  }
2240
- componentValueObserved(vm, key);
2241
- return vm.cmpProps[key];
2363
+ const val = vm.cmpProps[key];
2364
+ componentValueObserved(vm, key, val);
2365
+ return val;
2242
2366
  },
2243
2367
  set(newValue) {
2244
2368
  const vm = getAssociatedVM(this);
@@ -2311,8 +2435,9 @@ function internalTrackDecorator(key) {
2311
2435
  return {
2312
2436
  get() {
2313
2437
  const vm = getAssociatedVM(this);
2314
- componentValueObserved(vm, key);
2315
- return vm.cmpFields[key];
2438
+ const val = vm.cmpFields[key];
2439
+ componentValueObserved(vm, key, val);
2440
+ return val;
2316
2441
  },
2317
2442
  set(newValue) {
2318
2443
  const vm = getAssociatedVM(this);
@@ -3147,10 +3272,15 @@ function createComponentDef(Ctor) {
3147
3272
  logError(`Missing ${ctorName}.constructor, ${ctorName} should have a "constructor" property.`);
3148
3273
  }
3149
3274
  if (!shared.isUndefined(ctorShadowSupportMode) &&
3275
+ ctorShadowSupportMode !== "any" /* ShadowSupportMode.Any */ &&
3150
3276
  ctorShadowSupportMode !== "reset" /* ShadowSupportMode.Default */ &&
3151
3277
  ctorShadowSupportMode !== "native" /* ShadowSupportMode.Native */) {
3152
3278
  logError(`Invalid value for static property shadowSupportMode: '${ctorShadowSupportMode}'`);
3153
3279
  }
3280
+ // TODO [#3971]: Completely remove shadowSupportMode "any"
3281
+ if (ctorShadowSupportMode === "any" /* ShadowSupportMode.Any */) {
3282
+ logWarn(`Invalid value 'any' for static property shadowSupportMode. 'any' is deprecated and will be removed in a future release--use 'native' instead.`);
3283
+ }
3154
3284
  if (!shared.isUndefined(ctorRenderMode) &&
3155
3285
  ctorRenderMode !== 'light' &&
3156
3286
  ctorRenderMode !== 'shadow') {
@@ -3181,6 +3311,14 @@ function createComponentDef(Ctor) {
3181
3311
  let shadowSupportMode = superDef.shadowSupportMode;
3182
3312
  if (!shared.isUndefined(ctorShadowSupportMode)) {
3183
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
+ }
3184
3322
  }
3185
3323
  let renderMode = superDef.renderMode;
3186
3324
  if (!shared.isUndefined(ctorRenderMode)) {
@@ -3500,7 +3638,7 @@ function getNearestShadowComponent(vm) {
3500
3638
  function getScopeTokenClass(owner, legacy) {
3501
3639
  const { cmpTemplate, context } = owner;
3502
3640
  return ((context.hasScopedStyles &&
3503
- (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)) ||
3504
3642
  null);
3505
3643
  }
3506
3644
  /**
@@ -3627,7 +3765,7 @@ function patchAttributes(oldVnode, vnode, renderer) {
3627
3765
  }
3628
3766
  function patchSlotAssignment(oldVnode, vnode, renderer) {
3629
3767
  const { slotAssignment } = vnode;
3630
- if ((oldVnode === null || oldVnode === void 0 ? void 0 : oldVnode.slotAssignment) === slotAssignment) {
3768
+ if (oldVnode?.slotAssignment === slotAssignment) {
3631
3769
  return;
3632
3770
  }
3633
3771
  const { elm } = vnode;
@@ -3704,6 +3842,8 @@ function getMapFromClassName(className) {
3704
3842
  return EmptyObject;
3705
3843
  }
3706
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
3707
3847
  className = shared.isString(className) ? className : className + '';
3708
3848
  let map = classNameToClassMap[className];
3709
3849
  if (map) {
@@ -3784,9 +3924,8 @@ function patchStyleAttribute(oldVnode, vnode, renderer) {
3784
3924
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3785
3925
  */
3786
3926
  function applyEventListeners(vnode, renderer) {
3787
- var _a;
3788
3927
  const { elm } = vnode;
3789
- const on = (_a = vnode.data) === null || _a === void 0 ? void 0 : _a.on;
3928
+ const on = vnode.data?.on;
3790
3929
  if (shared.isUndefined(on)) {
3791
3930
  return;
3792
3931
  }
@@ -3921,7 +4060,7 @@ function traverseAndSetElements(root, parts, renderer) {
3921
4060
  * @param renderer - the renderer to use
3922
4061
  * @param mount - true this is a first (mount) render as opposed to a subsequent (patch) render
3923
4062
  */
3924
- function applyStaticParts(root, vnode, renderer, mount) {
4063
+ function mountStaticParts(root, vnode, renderer) {
3925
4064
  // On the server, we don't support ref (because it relies on renderedCallback), nor do we
3926
4065
  // support event listeners (no interactivity), so traversing parts makes no sense
3927
4066
  if (!process.env.IS_BROWSER) {
@@ -3931,20 +4070,46 @@ function applyStaticParts(root, vnode, renderer, mount) {
3931
4070
  if (shared.isUndefined(parts)) {
3932
4071
  return;
3933
4072
  }
3934
- // 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`
3935
4074
  // array is recreated from scratch every time, so each `part.elm` is now undefined.
3936
- // TODO [#3800]: avoid calling traverseAndSetElements on every re-render
3937
4075
  traverseAndSetElements(root, parts, renderer);
3938
4076
  // Currently only event listeners and refs are supported for static vnodes
3939
4077
  for (const part of parts) {
3940
- if (mount) {
3941
- // Event listeners only need to be applied once when mounting
3942
- applyEventListeners(part, renderer);
3943
- }
4078
+ // Event listeners only need to be applied once when mounting
4079
+ applyEventListeners(part, renderer);
3944
4080
  // Refs must be updated after every render due to refVNodes getting reset before every render
3945
4081
  applyRefs(part, owner);
3946
4082
  }
3947
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
+ }
3948
4113
 
3949
4114
  /*
3950
4115
  * Copyright (c) 2018, salesforce.com, inc.
@@ -3961,7 +4126,6 @@ function patchChildren(c1, c2, parent, renderer) {
3961
4126
  }
3962
4127
  }
3963
4128
  function patch(n1, n2, parent, renderer) {
3964
- var _a, _b;
3965
4129
  if (n1 === n2) {
3966
4130
  return;
3967
4131
  }
@@ -3994,15 +4158,14 @@ function patch(n1, n2, parent, renderer) {
3994
4158
  patchFragment(n1, n2, parent, renderer);
3995
4159
  break;
3996
4160
  case 2 /* VNodeType.Element */:
3997
- patchElement(n1, n2, (_a = n2.data.renderer) !== null && _a !== void 0 ? _a : renderer);
4161
+ patchElement(n1, n2, n2.data.renderer ?? renderer);
3998
4162
  break;
3999
4163
  case 3 /* VNodeType.CustomElement */:
4000
- patchCustomElement(n1, n2, parent, (_b = n2.data.renderer) !== null && _b !== void 0 ? _b : renderer);
4164
+ patchCustomElement(n1, n2, parent, n2.data.renderer ?? renderer);
4001
4165
  break;
4002
4166
  }
4003
4167
  }
4004
4168
  function mount(node, parent, renderer, anchor) {
4005
- var _a, _b;
4006
4169
  switch (node.type) {
4007
4170
  case 0 /* VNodeType.Text */:
4008
4171
  // VText has no special capability, fallback to the owner's renderer
@@ -4021,11 +4184,11 @@ function mount(node, parent, renderer, anchor) {
4021
4184
  break;
4022
4185
  case 2 /* VNodeType.Element */:
4023
4186
  // If the vnode data has a renderer override use it, else fallback to owner's renderer
4024
- mountElement(node, parent, anchor, (_a = node.data.renderer) !== null && _a !== void 0 ? _a : renderer);
4187
+ mountElement(node, parent, anchor, node.data.renderer ?? renderer);
4025
4188
  break;
4026
4189
  case 3 /* VNodeType.CustomElement */:
4027
4190
  // If the vnode data has a renderer override use it, else fallback to owner's renderer
4028
- mountCustomElement(node, parent, anchor, (_b = node.data.renderer) !== null && _b !== void 0 ? _b : renderer);
4191
+ mountCustomElement(node, parent, anchor, node.data.renderer ?? renderer);
4029
4192
  break;
4030
4193
  }
4031
4194
  }
@@ -4087,11 +4250,11 @@ function mountElement(vnode, parent, anchor, renderer) {
4087
4250
  mountVNodes(vnode.children, elm, renderer, null);
4088
4251
  }
4089
4252
  function patchStatic(n1, n2, renderer) {
4090
- const elm = (n2.elm = n1.elm);
4253
+ n2.elm = n1.elm;
4091
4254
  // slotAssignments can only apply to the top level element, never to a static part.
4092
4255
  patchSlotAssignment(n1, n2, renderer);
4093
4256
  // The `refs` object is blown away in every re-render, so we always need to re-apply them
4094
- applyStaticParts(elm, n2, renderer, false);
4257
+ patchStaticParts(n1, n2);
4095
4258
  }
4096
4259
  function patchElement(n1, n2, renderer) {
4097
4260
  const elm = (n2.elm = n1.elm);
@@ -4114,7 +4277,7 @@ function mountStatic(vnode, parent, anchor, renderer) {
4114
4277
  // slotAssignments can only apply to the top level element, never to a static part.
4115
4278
  patchSlotAssignment(null, vnode, renderer);
4116
4279
  insertNode(elm, parent, anchor, renderer);
4117
- applyStaticParts(elm, vnode, renderer, true);
4280
+ mountStaticParts(elm, vnode, renderer);
4118
4281
  }
4119
4282
  function mountCustomElement(vnode, parent, anchor, renderer) {
4120
4283
  const { sel, owner, ctor } = vnode;
@@ -4376,17 +4539,15 @@ function applyStyleScoping(elm, owner, renderer) {
4376
4539
  }
4377
4540
  }
4378
4541
  function applyDomManual(elm, vnode) {
4379
- var _a;
4380
4542
  const { owner, data: { context }, } = vnode;
4381
- 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 */) {
4382
4544
  elm.$domManual$ = true;
4383
4545
  }
4384
4546
  }
4385
4547
  function applyElementRestrictions(elm, vnode) {
4386
- var _a, _b;
4387
4548
  if (process.env.NODE_ENV !== 'production') {
4388
4549
  const isSynthetic = vnode.owner.shadowMode === 1 /* ShadowMode.Synthetic */;
4389
- 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 */;
4390
4551
  const isLight = vnode.owner.renderMode === 0 /* RenderMode.Light */;
4391
4552
  patchElementWithRestrictions(elm, {
4392
4553
  isPortal,
@@ -4493,7 +4654,6 @@ function createViewModelHook(elm, vnode, renderer) {
4493
4654
  return vm;
4494
4655
  }
4495
4656
  function allocateInSlot(vm, children, owner) {
4496
- var _a;
4497
4657
  const { cmpSlots: { slotAssignments: oldSlotsMapping }, } = vm;
4498
4658
  const cmpSlotsMapping = shared.create(null);
4499
4659
  // Collect all slots into cmpSlotsMapping
@@ -4504,7 +4664,7 @@ function allocateInSlot(vm, children, owner) {
4504
4664
  }
4505
4665
  let slotName = '';
4506
4666
  if (isVBaseElement(vnode) || isVStatic(vnode)) {
4507
- slotName = (_a = vnode.slotAssignment) !== null && _a !== void 0 ? _a : '';
4667
+ slotName = vnode.slotAssignment ?? '';
4508
4668
  }
4509
4669
  else if (isVScopedSlotFragment(vnode)) {
4510
4670
  slotName = vnode.slotName;
@@ -4513,6 +4673,7 @@ function allocateInSlot(vm, children, owner) {
4513
4673
  // but elm.setAttribute('slot', Symbol(1)) is an error.
4514
4674
  // the following line also throws same error for symbols
4515
4675
  // Similar for Object.create(null)
4676
+ // eslint-disable-next-line @typescript-eslint/restrict-plus-operands
4516
4677
  const normalizedSlotName = '' + slotName;
4517
4678
  const vnodes = (cmpSlotsMapping[normalizedSlotName] =
4518
4679
  cmpSlotsMapping[normalizedSlotName] || []);
@@ -4819,6 +4980,8 @@ function h(sel, data, children = EmptyArray) {
4819
4980
  }
4820
4981
  });
4821
4982
  }
4983
+ // TODO [#3974]: remove temporary logic to support v5 compiler + v6+ engine
4984
+ data = applyTemporaryCompilerV5SlotFix(data);
4822
4985
  const { key, slotAssignment } = data;
4823
4986
  const vnode = {
4824
4987
  type: 2 /* VNodeType.Element */,
@@ -4855,6 +5018,8 @@ function s(slotName, data, children, slotset) {
4855
5018
  }
4856
5019
  const vmBeingRendered = getVMBeingRendered();
4857
5020
  const { renderMode, apiVersion } = vmBeingRendered;
5021
+ // TODO [#3974]: remove temporary logic to support v5 compiler + v6+ engine
5022
+ data = applyTemporaryCompilerV5SlotFix(data);
4858
5023
  if (!shared.isUndefined(slotset) &&
4859
5024
  !shared.isUndefined(slotset.slotAssignments) &&
4860
5025
  !shared.isUndefined(slotset.slotAssignments[slotName]) &&
@@ -4906,11 +5071,11 @@ function s(slotName, data, children, slotset) {
4906
5071
  // to the vnode because the current way the diffing algo works, it will replace the original reference
4907
5072
  // to the host element with a new one. This means the new element will be mounted and immediately unmounted.
4908
5073
  // Creating a copy of the vnode to preserve a reference to the previous host element.
4909
- clonedVNode = Object.assign(Object.assign({}, vnode), { slotAssignment: data.slotAssignment });
5074
+ clonedVNode = { ...vnode, slotAssignment: data.slotAssignment };
4910
5075
  }
4911
5076
  // If the slot content is standard type, the content is static, no additional
4912
5077
  // processing needed on the vnode
4913
- shared.ArrayPush.call(newChildren, clonedVNode !== null && clonedVNode !== void 0 ? clonedVNode : vnode);
5078
+ shared.ArrayPush.call(newChildren, clonedVNode ?? vnode);
4914
5079
  }
4915
5080
  }
4916
5081
  }
@@ -4958,6 +5123,8 @@ function c(sel, Ctor, data, children = EmptyArray) {
4958
5123
  });
4959
5124
  }
4960
5125
  }
5126
+ // TODO [#3974]: remove temporary logic to support v5 compiler + v6+ engine
5127
+ data = applyTemporaryCompilerV5SlotFix(data);
4961
5128
  const { key, slotAssignment } = data;
4962
5129
  let elm, aChildren, vm;
4963
5130
  const vnode = {
@@ -5367,7 +5534,7 @@ function logGlobalOperationStart(opId, vm) {
5367
5534
  start(markName);
5368
5535
  }
5369
5536
  if (isProfilerEnabled) {
5370
- 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);
5371
5538
  }
5372
5539
  }
5373
5540
  function logGlobalOperationEnd(opId, vm) {
@@ -5377,7 +5544,7 @@ function logGlobalOperationEnd(opId, vm) {
5377
5544
  end(opName, markName);
5378
5545
  }
5379
5546
  if (isProfilerEnabled) {
5380
- 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);
5381
5548
  }
5382
5549
  }
5383
5550
 
@@ -5399,7 +5566,6 @@ function validateSlots(vm) {
5399
5566
  assertNotProd(); // this method should never leak to prod
5400
5567
  const { cmpSlots } = vm;
5401
5568
  for (const slotName in cmpSlots.slotAssignments) {
5402
- // eslint-disable-next-line @lwc/lwc-internal/no-production-assert
5403
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}.`);
5404
5570
  }
5405
5571
  }
@@ -5697,16 +5863,14 @@ Ctor, metadata) {
5697
5863
  return Ctor;
5698
5864
  }
5699
5865
  function getComponentRegisteredTemplate(Ctor) {
5700
- var _a;
5701
- return (_a = registeredComponentMap.get(Ctor)) === null || _a === void 0 ? void 0 : _a.tmpl;
5866
+ return registeredComponentMap.get(Ctor)?.tmpl;
5702
5867
  }
5703
5868
  function getComponentRegisteredName(Ctor) {
5704
- var _a;
5705
- return (_a = registeredComponentMap.get(Ctor)) === null || _a === void 0 ? void 0 : _a.sel;
5869
+ return registeredComponentMap.get(Ctor)?.sel;
5706
5870
  }
5707
5871
  function getComponentAPIVersion(Ctor) {
5708
5872
  const metadata = registeredComponentMap.get(Ctor);
5709
- const apiVersion = metadata === null || metadata === void 0 ? void 0 : metadata.apiVersion;
5873
+ const apiVersion = metadata?.apiVersion;
5710
5874
  if (shared.isUndefined(apiVersion)) {
5711
5875
  // This should only occur in our Karma tests; in practice every component
5712
5876
  // is registered, and so this code path should not get hit. But to be safe,
@@ -5724,11 +5888,27 @@ function getTemplateReactiveObserver(vm) {
5724
5888
  }
5725
5889
  });
5726
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
+ }
5727
5899
  function renderComponent(vm) {
5728
5900
  if (process.env.NODE_ENV !== 'production') {
5729
5901
  shared.assert.invariant(vm.isDirty, `${vm} is not dirty.`);
5730
5902
  }
5731
- 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);
5732
5912
  const vnodes = invokeComponentRenderMethod(vm);
5733
5913
  vm.isDirty = false;
5734
5914
  vm.isScheduled = false;
@@ -5803,9 +5983,8 @@ function appendVM(vm) {
5803
5983
  function resetComponentStateWhenRemoved(vm) {
5804
5984
  const { state } = vm;
5805
5985
  if (state !== 2 /* VMState.disconnected */) {
5806
- const { tro } = vm;
5807
5986
  // Making sure that any observing record will not trigger the rehydrated on this vm
5808
- tro.reset();
5987
+ resetTemplateObserverAndUnsubscribe(vm);
5809
5988
  runDisconnectedCallback(vm);
5810
5989
  // Spec: https://dom.spec.whatwg.org/#concept-node-remove (step 14-15)
5811
5990
  runChildNodesDisconnectedCallback(vm);
@@ -5889,7 +6068,7 @@ function createVM(elm, ctor, renderer, options) {
5889
6068
  vm.debugInfo = shared.create(null);
5890
6069
  }
5891
6070
  vm.stylesheets = computeStylesheets(vm, def.ctor);
5892
- const computedShadowMode = computeShadowMode(def, vm.owner, renderer);
6071
+ const computedShadowMode = computeShadowMode(def, vm.owner, renderer, hydrated);
5893
6072
  if (lwcRuntimeFlags.ENABLE_FORCE_SHADOW_MIGRATE_MODE) {
5894
6073
  vm.shadowMode = 0 /* ShadowMode.Native */;
5895
6074
  vm.shadowMigrateMode = computedShadowMode === 1 /* ShadowMode.Synthetic */;
@@ -5976,16 +6155,21 @@ function computeShadowAndRenderMode(Ctor, renderer) {
5976
6155
  const def = getComponentInternalDef(Ctor);
5977
6156
  const { renderMode } = def;
5978
6157
  // Assume null `owner` - this is what happens in hydration cases anyway
5979
- const shadowMode = computeShadowMode(def, /* owner */ null, renderer);
6158
+ // Also assume we are not in hydration mode for this exported API
6159
+ const shadowMode = computeShadowMode(def, /* owner */ null, renderer, false);
5980
6160
  return { renderMode, shadowMode };
5981
6161
  }
5982
- function computeShadowMode(def, owner, renderer) {
6162
+ function computeShadowMode(def, owner, renderer, hydrated) {
5983
6163
  // Force the shadow mode to always be native. Used for running tests with synthetic shadow patches
5984
6164
  // on, but components running in actual native shadow mode
5985
6165
  if (process.env.NODE_ENV !== 'production' &&
5986
6166
  lwcRuntimeFlags.ENABLE_FORCE_NATIVE_SHADOW_MODE_FOR_TEST) {
5987
6167
  return 0 /* ShadowMode.Native */;
5988
6168
  }
6169
+ if (shared.isTrue(hydrated)) {
6170
+ // hydration only supports native shadow
6171
+ return 0 /* ShadowMode.Native */;
6172
+ }
5989
6173
  const { isSyntheticShadowDefined } = renderer;
5990
6174
  let shadowMode;
5991
6175
  if (isSyntheticShadowDefined || lwcRuntimeFlags.ENABLE_FORCE_SHADOW_MIGRATE_MODE) {
@@ -6113,7 +6297,7 @@ function flushRehydrationQueue() {
6113
6297
  logGlobalOperationEnd(8 /* OperationId.GlobalRehydrate */);
6114
6298
  // re-throwing the original error will break the current tick, but since the next tick is
6115
6299
  // already scheduled, it should continue patching the rest.
6116
- throw error; // eslint-disable-line no-unsafe-finally
6300
+ throw error;
6117
6301
  }
6118
6302
  }
6119
6303
  logGlobalOperationEnd(8 /* OperationId.GlobalRehydrate */);
@@ -6586,7 +6770,7 @@ function checkAndReportViolation(elm, prop, isSetter, setValue) {
6586
6770
  setValueType = shared.isNull(setValue) ? 'null' : typeof setValue;
6587
6771
  }
6588
6772
  report("NonStandardAriaReflection" /* ReportingEventId.NonStandardAriaReflection */, {
6589
- tagName: vm === null || vm === void 0 ? void 0 : vm.tagName,
6773
+ tagName: vm?.tagName,
6590
6774
  propertyName: prop,
6591
6775
  isSetter,
6592
6776
  setValueType,
@@ -6664,7 +6848,6 @@ function hydrateVM(vm) {
6664
6848
  runRenderedCallback(vm);
6665
6849
  }
6666
6850
  function hydrateNode(node, vnode, renderer) {
6667
- var _a, _b;
6668
6851
  let hydratedNode;
6669
6852
  switch (vnode.type) {
6670
6853
  case 0 /* VNodeType.Text */:
@@ -6684,10 +6867,10 @@ function hydrateNode(node, vnode, renderer) {
6684
6867
  hydratedNode = hydrateFragment(node, vnode, renderer);
6685
6868
  break;
6686
6869
  case 2 /* VNodeType.Element */:
6687
- hydratedNode = hydrateElement(node, vnode, (_a = vnode.data.renderer) !== null && _a !== void 0 ? _a : renderer);
6870
+ hydratedNode = hydrateElement(node, vnode, vnode.data.renderer ?? renderer);
6688
6871
  break;
6689
6872
  case 3 /* VNodeType.CustomElement */:
6690
- hydratedNode = hydrateCustomElement(node, vnode, (_b = vnode.data.renderer) !== null && _b !== void 0 ? _b : renderer);
6873
+ hydratedNode = hydrateCustomElement(node, vnode, vnode.data.renderer ?? renderer);
6691
6874
  break;
6692
6875
  }
6693
6876
  return renderer.nextSibling(hydratedNode);
@@ -6730,7 +6913,6 @@ function getValidationPredicate(optOutStaticProp) {
6730
6913
  return (_attrName) => true;
6731
6914
  }
6732
6915
  function hydrateText(node, vnode, renderer) {
6733
- var _a;
6734
6916
  if (!hasCorrectNodeType(vnode, node, 3 /* EnvNodeTypes.TEXT */, renderer)) {
6735
6917
  return handleMismatch(node, vnode, renderer);
6736
6918
  }
@@ -6740,12 +6922,11 @@ function hydrateText(node, vnode, renderer) {
6740
6922
  }
6741
6923
  }
6742
6924
  const { setText } = renderer;
6743
- setText(node, (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
6925
+ setText(node, vnode.text ?? null);
6744
6926
  vnode.elm = node;
6745
6927
  return node;
6746
6928
  }
6747
6929
  function hydrateComment(node, vnode, renderer) {
6748
- var _a;
6749
6930
  if (!hasCorrectNodeType(vnode, node, 8 /* EnvNodeTypes.COMMENT */, renderer)) {
6750
6931
  return handleMismatch(node, vnode, renderer);
6751
6932
  }
@@ -6757,7 +6938,7 @@ function hydrateComment(node, vnode, renderer) {
6757
6938
  }
6758
6939
  }
6759
6940
  const { setProperty } = renderer;
6760
- setProperty(node, NODE_VALUE_PROP, (_a = vnode.text) !== null && _a !== void 0 ? _a : null);
6941
+ setProperty(node, NODE_VALUE_PROP, vnode.text ?? null);
6761
6942
  vnode.elm = node;
6762
6943
  return node;
6763
6944
  }
@@ -6767,7 +6948,7 @@ function hydrateStaticElement(elm, vnode, renderer) {
6767
6948
  return handleMismatch(elm, vnode, renderer);
6768
6949
  }
6769
6950
  vnode.elm = elm;
6770
- applyStaticParts(elm, vnode, renderer, true);
6951
+ mountStaticParts(elm, vnode, renderer);
6771
6952
  return elm;
6772
6953
  }
6773
6954
  function hydrateFragment(elm, vnode, renderer) {
@@ -6792,7 +6973,10 @@ function hydrateElement(elm, vnode, renderer) {
6792
6973
  if (!shared.isUndefined(props) && !shared.isUndefined(props.innerHTML)) {
6793
6974
  if (getProperty(elm, 'innerHTML') === props.innerHTML) {
6794
6975
  // Do a shallow clone since VNodeData may be shared across VNodes due to hoist optimization
6795
- vnode.data = Object.assign(Object.assign({}, vnode.data), { props: cloneAndOmitKey(props, 'innerHTML') });
6976
+ vnode.data = {
6977
+ ...vnode.data,
6978
+ props: cloneAndOmitKey(props, 'innerHTML'),
6979
+ };
6796
6980
  }
6797
6981
  else {
6798
6982
  if (process.env.NODE_ENV !== 'production') {
@@ -7004,7 +7188,11 @@ function validateClassAttr(vnode, elm, renderer) {
7004
7188
  className = shared.ArrayJoin.call(classNames, ' ');
7005
7189
  }
7006
7190
  else if (!shared.isUndefined(classMap)) {
7007
- 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
+ };
7008
7196
  }
7009
7197
  else {
7010
7198
  // The order of the className should be scopedToken stylesheetTokenHost
@@ -7440,5 +7628,5 @@ exports.swapTemplate = swapTemplate;
7440
7628
  exports.track = track;
7441
7629
  exports.unwrap = unwrap;
7442
7630
  exports.wire = wire;
7443
- /** version: 6.1.0 */
7631
+ /** version: 6.2.0 */
7444
7632
  //# sourceMappingURL=index.cjs.js.map