@locker/cli 0.29.1 → 0.29.3

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.
@@ -2,10 +2,10 @@
2
2
  'use strict';
3
3
 
4
4
  /**
5
- * Copyright (c) 2025 Salesforce, Inc.
5
+ * Copyright (c) 2026 Salesforce, Inc.
6
6
  */
7
7
  /**
8
- * Copyright (c) 2025 Salesforce, Inc.
8
+ * Copyright (c) 2026 Salesforce, Inc.
9
9
  */
10
10
  /*
11
11
  * Copyright (c) 2018, salesforce.com, inc.
@@ -266,34 +266,43 @@
266
266
  61 /* APIVersion.V61_250_SUMMER_24 */,
267
267
  62 /* APIVersion.V62_252_WINTER_25 */,
268
268
  63 /* APIVersion.V63_254_SPRING_25 */,
269
+ 64 /* APIVersion.V64_256_SUMMER_25 */,
270
+ 65 /* APIVersion.V65_258_WINTER_26 */,
271
+ 66 /* APIVersion.V66_260_SPRING_26 */,
269
272
  ];
270
273
  const LOWEST_API_VERSION = allVersions[0];
271
274
  /**
272
- *
273
275
  * @param apiVersionFeature
274
- * @param apiVersion
275
276
  */
276
- function isAPIFeatureEnabled(apiVersionFeature, apiVersion) {
277
+ function minApiVersion(apiVersionFeature) {
277
278
  switch (apiVersionFeature) {
278
279
  case 0 /* APIFeature.LOWERCASE_SCOPE_TOKENS */:
279
280
  case 1 /* APIFeature.TREAT_ALL_PARSE5_ERRORS_AS_ERRORS */:
280
- return apiVersion >= 59 /* APIVersion.V59_246_WINTER_24 */;
281
+ return 59 /* APIVersion.V59_246_WINTER_24 */;
281
282
  case 3 /* APIFeature.DISABLE_OBJECT_REST_SPREAD_TRANSFORMATION */:
282
283
  case 4 /* APIFeature.SKIP_UNNECESSARY_REGISTER_DECORATORS */:
283
284
  case 5 /* APIFeature.USE_COMMENTS_FOR_FRAGMENT_BOOKENDS */:
284
285
  case 2 /* APIFeature.USE_FRAGMENTS_FOR_LIGHT_DOM_SLOTS */:
285
- return apiVersion >= 60 /* APIVersion.V60_248_SPRING_24 */;
286
+ return 60 /* APIVersion.V60_248_SPRING_24 */;
286
287
  case 7 /* APIFeature.ENABLE_ELEMENT_INTERNALS_AND_FACE */:
287
288
  case 6 /* APIFeature.USE_LIGHT_DOM_SLOT_FORWARDING */:
288
- return apiVersion >= 61 /* APIVersion.V61_250_SUMMER_24 */;
289
+ return 61 /* APIVersion.V61_250_SUMMER_24 */;
289
290
  case 8 /* APIFeature.ENABLE_THIS_DOT_HOST_ELEMENT */:
290
291
  case 9 /* APIFeature.ENABLE_THIS_DOT_STYLE */:
291
292
  case 10 /* APIFeature.TEMPLATE_CLASS_NAME_OBJECT_BINDING */:
292
- return apiVersion >= 62 /* APIVersion.V62_252_WINTER_25 */;
293
+ return 62 /* APIVersion.V62_252_WINTER_25 */;
293
294
  case 11 /* APIFeature.ENABLE_COMPLEX_TEMPLATE_EXPRESSIONS */:
294
- return apiVersion >= 63 /* APIVersion.V63_254_SPRING_25 */;
295
+ return 66 /* APIVersion.V66_260_SPRING_26 */;
295
296
  }
296
297
  }
298
+ /**
299
+ *
300
+ * @param apiVersionFeature
301
+ * @param apiVersion
302
+ */
303
+ function isAPIFeatureEnabled(apiVersionFeature, apiVersion) {
304
+ return apiVersion >= minApiVersion(apiVersionFeature);
305
+ }
297
306
 
298
307
  /*
299
308
  * Copyright (c) 2018, salesforce.com, inc.
@@ -655,17 +664,14 @@
655
664
  }
656
665
  function isTrustedSignal(target) {
657
666
  if (!trustedSignals) {
658
- // The runtime didn't set a trustedSignals set
659
- // this check should only be performed for runtimes that care about filtering signals to track
660
- // our default behavior should be to track all signals
661
- return true;
667
+ return false;
662
668
  }
663
669
  return trustedSignals.has(target);
664
670
  }
665
- /** version: 8.21.1 */
671
+ /** version: 9.4.3 */
666
672
 
667
673
  /**
668
- * Copyright (c) 2025 Salesforce, Inc.
674
+ * Copyright (c) 2026 Salesforce, Inc.
669
675
  */
670
676
 
671
677
  /*
@@ -683,13 +689,26 @@
683
689
  ENABLE_WIRE_SYNC_EMIT: null,
684
690
  DISABLE_LIGHT_DOM_UNSCOPED_CSS: null,
685
691
  ENABLE_FROZEN_TEMPLATE: null,
686
- ENABLE_LEGACY_SCOPE_TOKENS: null,
687
- ENABLE_FORCE_SHADOW_MIGRATE_MODE: null,
688
692
  ENABLE_EXPERIMENTAL_SIGNALS: null,
689
693
  DISABLE_SYNTHETIC_SHADOW: null,
690
- DISABLE_SCOPE_TOKEN_VALIDATION: null,
691
- LEGACY_LOCKER_ENABLED: null,
692
- DISABLE_LEGACY_VALIDATION: null,
694
+ DISABLE_HOST_ATTACH_SHADOW_GUARD: null,
695
+ DISABLE_STRICT_VALIDATION: null,
696
+ DISABLE_DETACHED_REHYDRATION: null,
697
+ DISABLE_BRIDGE_ELEMENT_PROPERTY_GUARD: null,
698
+ // Remove in 270
699
+ ENABLE_LEGACY_ITEM_POLYFILL: null,
700
+ // Remove in 270
701
+ ENABLE_SHADOW_ROOT_UNDEFINED_GET_ELEMENT_BY_ID: null,
702
+ // Remove in 270
703
+ ENABLE_BROKEN_HTML_COLLECTION_NAMED_ITEM: null,
704
+ // Remove in 270
705
+ ENABLE_LEGACY_ATTRIBUTE_CHANGED_CALLBACK: null,
706
+ // Remove in 270
707
+ DISABLE_HYDRATION_CUSTOM_ELEMENT_CHECK: null,
708
+ DISABLE_SANITIZED_HTML_CONTENT_IDENTITY_CHECK: null,
709
+ ENABLE_INTRINSIC_TEMPLATE_INVOCATION: null,
710
+ ENABLE_PARSE_FRAGMENT_SANITIZATION: null,
711
+ ENABLE_RENDERER_FACTORY_GUARD: null,
693
712
  };
694
713
  if (!globalThis.lwcRuntimeFlags) {
695
714
  Object.defineProperty(globalThis, 'lwcRuntimeFlags', { value: create(null) });
@@ -718,7 +737,7 @@
718
737
  console.info(`Attempt to set a value on an unknown feature flag "${name}" resulted in a NOOP.`);
719
738
  return;
720
739
  }
721
- // This may seem redundant, but `"production" === 'test-karma-lwc'` is replaced by Karma tests
740
+ // This may seem redundant, but `"production" === 'test-lwc-integration'` is replaced by integration tests
722
741
  {
723
742
  // Disallow the same flag to be set more than once in production
724
743
  const runtimeValue = flags[name];
@@ -739,13 +758,13 @@
739
758
  */
740
759
  function setFeatureFlagForTest(name, value) {
741
760
  }
742
- /** version: 8.21.1 */
761
+ /** version: 9.4.3 */
743
762
 
744
763
  /**
745
- * Copyright (c) 2025 Salesforce, Inc.
764
+ * Copyright (c) 2026 Salesforce, Inc.
746
765
  */
747
766
  /**
748
- * Copyright (c) 2025 Salesforce, Inc.
767
+ * Copyright (c) 2026 Salesforce, Inc.
749
768
  */
750
769
  /*
751
770
  * Copyright (c) 2018, salesforce.com, inc.
@@ -763,7 +782,7 @@
763
782
  * @param value
764
783
  * @param msg
765
784
  */
766
- /** version: 8.21.1 */
785
+ /** version: 9.4.3 */
767
786
 
768
787
  /*
769
788
  * Copyright (c) 2023, salesforce.com, inc.
@@ -787,10 +806,10 @@
787
806
  }
788
807
  }
789
808
  }
790
- /** version: 8.21.1 */
809
+ /** version: 9.4.3 */
791
810
 
792
811
  /**
793
- * Copyright (c) 2025 Salesforce, Inc.
812
+ * Copyright (c) 2026 Salesforce, Inc.
794
813
  */
795
814
 
796
815
  /*
@@ -1149,6 +1168,18 @@
1149
1168
  signalTracker.reset();
1150
1169
  }
1151
1170
  }
1171
+ /**
1172
+ * A normalized string representation of an error, because browsers behave differently
1173
+ */
1174
+ const errorWithStack = (err) => {
1175
+ if (typeof err !== 'object' || err === null) {
1176
+ return String(err);
1177
+ }
1178
+ const stack = 'stack' in err ? String(err.stack) : '';
1179
+ const message = 'message' in err ? String(err.message) : '';
1180
+ const constructor = err.constructor.name;
1181
+ return stack.includes(message) ? stack : `${constructor}: ${message}\n${stack}`;
1182
+ };
1152
1183
  /**
1153
1184
  * This class is used to keep track of the signals associated to a given object.
1154
1185
  * It is used to prevent the LWC engine from subscribing duplicate callbacks multiple times
@@ -1172,7 +1203,7 @@
1172
1203
  }
1173
1204
  }
1174
1205
  catch (err) {
1175
- logWarnOnce(`Attempted to subscribe to an object that has the shape of a signal but received the following error: ${err?.stack ?? err}`);
1206
+ logWarnOnce(`Attempted to subscribe to an object that has the shape of a signal but received the following error: ${errorWithStack(err)}`);
1176
1207
  }
1177
1208
  }
1178
1209
  unsubscribeFromSignals() {
@@ -1180,7 +1211,7 @@
1180
1211
  this.signalToUnsubscribeMap.forEach((unsubscribe) => unsubscribe());
1181
1212
  }
1182
1213
  catch (err) {
1183
- logWarnOnce(`Attempted to call a signal's unsubscribe callback but received the following error: ${err?.stack ?? err}`);
1214
+ logWarnOnce(`Attempted to call a signal's unsubscribe callback but received the following error: ${errorWithStack(err)}`);
1184
1215
  }
1185
1216
  }
1186
1217
  reset() {
@@ -1206,12 +1237,13 @@
1206
1237
  if (lwcRuntimeFlags.ENABLE_EXPERIMENTAL_SIGNALS &&
1207
1238
  isObject(target) &&
1208
1239
  !isNull(target) &&
1209
- isTrustedSignal(target) &&
1210
1240
  true &&
1211
1241
  // Only subscribe if a template is being rendered by the engine
1212
1242
  tro.isObserving()) {
1213
- // Subscribe the template reactive observer's notify method, which will mark the vm as dirty and schedule hydration.
1214
- subscribeToSignal(component, target, tro.notify.bind(tro));
1243
+ if (isTrustedSignal(target)) {
1244
+ // Subscribe the template reactive observer's notify method, which will mark the vm as dirty and schedule hydration.
1245
+ subscribeToSignal(component, target, tro.notify.bind(tro));
1246
+ }
1215
1247
  }
1216
1248
  }
1217
1249
  function createReactiveObserver(callback) {
@@ -1792,78 +1824,6 @@
1792
1824
  }
1793
1825
  }
1794
1826
 
1795
- /*
1796
- * Copyright (c) 2023, salesforce.com, inc.
1797
- * All rights reserved.
1798
- * SPDX-License-Identifier: MIT
1799
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
1800
- */
1801
- let globalStylesheet;
1802
- function isStyleElement(elm) {
1803
- return elm.tagName === 'STYLE';
1804
- }
1805
- async function fetchStylesheet(elm) {
1806
- if (isStyleElement(elm)) {
1807
- return elm.textContent;
1808
- }
1809
- else {
1810
- // <link>
1811
- const { href } = elm;
1812
- try {
1813
- return await (await fetch(href)).text();
1814
- }
1815
- catch (_err) {
1816
- logWarnOnce(`Ignoring cross-origin stylesheet in migrate mode: ${href}`);
1817
- // ignore errors with cross-origin stylesheets - nothing we can do for those
1818
- return '';
1819
- }
1820
- }
1821
- }
1822
- function initGlobalStylesheet() {
1823
- const stylesheet = new CSSStyleSheet();
1824
- const elmsToPromises = new Map();
1825
- let lastSeenLength = 0;
1826
- const copyToGlobalStylesheet = () => {
1827
- const elms = document.head.querySelectorAll('style:not([data-rendered-by-lwc]),link[rel="stylesheet"]');
1828
- if (elms.length === lastSeenLength) {
1829
- return; // nothing to update
1830
- }
1831
- lastSeenLength = elms.length;
1832
- const promises = [...elms].map((elm) => {
1833
- let promise = elmsToPromises.get(elm);
1834
- if (!promise) {
1835
- // Cache the promise
1836
- promise = fetchStylesheet(elm);
1837
- elmsToPromises.set(elm, promise);
1838
- }
1839
- return promise;
1840
- });
1841
- // eslint-disable-next-line @typescript-eslint/no-floating-promises
1842
- Promise.all(promises).then((stylesheetTexts) => {
1843
- // When replaceSync() is called, the entire contents of the constructable stylesheet are replaced
1844
- // with the copied+concatenated styles. This means that any shadow root's adoptedStyleSheets that
1845
- // contains this constructable stylesheet will immediately get the new styles.
1846
- stylesheet.replaceSync(stylesheetTexts.join('\n'));
1847
- });
1848
- };
1849
- const headObserver = new MutationObserver(copyToGlobalStylesheet);
1850
- // By observing only the childList, note that we are not covering the case where someone changes an `href`
1851
- // on an existing <link>`, or the textContent on an existing `<style>`. This is assumed to be an uncommon
1852
- // case and not worth covering.
1853
- headObserver.observe(document.head, {
1854
- childList: true,
1855
- });
1856
- copyToGlobalStylesheet();
1857
- return stylesheet;
1858
- }
1859
- function applyShadowMigrateMode(shadowRoot) {
1860
- if (!globalStylesheet) {
1861
- globalStylesheet = initGlobalStylesheet();
1862
- }
1863
- shadowRoot.synthetic = true; // pretend to be synthetic mode
1864
- shadowRoot.adoptedStyleSheets.push(globalStylesheet);
1865
- }
1866
-
1867
1827
  /*
1868
1828
  * Copyright (c) 2024, Salesforce, Inc.
1869
1829
  * All rights reserved.
@@ -1963,10 +1923,6 @@
1963
1923
  });
1964
1924
  vm.shadowRoot = shadowRoot;
1965
1925
  associateVM(shadowRoot, vm);
1966
- if (lwcRuntimeFlags.ENABLE_FORCE_SHADOW_MIGRATE_MODE &&
1967
- vm.shadowMigrateMode) {
1968
- applyShadowMigrateMode(shadowRoot);
1969
- }
1970
1926
  return shadowRoot;
1971
1927
  }
1972
1928
  // Type assertion because we need to build the prototype before it satisfies the interface.
@@ -2037,16 +1993,35 @@
2037
1993
  },
2038
1994
  attachInternals() {
2039
1995
  const vm = getAssociatedVM(this);
2040
- const { elm, apiVersion, renderer: { attachInternals }, } = vm;
1996
+ const { def: { ctor }, elm, apiVersion, renderer: { attachInternals }, } = vm;
2041
1997
  if (!isAPIFeatureEnabled(7 /* APIFeature.ENABLE_ELEMENT_INTERNALS_AND_FACE */, apiVersion)) {
2042
1998
  throw new Error(`The attachInternals API is only supported in API version 61 and above. ` +
2043
1999
  `The current version is ${apiVersion}. ` +
2044
2000
  `To use this API, update the LWC component API version. https://lwc.dev/guide/versioning`);
2045
2001
  }
