Skip to content

Ensure newly created or dirty and reattached views are reachable by change detection traversal - #53022

Closed
atscott wants to merge 1 commit into
angular:mainfrom
atscott:dirtyViewReattached2
Closed

atscott wants to merge 1 commit into
angular:mainfrom
atscott:dirtyViewReattached2

Conversation

@atscott

@atscott atscott commented Nov 17, 2023 •

Copy link
Copy Markdown
Contributor

See individual commits

fixes #52928

@atscott atscott added area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release action: global presubmit The PR is in need of a google3 global presubmit labels Nov 17, 2023
@ngbot ngbot Bot added this to the Backlog milestone Nov 17, 2023
@atscott
atscott force-pushed the dirtyViewReattached2 branch from 0e36005 to 9eb304f Compare November 20, 2023 17:13
@atscott
atscott force-pushed the dirtyViewReattached2 branch from 9eb304f to d66b17c Compare November 29, 2023 17:38
@atscott
atscott force-pushed the dirtyViewReattached2 branch 3 times, most recently from dc8d60e to 7975dea Compare December 6, 2023 17:31
@atscott
atscott marked this pull request as ready for review December 7, 2023 20:04
@atscott
atscott force-pushed the dirtyViewReattached2 branch from 7975dea to 3a0db8d Compare December 7, 2023 20:07
@atscott
atscott force-pushed the dirtyViewReattached2 branch from 3a0db8d to 0850db2 Compare December 11, 2023 20:01
@atscott atscott changed the title Fixes for #52928 Ensure newly created or dirty and reattached views are reachable by change detection traversal Dec 11, 2023
@atscott

atscott commented Dec 11, 2023 •

Copy link
Copy Markdown
Contributor Author

global presubmit had ~6 total failures:

  • 2 failures were test setups that did not set required inputs correctly. Now that the test component actually executes, it threw errors
  • 1 a11y test that appears to be a result of autofocus now working correctly where it did not before
  • 1 screenshot test with a small shift in pixels for a tooltip
  • (the big one): 1 failure that relied on the bug being fixed. Component initialization attempted to read the value of an input where that value was set by ngModel. That happens in a Promise so the component relied on not getting change detected in the current cycle. Note that this should really be ExpressionChanged... error anyways but checkNoChanges was blocked by an OnPush parent

The last failure is concerning and while the new behavior is still technically correct, this change can lead to actual production issues. As a result, this PR is updated to have the fix controlled by a flag that is off right now. We will roll this out when possible in g3 with the private exports to opt out temporarily. This flag will also be set to true by default for the v18 release.

@atscott atscott added action: review The PR is still awaiting reviews from at least one requested reviewer and removed action: global presubmit The PR is in need of a google3 global presubmit labels Dec 11, 2023
…d during CD

When a view has the `Dirty` flag and is reattached, we should ensure that it is
reached and refreshed during the next change detection run from above.

In addition, when a view is created and attached, we should ensure that it is reached
and refreshed during change detection. This can happen if the view is
created and attached outside a change run or when it is created and
attached after its insertion view was already checked. In both cases, we
should ensure that the view is reached and refreshed during either the
current change detection or the next one (if change detection is not
already running).

We can achieve this by creating all views with the `Dirty` flag set.

However, this does happen to be a breaking change in some scenarios.
The one identified internally was actually depending on change detection
_not_ running immediately because it relied on an input value that was
set using `ngModel`. Because `ngModel` sets its value in a `Promise`, it
is not available until the _next_ change detection cycle. Ensuring
created views run in the current change change detection will result in
different behavior in this case.

Making option the default is the solution to angular#52928. That will have to
wait for a major version.
@atscott
atscott force-pushed the dirtyViewReattached2 branch from 0850db2 to bfec0c2 Compare December 13, 2023 20:30
@atscott atscott added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels Dec 14, 2023
@atscott

atscott commented Dec 14, 2023

Copy link
Copy Markdown
Contributor Author

This PR was merged into the repository by commit 606de51.

