|
4 | 4 | * SPDX-License-Identifier: MIT |
5 | 5 | * For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT |
6 | 6 | */ |
7 | | -import { isNull, isObject, isTrustedSignal } from '@lwc/shared'; |
| 7 | +import { isNull, isObject, isTrustedSignal, legacyIsTrustedSignal } from '@lwc/shared'; |
8 | 8 | import { ReactiveObserver, valueMutated, valueObserved } from '../libs/mutation-tracker'; |
9 | 9 | import { subscribeToSignal } from '../libs/signal-tracker'; |
10 | 10 | import type { Signal } from '@lwc/signals'; |
@@ -41,13 +41,26 @@ export function componentValueObserved(vm: VM, key: PropertyKey, target: any = { |
41 | 41 | lwcRuntimeFlags.ENABLE_EXPERIMENTAL_SIGNALS && |
42 | 42 | isObject(target) && |
43 | 43 | !isNull(target) && |
44 | | - isTrustedSignal(target) && |
45 | 44 | process.env.IS_BROWSER && |
46 | 45 | // Only subscribe if a template is being rendered by the engine |
47 | 46 | tro.isObserving() |
48 | 47 | ) { |
49 | | - // Subscribe the template reactive observer's notify method, which will mark the vm as dirty and schedule hydration. |
50 | | - subscribeToSignal(component, target as Signal<unknown>, tro.notify.bind(tro)); |
| 48 | + /** |
| 49 | + * The legacy validation behavior was that this check should only |
| 50 | + * be performed for runtimes that have provided a trustedSignals set. |
| 51 | + * However, this resulted in a bug as all object values were |
| 52 | + * being considered signals in environments where the trustedSignals |
| 53 | + * set had not been defined. The runtime flag has been added as a killswitch |
| 54 | + * in case the fix needs to be reverted. |
| 55 | + */ |
| 56 | + if ( |
| 57 | + lwcRuntimeFlags.ENABLE_LEGACY_SIGNAL_CONTEXT_VALIDATION |
| 58 | + ? legacyIsTrustedSignal(target) |
| 59 | + : isTrustedSignal(target) |
| 60 | + ) { |
| 61 | + // Subscribe the template reactive observer's notify method, which will mark the vm as dirty and schedule hydration. |
| 62 | + subscribeToSignal(component, target as Signal<unknown>, tro.notify.bind(tro)); |
| 63 | + } |
51 | 64 | } |
52 | 65 | } |
53 | 66 |
|
|
0 commit comments