2046
- if (vm.shadowMode === 1 /* ShadowMode.Synthetic */) {
2002
+ const internals = attachInternals(elm);
2003
+ if (vm.shadowMode === 1 /* ShadowMode.Synthetic */ && supportsSyntheticElementInternals(ctor)) {
2004
+ const handler = {
2005
+ get(target, prop) {
2006
+ if (prop === 'shadowRoot') {
2007
+ return vm.shadowRoot;
2008
+ }
2009
+ const value = Reflect.get(target, prop);
2010
+ if (typeof value === 'function') {
2011
+ return value.bind(target);
2012
+ }
2013
+ return value;
2014
+ },
2015
+ set(target, prop, value) {
2016
+ return Reflect.set(target, prop, value);
2017
+ },
2018
+ };
2019
+ return new Proxy(internals, handler);
2020
+ }
2021
+ else if (vm.shadowMode === 1 /* ShadowMode.Synthetic */) {
2047
2022
  throw new Error('attachInternals API is not supported in synthetic shadow.');
2048
2023
  }
2049
- return attachInternals(elm);
2024
+ return internals;
2050
2025
  },
2051
2026
  get isConnected() {
2052
2027
  const vm = getAssociatedVM(this);
@@ -2515,7 +2490,7 @@
2515
2490
  value,
2516
2491
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2517
2492
  context) {
2518
- throw new Error();
2493
+ assert.fail(`@api decorator can only be used as a decorator function.`);
2519
2494
  }
