fix(core): replace assertion with more intentional error #52427
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Issue #50320 shows that in some cases, updating a signal that's a dependency of a template during change detection of that template can have several adverse effects. This can happen, for example, if the signal is set during the lifecycle hook of a directive within the same template that reads the signal.
This can cause a few things to happen:
ExpressionChanged
errors.ReactiveLViewConsumer
to fail.OnPush
component to stop working.The root cause of these later behaviors is subtle, and is ultimately a desync between the reactive graph and the view tree's notion of "dirty" for a given view. This will be fixed with further work planned for change detection to handle such updates directly. Until then, this commit improves the DX through two changes:
The mechanism of "committing"
ReactiveLViewConsumer
s to a view is changed to use theconsumerOnSignalRead
hook from the reactive graph. This prevents the situation which required the assertion in the first place.A
console.warn
warning is added when a view is marked dirty via a signal while it's still executing.The warning informs users that they're pushing data against the direction of change detection, risking
ExpressionChanged
or other issues. It's a warning and not an error because the check is overly broad and captures situations where the application would not actually break as a result, such as if acomputed
marked the template dirty but still returned the same value.