atscott added a commit that referenced this pull request Dec 14, 2023
…d during CD (#53022)

When a view has the `Dirty` flag and is reattached, we should ensure that it is
reached and refreshed during the next change detection run from above.

In addition, when a view is created and attached, we should ensure that it is reached
and refreshed during change detection. This can happen if the view is
created and attached outside a change run or when it is created and
attached after its insertion view was already checked. In both cases, we
should ensure that the view is reached and refreshed during either the
current change detection or the next one (if change detection is not
already running).

We can achieve this by creating all views with the `Dirty` flag set.

However, this does happen to be a breaking change in some scenarios.
The one identified internally was actually depending on change detection
_not_ running immediately because it relied on an input value that was
set using `ngModel`. Because `ngModel` sets its value in a `Promise`, it
is not available until the _next_ change detection cycle. Ensuring
created views run in the current change change detection will result in
different behavior in this case.

Making option the default is the solution to #52928. That will have to
wait for a major version.

PR Close #53022
@atscott atscott closed this in 606de51 Dec 14, 2023
@angular-automatic-lock-bot

Copy link
Copy Markdown

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot Bot locked and limited conversation to collaborators Jan 14, 2024
ChellappanRajan pushed a commit to ChellappanRajan/angular that referenced this pull request Jan 23, 2024
…d during CD (angular#53022)

When a view has the `Dirty` flag and is reattached, we should ensure that it is
reached and refreshed during the next change detection run from above.

In addition, when a view is created and attached, we should ensure that it is reached
and refreshed during change detection. This can happen if the view is
created and attached outside a change run or when it is created and
attached after its insertion view was already checked. In both cases, we
should ensure that the view is reached and refreshed during either the
current change detection or the next one (if change detection is not
already running).

We can achieve this by creating all views with the `Dirty` flag set.

However, this does happen to be a breaking change in some scenarios.
The one identified internally was actually depending on change detection
_not_ running immediately because it relied on an input value that was
set using `ngModel`. Because `ngModel` sets its value in a `Promise`, it
is not available until the _next_ change detection cycle. Ensuring
created views run in the current change change detection will result in
different behavior in this case.

Making option the default is the solution to angular#52928. That will have to
wait for a major version.

PR Close angular#53022
rlmestre pushed a commit to rlmestre/angular that referenced this pull request Jan 26, 2024
…d during CD (angular#53022)

When a view has the `Dirty` flag and is reattached, we should ensure that it is
reached and refreshed during the next change detection run from above.

In addition, when a view is created and attached, we should ensure that it is reached
and refreshed during change detection. This can happen if the view is
created and attached outside a change run or when it is created and
attached after its insertion view was already checked. In both cases, we
should ensure that the view is reached and refreshed during either the
current change detection or the next one (if change detection is not
already running).

We can achieve this by creating all views with the `Dirty` flag set.

However, this does happen to be a breaking change in some scenarios.
The one identified internally was actually depending on change detection
_not_ running immediately because it relied on an input value that was
set using `ngModel`. Because `ngModel` sets its value in a `Promise`, it
is not available until the _next_ change detection cycle. Ensuring
created views run in the current change change detection will result in
different behavior in this case.

Making option the default is the solution to angular#52928. That will have to
wait for a major version.

PR Close angular#53022
amilamen pushed a commit to amilamen/angular that referenced this pull request Jan 26, 2024
…d during CD (angular#53022)

When a view has the `Dirty` flag and is reattached, we should ensure that it is
reached and refreshed during the next change detection run from above.

In addition, when a view is created and attached, we should ensure that it is reached
and refreshed during change detection. This can happen if the view is
created and attached outside a change run or when it is created and
attached after its insertion view was already checked. In both cases, we
should ensure that the view is reached and refreshed during either the
current change detection or the next one (if change detection is not
already running).

We can achieve this by creating all views with the `Dirty` flag set.

However, this does happen to be a breaking change in some scenarios.
The one identified internally was actually depending on change detection
_not_ running immediately because it relied on an input value that was
set using `ngModel`. Because `ngModel` sets its value in a `Promise`, it
is not available until the _next_ change detection cycle. Ensuring
created views run in the current change change detection will result in
different behavior in this case.

Making option the default is the solution to angular#52928. That will have to
wait for a major version.

PR Close angular#53022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Views attached inside OnPush components are not checked in some circumstences

2 participants