2520
2495
  function createPublicPropertyDescriptor(key) {
2521
2496
  return {
@@ -2567,7 +2542,7 @@
2567
2542
  if (arguments.length === 1) {
2568
2543
  return getReactiveProxy(target);
2569
2544
  }
2570
- throw new Error();
2545
+ assert.fail(`@track decorator can only be used with one argument to return a trackable object, or as a decorator function.`);
2571
2546
  }
2572
2547
  function internalTrackDecorator(key) {
2573
2548
  return {
@@ -2595,6 +2570,10 @@
2595
2570
  */
2596
2571
  /**
2597
2572
  * Decorator factory to wire a property or method to a wire adapter data source.
2573
+ *
2574
+ * TypeScript users: Due to limitations of the type system, some edge cases are
2575
+ * not fully type checked. See the type definition for {@linkcode ConfigWithReactiveProps}
2576
+ * for details.
2598
2577
  * @param adapter the adapter used to provision data
2599
2578
  * @param config configuration object for the adapter
2600
2579
  * @returns A decorator function
@@ -2609,7 +2588,7 @@
2609
2588
  adapter,
2610
2589
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
2611
2590
  config) {
2612
- throw new Error();
2591
+ assert.fail('@wire(adapter, config?) may only be used as a decorator.');
2613
2592
  }
2614
2593
  function internalWireFieldDecorator(key) {
2615
2594
  return {
@@ -2805,11 +2784,28 @@
2805
2784
  // descriptor, so we can cache them:
2806
2785
  const cachedGetterByKey = create(null);
2807
2786
  const cachedSetterByKey = create(null);
2787
+ // Because bridge descriptors are cached by member name and shared across every component's bridge
2788
+ // element, a descriptor captured from one component can be re-invoked against an unrelated component
2789
+ // (e.g. `donorDescriptor.get.call(otherHost)`). The cached accessor recovers the component VM from
2790
+ // the invocation receiver (`this`), so without this guard it would forward the call to whatever
2791
+ // like-named member exists on the other component — including a *private* one that the other
2792
+ // component never exposed publicly. `vm.def.props`/`vm.def.methods` are the authoritative sets of
2793
+ // members the bridge is allowed to expose for that component, so we verify the member is present
2794
+ // there before forwarding. See W-23641816.
2795
+ function assertPublicBridgeMember(vm, memberMap, memberName) {
2796
+ if (lwcRuntimeFlags.DISABLE_BRIDGE_ELEMENT_PROPERTY_GUARD) {
2797
+ return;
2798
+ }
2799
+ if (!hasOwnProperty$1.call(memberMap, memberName)) {
2800
+ throw new TypeError(`Invalid attempt to access "${memberName}" on <${vm.def.name}>. This member is not a public property or method of the component.`);
2801
+ }
2802
+ }
2808
2803
  function createGetter(key) {
2809
2804
  let fn = cachedGetterByKey[key];
2810
2805
  if (isUndefined$1(fn)) {
2811
2806
  fn = cachedGetterByKey[key] = function () {
2812
2807
  const vm = getAssociatedVM(this);
2808
+ assertPublicBridgeMember(vm, vm.def.props, key);
2813
2809
  const { getHook } = vm;
2814
2810
  return getHook(vm.component, key);
2815
2811
  };
@@ -2821,6 +2817,7 @@
2821
2817
  if (isUndefined$1(fn)) {
2822
2818
  fn = cachedSetterByKey[key] = function (newValue) {
2823
2819
  const vm = getAssociatedVM(this);
2820
+ assertPublicBridgeMember(vm, vm.def.props, key);
2824
2821
  const { setHook } = vm;
2825
2822
  newValue = getReadOnlyProxy(newValue);
2826
2823
  setHook(vm.component, key, newValue);
@@ -2831,6 +2828,7 @@
2831
2828
  function createMethodCaller(methodName) {
2832
2829
  return function () {
2833
2830
  const vm = getAssociatedVM(this);
2831
+ assertPublicBridgeMember(vm, vm.def.methods, methodName);
2834
2832
  const { callHook, component } = vm;
2835
2833
  const fn = component[methodName];
2836
2834
  return callHook(vm.component, fn, ArraySlice.call(arguments));
@@ -2838,22 +2836,26 @@
2838
2836
  }
2839
2837
  function createAttributeChangedCallback(attributeToPropMap, superAttributeChangedCallback) {
2840
2838
  return function attributeChangedCallback(attrName, oldValue, newValue) {
2841
- if (oldValue === newValue) {
2842
- // Ignore same values.
2843
- return;
2844
- }
2845
- const propName = attributeToPropMap[attrName];
2846
- if (isUndefined$1(propName)) {
2847
- if (!isUndefined$1(superAttributeChangedCallback)) {
2848
- // delegate unknown attributes to the super.
2849
- // Typescript does not like it when you treat the `arguments` object as an array
2850
- // @ts-expect-error type-mismatch
2851
- superAttributeChangedCallback.apply(this, arguments);
2839
+ // W-17420330 & W-23590585
2840
+ if (this instanceof BaseBridgeElement ||
2841
+ lwcRuntimeFlags.ENABLE_LEGACY_ATTRIBUTE_CHANGED_CALLBACK) {
2842
+ if (oldValue === newValue) {
2843
+ // Ignore same values.
2844
+ return;
2852
2845
  }
2853
- return;
2846
+ const propName = attributeToPropMap[attrName];
2847
+ if (isUndefined$1(propName)) {
2848
+ if (!isUndefined$1(superAttributeChangedCallback)) {
2849
+ // delegate unknown attributes to the super.
2850
+ // Typescript does not like it when you treat the `arguments` object as an array
2851
+ // @ts-expect-error type-mismatch
2852
+ superAttributeChangedCallback.apply(this, arguments);
2853
+ }
2854
+ return;
2855
+ }
2856
+ // Reflect attribute change to the corresponding property when changed from outside.
2857
+ this[propName] = newValue;
2854
2858
  }
2855
- // Reflect attribute change to the corresponding property when changed from outside.
2856
- this[propName] = newValue;
2857
2859
  };
2858
2860
  }
2859
2861
  function HTMLBridgeElementFactory(SuperClass, publicProperties, methods, observedFields, proto, hasCustomSuperClass) {
@@ -2956,11 +2958,12 @@
2956
2958
  },
2957
2959
  }, [api.t(content)]);
2958
2960
  }
2959
- // TODO [#3733]: remove support for legacy scope tokens
2961
+ // TODO [#3733]: remove this dead legacy-scope-token plumbing (the ENABLE_LEGACY_SCOPE_TOKENS
2962
+ // runtime flag has been removed, so the `legacy` argument is now always false).
2960
2963
  function updateStylesheetToken(vm, template, legacy) {
2961
2964
  const { elm, context, renderMode, shadowMode, renderer: { getClassList, removeAttribute, setAttribute }, } = vm;
2962
2965
  const { stylesheets: newStylesheets } = template;
2963
- const newStylesheetToken = legacy ? template.legacyStylesheetToken : template.stylesheetToken;
2966
+ const newStylesheetToken = template.stylesheetToken;
2964
2967
  const { stylesheets: newVmStylesheets } = vm;
2965
2968
  const isSyntheticShadow = renderMode === 1 /* RenderMode.Shadow */ && shadowMode === 1 /* ShadowMode.Synthetic */;
2966
2969
  const { hasScopedStyles } = context;
@@ -2971,12 +2974,7 @@
2971
2974
  let oldToken;
2972
2975
  let oldHasTokenInClass;
2973
2976
  let oldHasTokenInAttribute;
2974
- if (legacy) {
2975
- oldToken = context.legacyStylesheetToken;
2976
- oldHasTokenInClass = context.hasLegacyTokenInClass;
2977
- oldHasTokenInAttribute = context.hasLegacyTokenInAttribute;
2978
- }
2979
- else {
2977
+ {
2980
2978
  oldToken = context.stylesheetToken;
2981
2979
  oldHasTokenInClass = context.hasTokenInClass;
2982
2980
  oldHasTokenInAttribute = context.hasTokenInAttribute;
@@ -3009,12 +3007,7 @@
3009
3007
  }
3010
3008
  }
3011
3009
  // Update the styling tokens present on the context object.
3012
- if (legacy) {
3013
- context.legacyStylesheetToken = newToken;
3014
- context.hasLegacyTokenInClass = newHasTokenInClass;
3015
- context.hasLegacyTokenInAttribute = newHasTokenInAttribute;
3016
- }
3017
- else {
3010
+ {
3018
3011
  context.stylesheetToken = newToken;
3019
3012
  context.hasTokenInClass = newHasTokenInClass;
3020
3013
  context.hasTokenInAttribute = newHasTokenInAttribute;
@@ -3082,6 +3075,9 @@
3082
3075
  function getStylesheetsContent(vm, template) {
3083
3076
  const { stylesheets, stylesheetToken } = template;
3084
3077
  const { stylesheets: vmStylesheets } = vm;
3078
+ if (!isUndefined$1(stylesheetToken) && !isValidScopeToken(stylesheetToken)) {
3079
+ throw new Error('stylesheet token must be a valid string');
3080
+ }
3085
3081
  const hasTemplateStyles = hasStyles(stylesheets);
3086
3082
  const hasVmStyles = hasStyles(vmStylesheets);
3087
3083
  if (hasTemplateStyles) {
@@ -3119,11 +3115,12 @@
3119
3115
  * @param owner
3120
3116
  * @param legacy
3121
3117
  */
3122
- // TODO [#3733]: remove support for legacy scope tokens
3118
+ // TODO [#3733]: remove this dead legacy-scope-token plumbing (the ENABLE_LEGACY_SCOPE_TOKENS
3119
+ // runtime flag has been removed, so the `legacy` argument is now always false).
3123
3120
  function getScopeTokenClass(owner, legacy) {
3124
3121
  const { cmpTemplate, context } = owner;
3125
3122
  return ((context.hasScopedStyles &&
3126
- (legacy ? cmpTemplate?.legacyStylesheetToken : cmpTemplate?.stylesheetToken)) ||
3123
+ (cmpTemplate?.stylesheetToken)) ||
3127
3124
  null);
3128
3125
  }
3129
3126
  function getNearestNativeShadowComponent(vm) {
@@ -3167,7 +3164,7 @@
3167
3164
  return false;
3168
3165
  }
3169
3166
  // See W-16614556
3170
- return lwcRuntimeFlags.DISABLE_SCOPE_TOKEN_VALIDATION || VALID_SCOPE_TOKEN_REGEX.test(token);
3167
+ return VALID_SCOPE_TOKEN_REGEX.test(token);
3171
3168
  }
3172
3169
 
3173
3170
  /*
@@ -3176,34 +3173,16 @@
3176
3173
  * SPDX-License-Identifier: MIT
3177
3174
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3178
3175
  */
3179
- const supportsWeakRefs = typeof WeakRef === 'function' && typeof FinalizationRegistry === 'function';
3180
- // In browsers that doesn't support WeakRefs, the values will still leak, but at least the keys won't
3181
- class LegacyWeakMultiMap {
3182
- constructor() {
3183
- this._map = new WeakMap();
3184
- }
3185
- _getValues(key) {
3186
- let values = this._map.get(key);
3187
- if (isUndefined$1(values)) {
3188
- values = new Set();
3189
- this._map.set(key, values);
3190
- }
3191
- return values;
3192
- }
3193
- get(key) {
3194
- return this._getValues(key);
3195
- }
3196
- add(key, vm) {
3197
- const set = this._getValues(key);
3198
- set.add(vm);
3199
- }
3200
- delete(key) {
3201
- this._map.delete(key);
3202
- }
3203
- }
3204
- // This implementation relies on the WeakRef/FinalizationRegistry proposal.
3205
- // For some background, see: https://github.com/tc39/proposal-weakrefs
3206
- class ModernWeakMultiMap {
3176
+ /**
3177
+ * A map where the keys are weakly held and the values are a Set that are also each weakly held.
3178
+ * The goal is to avoid leaking the values, which is what would happen with a WeakMap<K, Set<V>>.
3179
+ *
3180
+ * Note that this is currently only intended to be used in dev/PRODDEBUG environments.
3181
+ *
3182
+ * This implementation relies on WeakRefs and FinalizationRegistry.
3183
+ * For some background, see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/WeakRef
3184
+ */
3185
+ class WeakMultiMap {
3207
3186
  constructor() {
3208
3187
  this._map = new WeakMap();
3209
3188
  this._registry = new FinalizationRegistry((weakRefs) => {
@@ -3239,8 +3218,12 @@
3239
3218
  }
3240
3219
  add(key, value) {
3241
3220
  const weakRefs = this._getWeakRefs(key);
3242
- // We could check for duplicate values here, but it doesn't seem worth it.
3243
- // We transform the output into a Set anyway
3221
+ // Skip adding if already present
3222
+ for (const weakRef of weakRefs) {
3223
+ if (weakRef.deref() === value) {
3224
+ return;
3225
+ }
3226
+ }
3244
3227
  ArrayPush$1.call(weakRefs, new WeakRef(value));
3245
3228
  // It's important here not to leak the second argument, which is the "held value." The FinalizationRegistry
3246
3229
  // effectively creates a strong reference between the first argument (the "target") and the held value. When
@@ -3255,7 +3238,6 @@
3255
3238
  this._map.delete(key);
3256
3239
  }
3257
3240
  }
3258
- const WeakMultiMap = supportsWeakRefs ? ModernWeakMultiMap : LegacyWeakMultiMap;
3259
3241
  let swappedStyleMap = /*@__PURE__@*/ new WeakMap();
3260
3242
  // The important thing here is the weak values – VMs are transient (one per component instance) and should be GC'ed,
3261
3243
  // so we don't want to create strong references to them.
@@ -3352,6 +3334,13 @@
3352
3334
  return proto;
3353
3335
  }
3354
3336
  function createComponentDef(Ctor) {
3337
+ // Enforce component-level feature flag if provided at compile time
3338
+ if (!isComponentFeatureEnabled(Ctor)) {
3339
+ const metadata = getComponentMetadata(Ctor);
3340
+ const componentName = Ctor.name || metadata?.sel || 'Unknown';
3341
+ const componentFeatureFlagPath = metadata?.componentFeatureFlag?.path || 'Unknown';
3342
+ throw new Error(`Component ${componentName} is disabled by the feature flag at ${componentFeatureFlagPath}.`);
3343
+ }
3355
3344
  const { shadowSupportMode: ctorShadowSupportMode, renderMode: ctorRenderMode, formAssociated: ctorFormAssociated, } = Ctor;
3356
3345
  const decoratorsMeta = getDecoratorsMeta(Ctor);
3357
3346
  const { apiFields, apiFieldsConfig, apiMethods, wiredFields, wiredMethods, observedFields } = decoratorsMeta;
@@ -3563,26 +3552,60 @@
3563
3552
  * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
3564
3553
  */
3565
3554
  const sanitizedHtmlContentSymbol = Symbol('lwc-get-sanitized-html-content');
3555
+ // W-23680734: brand "trusted sanitized HTML" objects by IDENTITY, not by a structural
3556
+ // property/symbol. The previous brand check (`sanitizedHtmlContentSymbol in value`) and read
3557
+ // (`value[sanitizedHtmlContentSymbol]`) resolve through `value`'s own property semantics, so an
3558
+ // object with caller-controlled property behavior can report the brand and yield markup it does
3559
+ // not legitimately hold — trust based on shape rather than provenance.
3560
+ //
3561
+ // A WeakMap keyed on the wrapper's identity closes that gap: `WeakMap.prototype.has`/`get`
3562
+ // perform an internal-slot identity lookup that does not consult the object's property handlers,
3563
+ // and only wrappers we created were ever registered — so any other object is `false` regardless
3564
+ // of its shape. This mirrors the existing identity-based trust sets for signals/context in
3565
+ // `@lwc/shared` (`isTrustedSignal`, `isTrustedContext`).
3566
+ const sanitizedContentToString = new WeakMap();
3566
3567
  function isSanitizedHtmlContent(object) {
3567
- return isObject(object) && !isNull(object) && sanitizedHtmlContentSymbol in object;
3568
+ if (!isObject(object) || isNull(object)) {
3569
+ return false;
3570
+ }
3571
+ // Kill-switch: when the flag is set, fall back to the legacy structural symbol brand.
3572
+ // Present so the hardening can be disabled at runtime if it regresses a legit integration;
3573
+ // the default (flag unset) is the safe, identity-based check.
3574
+ if (lwcRuntimeFlags.DISABLE_SANITIZED_HTML_CONTENT_IDENTITY_CHECK) {
3575
+ return sanitizedHtmlContentSymbol in object;
3576
+ }
3577
+ // Identity check — only wrappers we created are members, independent of `object`'s shape.
3578
+ return sanitizedContentToString.has(object);
3579
+ }
3580
+ function getSanitizedContent(object) {
3581
+ if (lwcRuntimeFlags.DISABLE_SANITIZED_HTML_CONTENT_IDENTITY_CHECK) {
3582
+ return object[sanitizedHtmlContentSymbol];
3583
+ }
3584
+ // Read the sanitized string from OUR map by identity, never from a property access on
3585
+ // `object` (whose semantics may be caller-controlled).
3586
+ return sanitizedContentToString.get(object);
3568
3587
  }
3569
3588
  function unwrapIfNecessary(object) {
3570
- return isSanitizedHtmlContent(object) ? object[sanitizedHtmlContentSymbol] : object;
3589
+ return isSanitizedHtmlContent(object) ? getSanitizedContent(object) : object;
3571
3590
  }
3572
3591
  /**
3573
3592
  * Wrap a pre-sanitized string designated for `.innerHTML` via `lwc:inner-html`
3574
- * as an object with a Symbol that only we have access to.
3593
+ * as an object branded by identity in a module-private WeakMap that only we have access to.
3575
3594
  * @param sanitizedString
3576
3595
  * @returns SanitizedHtmlContent
3577
3596
  */
3578
3597
  function createSanitizedHtmlContent(sanitizedString) {
3579
- return create(null, {
3598
+ // The wrapper keeps the non-enumerable symbol property so the legacy kill-switch path and
3599
+ // any structural consumers still work; the authoritative brand is WeakMap membership.
3600
+ const wrapper = create(null, {
3580
3601
  [sanitizedHtmlContentSymbol]: {
3581
3602
  value: sanitizedString,
3582
3603
  configurable: false,
3583
3604
  writable: false,
3584
3605
  },
3585
3606
  });
3607
+ sanitizedContentToString.set(wrapper, sanitizedString);
3608
+ return wrapper;
3586
3609
  }
3587
3610
  /**
3588
3611
  * Safely call setProperty on an Element while handling any SanitizedHtmlContent objects correctly
@@ -3598,7 +3621,7 @@
3598
3621
  if ((key === 'innerHTML' || key === 'outerHTML') && !isUndefined$1(value)) {
3599
3622
  if (isSanitizedHtmlContent(value)) {
3600
3623
  // it's a SanitizedHtmlContent object
3601
- setProperty(elm, key, value[sanitizedHtmlContentSymbol]);
3624
+ setProperty(elm, key, getSanitizedContent(value));
3602
3625
  }
3603
3626
  }
3604
3627
  else {
@@ -4465,7 +4488,7 @@
4465
4488
  function applyStyleScoping(elm, owner, renderer) {
4466
4489
  const { getClassList } = renderer;
4467
4490
  // Set the class name for `*.scoped.css` style scoping.
4468
- const scopeToken = getScopeTokenClass(owner, /* legacy */ false);
4491
+ const scopeToken = getScopeTokenClass(owner);
4469
4492
  if (!isNull(scopeToken)) {
4470
4493
  if (!isValidScopeToken(scopeToken)) {
4471
4494
  // See W-16614556
@@ -4475,31 +4498,12 @@
4475
4498
  // probably we should have a renderer api for just the add operation
4476
4499
  getClassList(elm).add(scopeToken);
4477
4500
  }
4478
- // TODO [#3733]: remove support for legacy scope tokens
4479
- if (lwcRuntimeFlags.ENABLE_LEGACY_SCOPE_TOKENS) {
4480
- const legacyScopeToken = getScopeTokenClass(owner, /* legacy */ true);
4481
- if (!isNull(legacyScopeToken)) {
4482
- if (!isValidScopeToken(legacyScopeToken)) {
4483
- // See W-16614556
4484
- throw new Error('stylesheet token must be a valid string');
4485
- }
4486
- // TODO [#2762]: this dot notation with add is probably problematic
4487
- // probably we should have a renderer api for just the add operation
4488
- getClassList(elm).add(legacyScopeToken);
4489
- }
4490
- }
4491
4501
  // Set property element for synthetic shadow DOM style scoping.
4492
4502
  const { stylesheetToken: syntheticToken } = owner.context;
4493
4503
  if (owner.shadowMode === 1 /* ShadowMode.Synthetic */) {
4494
4504
  if (!isUndefined$1(syntheticToken)) {
4495
4505
  elm.$shadowToken$ = syntheticToken;
4496
4506
  }
4497
- if (lwcRuntimeFlags.ENABLE_LEGACY_SCOPE_TOKENS) {
4498
- const legacyToken = owner.context.legacyStylesheetToken;
4499
- if (!isUndefined$1(legacyToken)) {
4500
- elm.$legacyShadowToken$ = legacyToken;
4501
- }
4502
- }
4503
4507
  }
4504
4508
  }
4505
4509
  function applyDomManual(elm, vnode) {
@@ -4658,7 +4662,6 @@
4658
4662
  }
4659
4663
  function createKeyToOldIdx(children, beginIdx, endIdx) {
4660
4664
  const map = {};
4661
- // TODO [#1637]: simplify this by assuming that all vnodes has keys
4662
4665
  for (let j = beginIdx; j <= endIdx; ++j) {
4663
4666
  const ch = children[j];
4664
4667
  if (isVNode(ch)) {
@@ -5027,20 +5030,19 @@
5027
5030
  function c(sel, Ctor, data, children = EmptyArray) {
5028
5031
  const vmBeingRendered = getVMBeingRendered();
5029
5032
  const { key, slotAssignment } = data;
5030
- let elm, aChildren, vm;
5031
5033
  const vnode = {
5032
5034
  type: 3 /* VNodeType.CustomElement */,
5033
5035
  sel,
5034
5036
  data,
5035
5037
  children,
5036
- elm,
5038
+ elm: undefined,
5037
5039
  key,
5038
5040
  slotAssignment,
5039
5041
  ctor: Ctor,
5040
5042
  owner: vmBeingRendered,
5041
5043
  mode: 'open', // TODO [#1294]: this should be defined in Ctor
5042
- aChildren,
5043
- vm,
5044
+ aChildren: undefined,
5045
+ vm: undefined,
5044
5046
  };
5045
5047
  addVNodeToChildLWC(vnode);
5046
5048
  return vnode;
@@ -5099,25 +5101,23 @@
5099
5101
  }
5100
5102
  // [t]ext node
5101
5103
  function t(text) {
5102
- let key, elm;
5103
5104
  return {
5104
5105
  type: 0 /* VNodeType.Text */,
5105
5106
  sel: '__text__',
5106
5107
  text,
5107
- elm,
5108
- key,
5108
+ elm: undefined,
5109
+ key: undefined,
5109
5110
  owner: getVMBeingRendered(),
5110
5111
  };
5111
5112
  }
5112
5113
  // [co]mment node
5113
5114
  function co(text) {
5114
- let elm, key;
5115
5115
  return {
5116
5116
  type: 1 /* VNodeType.Comment */,
5117
5117
  sel: '__comment__',
5118
5118
  text,
5119
- elm,
5120
- key,
5119
+ elm: undefined,
5120
+ key: undefined,
5121
5121
  owner: getVMBeingRendered(),
5122
5122
  };
5123
5123
  }
@@ -5408,10 +5408,9 @@
5408
5408
  function buildParseFragmentFn(createFragmentFn) {
5409
5409
  return function parseFragment(strings, ...keys) {
5410
5410
  return function applyFragmentParts(parts) {
5411
- const { context: { hasScopedStyles, stylesheetToken, legacyStylesheetToken }, shadowMode, renderer, } = getVMBeingRendered();
5411
+ const { context: { hasScopedStyles, stylesheetToken }, shadowMode, renderer, } = getVMBeingRendered();
5412
5412
  const hasStyleToken = !isUndefined$1(stylesheetToken);
5413
5413
  const isSyntheticShadow = shadowMode === 1 /* ShadowMode.Synthetic */;
5414
- const hasLegacyToken = lwcRuntimeFlags.ENABLE_LEGACY_SCOPE_TOKENS && !isUndefined$1(legacyStylesheetToken);
5415
5414
  let cacheKey = 0;
5416
5415
  if (hasStyleToken && hasScopedStyles) {
5417
5416
  cacheKey |= 1 /* FragmentCacheKey.HAS_SCOPED_STYLE */;
@@ -5429,15 +5428,12 @@
5429
5428
  }
5430
5429
  // See W-16614556
5431
5430
  // TODO [#2826]: freeze the template object
5432
- if ((hasStyleToken && !isValidScopeToken(stylesheetToken)) ||
5433
- (hasLegacyToken && !isValidScopeToken(legacyStylesheetToken))) {
5431
+ if (hasStyleToken && !isValidScopeToken(stylesheetToken)) {
5434
5432
  throw new Error('stylesheet token must be a valid string');
5435
5433
  }
5436
- // If legacy stylesheet tokens are required, then add them to the rendered string
5437
- const stylesheetTokenToRender = stylesheetToken + (hasLegacyToken ? ` ${legacyStylesheetToken}` : '');
5438
- const classToken = hasScopedStyles && hasStyleToken ? ' ' + stylesheetTokenToRender : '';
5439
- const classAttrToken = hasScopedStyles && hasStyleToken ? ` class="${stylesheetTokenToRender}"` : '';
5440
- const attrToken = hasStyleToken && isSyntheticShadow ? ' ' + stylesheetTokenToRender : '';
5434
+ const classToken = hasScopedStyles && hasStyleToken ? ' ' + stylesheetToken : '';
5435
+ const classAttrToken = hasScopedStyles && hasStyleToken ? ` class="${stylesheetToken}"` : '';
5436
+ const attrToken = hasStyleToken && isSyntheticShadow ? ' ' + stylesheetToken : '';
5441
5437
  // In the browser, we provide the entire class attribute as a perf optimization to avoid applying it on mount.
5442
5438
  // The remaining class expression will be applied when the static parts are mounted.
5443
5439
  // In SSR, the entire class attribute (expression included) is assembled along with the fragment.
@@ -5477,14 +5473,29 @@
5477
5473
  };
5478
5474
  };
5479
5475
  }
5476
+ // W-23814957: static-content markup is assembled here and assigned to `innerHTML` by
5477
+ // `createFragment` (see @lwc/engine-dom). The `lwc:inner-html` directive routes its markup through
5478
+ // the overridable `sanitizeHtmlContent` hook before it becomes DOM; the static-content path does
5479
+ // not. When the opt-in flag is enabled, route the exact string that will be assigned to `innerHTML`
5480
+ // through the same hook, so both paths are consistent. This is applied per fragment variant (rather
5481
+ // than once on the pre-assembled markup) so the SVG variant is processed with its `<svg>` wrapper in
5482
+ // place — i.e. in the same parsing context (namespace) `createFragment` will use. Off by default to
5483
+ // preserve existing behavior (and because enabling it requires a hook that preserves the
5484
+ // engine-generated scope tokens embedded in the markup).
5485
+ function sanitizeFragmentIfEnabled(html) {
5486
+ if (lwcRuntimeFlags.ENABLE_PARSE_FRAGMENT_SANITIZATION) {
5487
+ return sanitizeHtmlContent(html);
5488
+ }
5489
+ return html;
5490
+ }
5480
5491
  // Note: at the moment this code executes, we don't have a renderer yet.
5481
5492
  const parseFragment = buildParseFragmentFn((html, renderer) => {
5482
5493
  const { createFragment } = renderer;
5483
- return createFragment(html);
5494
+ return createFragment(sanitizeFragmentIfEnabled(html));
5484
5495
  });
5485
5496
  const parseSVGFragment = buildParseFragmentFn((html, renderer) => {
5486
5497
  const { createFragment, getFirstChild } = renderer;
5487
- const fragment = createFragment('<svg>' + html + '</svg>');
5498
+ const fragment = createFragment(sanitizeFragmentIfEnabled('<svg>' + html + '</svg>'));
5488
5499
  return getFirstChild(fragment);
5489
5500
  });
5490
5501
  function evaluateTemplate(vm, html) {
@@ -5521,9 +5532,6 @@
5521
5532
  context.hasScopedStyles = computeHasScopedStyles(html, vm);
5522
5533
  // Update the scoping token on the host element.
5523
5534
  updateStylesheetToken(vm, html, /* legacy */ false);
5524
- if (lwcRuntimeFlags.ENABLE_LEGACY_SCOPE_TOKENS) {
5525
- updateStylesheetToken(vm, html, /* legacy */ true);
5526
- }
5527
5535
  // Evaluate, create stylesheet and cache the produced VNode for future
5528
5536
  // re-rendering.
5529
5537
  const stylesheetsContent = getStylesheetsContent(vm, html);
@@ -5538,10 +5546,18 @@
5538
5546
  vm.velements = [];
5539
5547
  // Set the global flag that template is being updated
5540
5548
  isUpdatingTemplate = true;
5541
- vnodes = html.call(undefined, api, component, cmpSlots, context.tplCache);
5549
+ // `html.call(...)` reads a `call` property off the compiled template function. A
5550
+ // component can shadow that property with an own value, causing the engine to invoke
5551
+ // the component-supplied function (with the privileged template `api`) instead of
5552
+ // `Function.prototype.call`. Invoking through the intrinsic `Reflect.apply` uses the
5553
+ // function's internal call behavior and ignores any own `call` property. Gated behind
5554
+ // a flag so the hardened path can be rolled out separately from the default behavior.
5555
+ vnodes = lwcRuntimeFlags.ENABLE_INTRINSIC_TEMPLATE_INVOCATION
5556
+ ? Reflect.apply(html, undefined, [api, component, cmpSlots, context.tplCache])
5557
+ : html.call(undefined, api, component, cmpSlots, context.tplCache);
5542
5558
  const { styleVNodes } = context;
5543
5559
  if (!isNull(styleVNodes)) {
5544
- // It's important here not to mutate the underlying `vnodes` returned from `html.call()`.
5560
+ // It's important here not to mutate the underlying `vnodes` returned from the template invocation.
5545
5561
  // The reason for this is because, due to the static content optimization, the vnodes array
5546
5562
  // may be a static array shared across multiple component instances. E.g. this occurs in the
5547
5563
  // case of an empty `<template></template>` in a `component.html` file, due to the underlying
@@ -5600,16 +5616,11 @@
5600
5616
  try {
5601
5617
  // job
5602
5618
  const result = new Ctor();
5603
- // Check indirectly if the constructor result is an instance of LightningElement.
5604
- // When Locker is enabled, the "instanceof" operator would not work since Locker Service
5605
- // provides its own implementation of LightningElement, so we indirectly check
5606
- // if the base constructor is invoked by accessing the component on the vm.
5607
- // When the DISABLE_LOCKER_VALIDATION gate is false or LEGACY_LOCKER_ENABLED is false,
5608
- // then the instanceof LightningElement can be used.
5609
- const useLegacyConstructorCheck = !lwcRuntimeFlags.DISABLE_LEGACY_VALIDATION || lwcRuntimeFlags.LEGACY_LOCKER_ENABLED;
5610
- const isInvalidConstructor = useLegacyConstructorCheck
5611
- ? vmBeingConstructed.component !== result
5612
- : !(result instanceof LightningElement);
5619
+ // When strict, reject when the constructor returns a *native* HTMLElement — that is,
5620
+ // result instanceof HTMLElement.
5621
+ const useStrictValidation = !lwcRuntimeFlags.DISABLE_STRICT_VALIDATION && true;
5622
+ const isMismatchedConstructor = vmBeingConstructed.component !== result;
5623
+ const isInvalidConstructor = isMismatchedConstructor || (useStrictValidation && result instanceof HTMLElement);
5613
5624
  if (isInvalidConstructor) {
5614
5625
  throw new TypeError('Invalid component constructor, the class should extend LightningElement.');
5615
5626
  }
@@ -5689,13 +5700,24 @@
5689
5700
  const metadata = registeredComponentMap.get(Ctor);
5690
5701
  const apiVersion = metadata?.apiVersion;
5691
5702
  if (isUndefined$1(apiVersion)) {
5692
- // This should only occur in our Karma tests; in practice every component
5703
+ // This should only occur in our integration tests; in practice every component
5693
5704
  // is registered, and so this code path should not get hit. But to be safe,
5694
5705
  // return the lowest possible version.
5695
5706
  return LOWEST_API_VERSION;
5696
5707
  }
5697
5708
  return apiVersion;
5698
5709
  }
5710
+ function supportsSyntheticElementInternals(Ctor) {
5711
+ return registeredComponentMap.get(Ctor)?.enableSyntheticElementInternals || false;
5712
+ }
5713
+ function isComponentFeatureEnabled(Ctor) {
5714
+ const flag = registeredComponentMap.get(Ctor)?.componentFeatureFlag;
5715
+ // Default to true if not provided
5716
+ return flag?.value !== false;
5717
+ }
5718
+ function getComponentMetadata(Ctor) {
5719
+ return registeredComponentMap.get(Ctor);
5720
+ }
5699
5721
  function getTemplateReactiveObserver(vm) {
5700
5722
  const reactiveObserver = createReactiveObserver(() => {
5701
5723
  const { isDirty } = vm;
@@ -5780,6 +5802,9 @@
5780
5802
  };
5781
5803
 
5782
5804
  var _ContextBinding_renderer, _ContextBinding_providedContextVarieties, _ContextBinding_elm;
5805
+ // Provider-listener teardowns per VM, registered on connect and invoked on disconnect. Without this
5806
+ // the listener closures retain the detached component after every mount/unmount.
5807
+ const contextProviderUnregisters = new WeakMap();
5783
5808
  class ContextBinding {
5784
5809
  constructor(vm, component, providedContextVarieties) {
5785
5810
  _ContextBinding_renderer.set(this, void 0);
@@ -5790,11 +5815,21 @@
5790
5815
  __classPrivateFieldSet(this, _ContextBinding_elm, vm.elm);
5791
5816
  __classPrivateFieldSet(this, _ContextBinding_providedContextVarieties, providedContextVarieties);
5792
5817
  // Register the component as a context provider.
5793
- __classPrivateFieldGet(this, _ContextBinding_renderer, "f").registerContextProvider(__classPrivateFieldGet(this, _ContextBinding_elm, "f"), ContextEventName, (contextConsumer) => {
5818
+ const unregister = __classPrivateFieldGet(this, _ContextBinding_renderer, "f").registerContextProvider(__classPrivateFieldGet(this, _ContextBinding_elm, "f"), ContextEventName, (contextConsumer) => {
5794
5819
  // This callback is invoked when the provided context is consumed somewhere down
5795
5820
  // in the component's subtree.
5796
5821
  return contextConsumer.setNewContext(__classPrivateFieldGet(this, _ContextBinding_providedContextVarieties, "f"));
5797
5822
  });
5823
+ // deprecated engine-server doesn't provide `unregister`
5824
+ if (unregister) {
5825
+ const unregisters = contextProviderUnregisters.get(vm);
5826
+ if (isUndefined$1(unregisters)) {
5827
+ contextProviderUnregisters.set(vm, [unregister]);
5828
+ }
5829
+ else {
5830
+ ArrayPush$1.call(unregisters, unregister);
5831
+ }
5832
+ }
5798
5833
  }
5799
5834
  provideContext(contextVariety, providedContextSignal) {
5800
5835
  if (__classPrivateFieldGet(this, _ContextBinding_providedContextVarieties, "f").has(contextVariety)) {
@@ -5821,42 +5856,60 @@
5821
5856
  }
5822
5857
  _ContextBinding_renderer = new WeakMap(), _ContextBinding_providedContextVarieties = new WeakMap(), _ContextBinding_elm = new WeakMap();
5823
5858
  function connectContext(vm) {
5859
+ // Non-decorated objects
5860
+ connect(vm, keys(vm.cmpFields), vm.cmpFields);
5861
+ // Decorated objects like @api context
5862
+ connect(vm, keys(vm.cmpProps), vm.cmpProps);
5863
+ }
5864
+ function disconnectContext(vm) {
5865
+ // Non-decorated objects
5866
+ disconnect(vm, keys(vm.cmpFields), vm.cmpFields);
5867
+ // Decorated objects like @api context
5868
+ disconnect(vm, keys(vm.cmpProps), vm.cmpProps);
5869
+ // Remove the provider listeners registered on connect.
5870
+ const unregisters = contextProviderUnregisters.get(vm);
5871
+ if (!isUndefined$1(unregisters)) {
5872
+ for (let i = 0; i < unregisters.length; i++) {
5873
+ unregisters[i]();
5874
+ }
5875
+ contextProviderUnregisters.delete(vm);
5876
+ }
5877
+ }
5878
+ function connect(vm, enumerableKeys, contextContainer) {
5824
5879
  const contextKeys = getContextKeys();
5825
5880
  if (isUndefined$1(contextKeys)) {
5826
5881
  return;
5827
5882
  }
5828
5883
  const { connectContext } = contextKeys;
5829
5884
  const { component } = vm;
5830
- const enumerableKeys = keys(getPrototypeOf$1(component));
5831
- const contextfulKeys = ArrayFilter.call(enumerableKeys, (enumerableKey) => isTrustedContext(component[enumerableKey]));
5885
+ const contextfulKeys = ArrayFilter.call(enumerableKeys, (enumerableKey) => isTrustedContext(contextContainer[enumerableKey]));
5832
5886
  if (contextfulKeys.length === 0) {
5833
5887
  return;
5834
5888
  }
5835
5889
  const providedContextVarieties = new Map();
5836
5890
  try {
5837
5891
  for (let i = 0; i < contextfulKeys.length; i++) {
5838
- component[contextfulKeys[i]][connectContext](new ContextBinding(vm, component, providedContextVarieties));
5892
+ contextContainer[contextfulKeys[i]][connectContext](new ContextBinding(vm, component, providedContextVarieties));
5839
5893
  }
5840
5894
  }
5841
5895
  catch (err) {
5842
5896
  logWarnOnce(`Attempted to connect to trusted context but received the following error: ${err.message}`);
5843
5897
  }
5844
5898
  }
5845
- function disconnectContext(vm) {
5899
+ function disconnect(vm, enumerableKeys, contextContainer) {
5846
5900
  const contextKeys = getContextKeys();
5847
5901
  if (!contextKeys) {
5848
5902
  return;
5849
5903
  }
5850
5904
  const { disconnectContext } = contextKeys;
5851
5905
  const { component } = vm;
5852
- const enumerableKeys = keys(getPrototypeOf$1(component));
5853
- const contextfulKeys = ArrayFilter.call(enumerableKeys, (enumerableKey) => isTrustedContext(component[enumerableKey]));
5906
+ const contextfulKeys = ArrayFilter.call(enumerableKeys, (enumerableKey) => isTrustedContext(contextContainer[enumerableKey]));
5854
5907
  if (contextfulKeys.length === 0) {
5855
5908
  return;
5856
5909
  }
5857
5910
  try {
5858
5911
  for (let i = 0; i < contextfulKeys.length; i++) {
5859
- component[contextfulKeys[i]][disconnectContext](component);
5912
+ contextContainer[contextfulKeys[i]][disconnectContext](component);
5860
5913
  }
5861
5914
  }
5862
5915
  catch (err) {
@@ -5970,7 +6023,6 @@
5970
6023
  // Properties set right after VM creation.
5971
6024
  tro: null,
5972
6025
  shadowMode: null,
5973
- shadowMigrateMode: false,
5974
6026
  stylesheets: null,
5975
6027
  // Properties set by the LightningElement constructor.
5976
6028
  component: null,
@@ -5983,14 +6035,7 @@
5983
6035
  apiVersion,
5984
6036
  };
5985
6037
  vm.stylesheets = computeStylesheets(vm, def.ctor);
5986
- const computedShadowMode = computeShadowMode(def, vm.owner, renderer, hydrated);
5987
- if (lwcRuntimeFlags.ENABLE_FORCE_SHADOW_MIGRATE_MODE) {
5988
- vm.shadowMode = 0 /* ShadowMode.Native */;
5989
- vm.shadowMigrateMode = computedShadowMode === 1 /* ShadowMode.Synthetic */;
5990
- }
5991
- else {
5992
- vm.shadowMode = computedShadowMode;
5993
- }
6038
+ vm.shadowMode = computeShadowMode(def, vm.owner, renderer, hydrated);
5994
6039
  vm.tro = getTemplateReactiveObserver(vm);
5995
6040
  // We don't need to report the shadow mode if we're rendering in light DOM
5996
6041
  if (isReportingEnabled() && vm.renderMode === 1 /* RenderMode.Shadow */) {
@@ -6060,7 +6105,7 @@
6060
6105
  }
6061
6106
  const { isSyntheticShadowDefined } = renderer;
6062
6107
  let shadowMode;
6063
- if (isSyntheticShadowDefined || lwcRuntimeFlags.ENABLE_FORCE_SHADOW_MIGRATE_MODE) {
6108
+ if (isSyntheticShadowDefined) {
6064
6109
  if (def.renderMode === 0 /* RenderMode.Light */) {
6065
6110
  // ShadowMode.Native implies "not synthetic shadow" which is consistent with how
6066
6111
  // everything defaults to native when the synthetic shadow polyfill is unavailable.
@@ -6152,7 +6197,14 @@
6152
6197
  for (let i = 0, len = vms.length; i < len; i += 1) {
6153
6198
  const vm = vms[i];
6154
6199
  try {
6155
- rehydrate(vm);
6200
+ // We want to prevent rehydration from occurring when nodes are detached from the DOM as this can trigger
6201
+ // unintended side effects, like lifecycle methods being called multiple times.
6202
+ // For backwards compatibility, we use a flag to control the check.
6203
+ // 1. When flag is off, always rehydrate (legacy behavior)
6204
+ // 2. When flag is on, only rehydrate when the VM state is connected (fixed behavior)
6205
+ if (!lwcRuntimeFlags.DISABLE_DETACHED_REHYDRATION || vm.state === 1 /* VMState.connected */) {
6206
+ rehydrate(vm);
6207
+ }
6156
6208
  }
6157
6209
  catch (error) {
6158
6210
  if (i + 1 < len) {
@@ -6359,8 +6411,10 @@
6359
6411
  }
6360
6412
  }
6361
6413
  function runFormAssociatedCustomElementCallback(vm, faceCb, args) {
6362
- const { renderMode, shadowMode } = vm;
6363
- if (shadowMode === 1 /* ShadowMode.Synthetic */ && renderMode !== 0 /* RenderMode.Light */) {
6414
+ const { renderMode, shadowMode, def: { ctor }, } = vm;
6415
+ if (shadowMode === 1 /* ShadowMode.Synthetic */ &&
6416
+ renderMode !== 0 /* RenderMode.Light */ &&
6417
+ !supportsSyntheticElementInternals(ctor)) {
6364
6418
  throw new Error('Form associated lifecycle methods are not available in synthetic shadow. Please use native shadow or light DOM.');
6365
6419
  }
6366
6420
  invokeComponentCallback(vm, faceCb, args);
@@ -7003,7 +7057,7 @@
7003
7057
  }
7004
7058
  // ---------- Step 2: handle the scope tokens
7005
7059
  // we don't care about legacy for hydration. it's a new use case
7006
- const scopeToken = getScopeTokenClass(owner, /* legacy */ false);
7060
+ const scopeToken = getScopeTokenClass(owner);
7007
7061
  // Classnames for scoped CSS are added directly to the DOM during rendering,
7008
7062
  // or to the VDOM on the server in the case of SSR. As such, these classnames
7009
7063
  // are never present in VDOM nodes in the browser.
@@ -7568,7 +7622,7 @@
7568
7622
  }
7569
7623
  // Using a BaseUpgradableConstructor superclass here is a perf optimization to avoid
7570
7624
  // re-defining the same logic (connectedCallback, disconnectedCallback, etc.) over and over.
7571
- class UpgradableConstructor extends (BaseUpgradableConstructor) {
7625
+ class UpgradableConstructor extends BaseUpgradableConstructor {
7572
7626
  }
7573
7627
  if (isFormAssociated) {
7574
7628
  // Perf optimization - the vast majority of components have formAssociated=false,
@@ -7620,12 +7674,28 @@
7620
7674
  * const customRenderer = rendererFactory(renderer);
7621
7675
  */
7622
7676
  function rendererFactory(baseRenderer) {
7677
+ // Invariant (W-23814927): this factory is expected to build a renderer exactly once per realm — the
7678
+ // engine's own bootstrap of the base `renderer`. `globalThis.__lwcRendererFactoryInvoked` records
7679
+ // that a renderer has already been produced; when `ENABLE_RENDERER_FACTORY_GUARD` is set, any later
7680
+ // invocation is rejected. The flag and the marker are reached through globals (the ambient
7681
+ // `lwcRuntimeFlags` and `globalThis`) rather than through module-scoped variables, so this function
7682
+ // stays self-contained: its source text can be read via `Function.prototype.toString` and recreated
7683
+ // in another realm without referencing anything from this module. `typeof` keeps the check inert in a
7684
+ // realm where the flag global is absent, so recreation elsewhere is unaffected and, by default (flag
7685
+ // unset), the factory stays freely re-invocable exactly as before.
7686
+ const alreadyCreated = globalThis.__lwcRendererFactoryInvoked === true;
7687
+ globalThis.__lwcRendererFactoryInvoked = true;
7688
+ if (alreadyCreated &&
7689
+ typeof lwcRuntimeFlags !== 'undefined' &&
7690
+ lwcRuntimeFlags.ENABLE_RENDERER_FACTORY_GUARD) {
7691
+ throw new Error('Invalid invocation of rendererFactory. The renderer has already been created and cannot be recreated.');
7692
+ }
7623
7693
  // Type assertion because this is replaced by rollup with an object, not a string.
7624
7694
  // See `injectInlineRenderer` in /scripts/rollup/rollup.config.js
7625
7695
  const renderer = (function (exports) {
7626
7696
 
7627
7697
  /**
7628
- * Copyright (c) 2025 Salesforce, Inc.
7698
+ * Copyright (c) 2026 Salesforce, Inc.
7629
7699
  */
7630
7700
  /*
7631
7701
  * Copyright (c) 2018, salesforce.com, inc.
@@ -7704,7 +7774,7 @@
7704
7774
  function isNull(obj) {
7705
7775
  return obj === null;
7706
7776
  }
7707
- /** version: 8.21.1 */
7777
+ /** version: 9.4.3 */
7708
7778
 
7709
7779
  /*
7710
7780
  * Copyright (c) 2024, Salesforce, Inc.
@@ -7737,7 +7807,7 @@
7737
7807
  dispatchEvent(elm, new WireContextSubscriptionEvent(adapterContextToken, subscriptionPayload));
7738
7808
  }
7739
7809
  function registerContextProvider(elm, adapterContextToken, onContextSubscription) {
7740
- addEventListener(elm, adapterContextToken, ((evt) => {
7810
+ const listener = ((evt) => {
7741
7811
  const { setNewContext, setDisconnectedCallback } = evt;
7742
7812
  // If context subscription is successful, stop event propagation
7743
7813
  if (onContextSubscription({
@@ -7746,7 +7816,10 @@
7746
7816
  })) {
7747
7817
  evt.stopImmediatePropagation();
7748
7818
  }
7749
- }));
7819
+ });
7820
+ addEventListener(elm, adapterContextToken, listener);
7821
+ // Caller removes the listener on disconnect; otherwise its closure retains the detached element.
7822
+ return () => removeEventListener(elm, adapterContextToken, listener);
7750
7823
  }
7751
7824
 
7752
7825
  /*
@@ -7971,7 +8044,9 @@
7971
8044
  */
7972
8045
  const renderer = assign(
7973
8046
  // The base renderer will invoke the factory with null and assign additional properties that are
7974
- // shared across renderers
8047
+ // shared across renderers. This is the factory's single expected invocation per realm; it marks
8048
+ // the renderer as created so that, when ENABLE_RENDERER_FACTORY_GUARD is set, later invocations are
8049
+ // rejected (see renderer-factory.ts).
7975
8050
  rendererFactory(null),
7976
8051
  // Properties that are either not required to be sandboxed or rely on a globally shared information
7977
8052
  {
@@ -7985,6 +8060,17 @@
7985
8060
  stopTrackingMutations,
7986
8061
  });
7987
8062
 
8063
+ /*
8064
+ * Copyright (c) 2024, Salesforce, Inc.
8065
+ * All rights reserved.
8066
+ * SPDX-License-Identifier: MIT
8067
+ * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
8068
+ */
8069
+ // Like @lwc/shared, but for DOM APIs
8070
+ const ElementDescriptors = getOwnPropertyDescriptors(Element.prototype);
8071
+ ElementDescriptors.attachShadow.value;
8072
+ ElementDescriptors.shadowRoot.get;
8073
+
7988
8074
  /*
7989
8075
  * Copyright (c) 2018, salesforce.com, inc.
7990
8076
  * All rights reserved.
@@ -8032,6 +8118,12 @@
8032
8118
  if (!(element instanceof Element)) {
8033
8119
  throw new TypeError(`"hydrateComponent" expects a valid DOM element as the first parameter but instead received ${element}.`);
8034
8120
  }
8121
+ if (
8122
+ // All custom elements must have a `-` in their tag name
8123
+ !ElementDescriptors.tagName.get.call(element).includes('-') &&
8124
+ !lwcRuntimeFlags.DISABLE_HYDRATION_CUSTOM_ELEMENT_CHECK) {
8125
+ throw new TypeError(`"hydrateComponent" expects a custom element as the first parameter but instead received ${element.tagName}.`);
8126
+ }
8035
8127
  if (!isFunction$1(Ctor)) {
8036
8128
  throw new TypeError(`"hydrateComponent" expects a valid component constructor as the second parameter but instead received ${Ctor}.`);
8037
8129
  }
@@ -8132,7 +8224,8 @@
8132
8224
  disconnectRootElement(this);
8133
8225
  }
8134
8226
  attributeChangedCallback(name, oldValue, newValue) {
8135
- if (this instanceof BaseBridgeElement) {
8227
+ if (!lwcRuntimeFlags.ENABLE_LEGACY_ATTRIBUTE_CHANGED_CALLBACK ||
8228
+ this instanceof BaseBridgeElement) {
8136
8229
  // W-17420330
8137
8230
  attributeChangedCallback.call(this, name, oldValue, newValue);
8138
8231
  }
@@ -8335,17 +8428,6 @@
8335
8428
  freeze(LightningElement);
8336
8429
  seal(LightningElement.prototype);
8337
8430
 
8338
- /*
8339
- * Copyright (c) 2024, Salesforce, Inc.
8340
- * All rights reserved.
8341
- * SPDX-License-Identifier: MIT
8342
- * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
8343
- */
8344
- // Like @lwc/shared, but for DOM APIs
8345
- const ElementDescriptors = getOwnPropertyDescriptors(Element.prototype);
8346
- ElementDescriptors.attachShadow.value;
8347
- ElementDescriptors.shadowRoot.get;
8348
-
8349
8431
  /*
8350
8432
  * Copyright (c) 2018, salesforce.com, inc.
8351
8433
  * All rights reserved.
@@ -8355,6 +8437,9 @@
8355
8437
  function addEventListener(target, type, callback, options) {
8356
8438
  target.addEventListener(type, callback, options);
8357
8439
  }
8440
+ function removeEventListener(target, type, callback, options) {
8441
+ target.removeEventListener(type, callback, options);
8442
+ }
8358
8443
 
8359
8444
  /*
8360
8445
  * Copyright (c) 2023, salesforce.com, inc.
@@ -8371,7 +8456,7 @@
8371
8456
  return createContextProviderWithRegister(adapter, registerContextProvider);
8372
8457
  }
8373
8458
  function registerContextProvider(elm, adapterContextToken, onContextSubscription) {
8374
- addEventListener(elm, adapterContextToken, ((evt) => {
8459
+ const listener = ((evt) => {
8375
8460
  const { setNewContext, setDisconnectedCallback } = evt;
8376
8461
  // If context subscription is successful, stop event propagation
8377
8462
  if (onContextSubscription({
@@ -8380,9 +8465,12 @@
8380
8465
  })) {
8381
8466
  evt.stopImmediatePropagation();
8382
8467
  }
8383
- }));
8468
+ });
8469
+ addEventListener(elm, adapterContextToken, listener);
8470
+ // Caller removes the listener on disconnect; otherwise its closure retains the detached element.
8471
+ return () => removeEventListener(elm, adapterContextToken, listener);
8384
8472
  }
8385
- /** version: 8.21.1 */
8473
+ /** version: 9.4.3 */
8386
8474
 
8387
8475
  var LWC = /*#__PURE__*/Object.freeze({
8388
8476
  __proto__: null,