Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
* SPDX-License-Identifier: MIT
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/MIT
*/
import { isFunction, isNull, isObject, isTrustedSignal } from '@lwc/shared';
import { isNull, isObject, isTrustedSignal } from '@lwc/shared';
import { ReactiveObserver, valueMutated, valueObserved } from '../libs/mutation-tracker';
import { subscribeToSignal } from '../libs/signal-tracker';
import { safeHasProp } from './utils';
import type { Signal } from '@lwc/signals';
import type { JobFunction, CallbackFunction } from '../libs/mutation-tracker';
import type { VM } from './vm';
Expand Down Expand Up @@ -42,9 +41,6 @@ export function componentValueObserved(vm: VM, key: PropertyKey, target: any = {
lwcRuntimeFlags.ENABLE_EXPERIMENTAL_SIGNALS &&
isObject(target) &&
!isNull(target) &&
safeHasProp(target, 'value') &&
safeHasProp(target, 'subscribe') &&
isFunction(target.subscribe) &&
Comment on lines -45 to -47
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we no longer checking the shape target to make sure it's a signal? Won't that potentially break things?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I assumed this was because checking for the properties doesn't guarantee correctness and it's up to the consumer to use the API properly? CC: @divmain

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isTrustedSignal(target) is adequate. Objects won't be in the WeakMap unless they're actual signals, which means they'll have the required shape.

If we remove the trusted signal mechanism in the future, we'll have to revisit how to detect signals properly without risking performance regressions. For the specific regression that we encountered, we could add !Array.isArray(target) as a condition. In an case, we can deal with this when/if we remove the trusted signals mechanism. That'll be a couple of years out at the earliest.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@divmain turns out this is not adequate if the trusted signal tracking set isn't initialized. It defaults to assuming everything is a trusted signal, and therefore tries to subscribe to every mutated object. It doesn't break the framework because it's wrapped in a try/catch, but it's a major console noise and a perf hit. Oops! 😓

#5492 (comment)

isTrustedSignal(target) &&
// Only subscribe if a template is being rendered by the engine
tro.isObserving()
Expand Down