Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(core): When using setInput, mark view dirty in same way as markForCheck #49747

Closed
wants to merge 1 commit into from

Conversation

atscott
Copy link
Contributor

@atscott atscott commented Apr 7, 2023

patch target for #49711

ComponentRef.setInput internally calls markDirtyIfOnPush which only marks the given view as dirty but does not mark parents dirty like ChangeDetectorRef.markForCheck would.

export function markDirtyIfOnPush(lView: LView, viewIndex: number): void {
ngDevMode && assertLView(lView);
const childComponentLView = getComponentLViewByIndex(viewIndex, lView);
if (!(childComponentLView[FLAGS] & LViewFlags.CheckAlways)) {
childComponentLView[FLAGS] |= LViewFlags.Dirty;
}
}

markDirtyIfOnPush has an assumption that it’s being called from the parent’s template. That is, we don’t need to mark dirty to the root, because we’ve already traversed down to it. The function used to only be called during template execution for input bindings but was added to setInput later. It's not a good fit because it means that if you are responding to events such as an emit from an Observable and call setInput, the view of your ComponentRef won't necessarily get checked when change detection runs next. If this lives inside some OnPush component tree that's not already dirty, it only gets refreshed if you also call ChangeDetectorRef.markForCheck in the host component (because it will be "shielded" be a non-dirty parent).

@atscott atscott added area: core Issues related to the framework runtime target: patch This PR is targeted for the next patch release labels Apr 7, 2023
@ngbot ngbot bot added this to the Backlog milestone Apr 7, 2023
…orCheck`

`ComponentRef.setInput` internally calls `markDirtyIfOnPush` which only marks
the given view as dirty but does not mark parents dirty like `ChangeDetectorRef.markForCheck` would.
https://github.com/angular/angular/blob/f071224720f8affb97fd32fb5aeaa13155b13693/packages/core/src/render3/instructions/shared.ts#L1018-L1024

`markDirtyIfOnPush` has an assumption that it’s being called from the parent’s template. That is, we don’t need to mark dirty to the root, because we’ve already traversed down to it.
The function used to only be called during template execution for input
bindings but was added to `setInput` later. It's not a good fit because
it means that if you are responding to events such as an emit from an `Observable`
and call `setInput`, the view of your `ComponentRef` won't necessarily get checked
when change detection runs next. If this lives inside some `OnPush` component tree
that's not already dirty, it only gets refreshed if you also call
`ChangeDetectorRef.markForCheck` in the host component (because it will be "shielded" be a non-dirty parent).
@atscott atscott changed the title fix(core): When using setInput, mark view dirty in same way as `markF… fix(core): When using setInput, mark view dirty in same way as markForCheck Apr 7, 2023
@atscott atscott added merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note action: merge The PR is ready for merge by the caretaker labels Apr 10, 2023
@atscott
Copy link
Contributor Author

atscott commented Apr 10, 2023

caretaker: this is a patch target for #49711

@AndrewKushnir
Copy link
Contributor

This PR was merged into the repository by commit 702ec90.

AndrewKushnir pushed a commit that referenced this pull request Apr 10, 2023
…orCheck` (#49747)

`ComponentRef.setInput` internally calls `markDirtyIfOnPush` which only marks
the given view as dirty but does not mark parents dirty like `ChangeDetectorRef.markForCheck` would.
https://github.com/angular/angular/blob/f071224720f8affb97fd32fb5aeaa13155b13693/packages/core/src/render3/instructions/shared.ts#L1018-L1024

`markDirtyIfOnPush` has an assumption that it’s being called from the parent’s template. That is, we don’t need to mark dirty to the root, because we’ve already traversed down to it.
The function used to only be called during template execution for input
bindings but was added to `setInput` later. It's not a good fit because
it means that if you are responding to events such as an emit from an `Observable`
and call `setInput`, the view of your `ComponentRef` won't necessarily get checked
when change detection runs next. If this lives inside some `OnPush` component tree
that's not already dirty, it only gets refreshed if you also call
`ChangeDetectorRef.markForCheck` in the host component (because it will be "shielded" be a non-dirty parent).

PR Close #49747
crapStone pushed a commit to Calciumdibromid/CaBr2 that referenced this pull request Apr 27, 2023
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [@angular/animations](https://github.com/angular/angular) | dependencies | patch | [`15.2.6` -> `15.2.8`](https://renovatebot.com/diffs/npm/@angular%2fanimations/15.2.6/15.2.8) |
| [@angular/common](https://github.com/angular/angular) | dependencies | patch | [`15.2.6` -> `15.2.8`](https://renovatebot.com/diffs/npm/@angular%2fcommon/15.2.6/15.2.8) |
| [@angular/compiler](https://github.com/angular/angular) | dependencies | patch | [`15.2.6` -> `15.2.8`](https://renovatebot.com/diffs/npm/@angular%2fcompiler/15.2.6/15.2.8) |
| [@angular/compiler-cli](https://github.com/angular/angular/tree/main/packages/compiler-cli) ([source](https://github.com/angular/angular)) | devDependencies | patch | [`15.2.6` -> `15.2.8`](https://renovatebot.com/diffs/npm/@angular%2fcompiler-cli/15.2.6/15.2.8) |
| [@angular/core](https://github.com/angular/angular) | dependencies | patch | [`15.2.6` -> `15.2.8`](https://renovatebot.com/diffs/npm/@angular%2fcore/15.2.6/15.2.8) |
| [@angular/forms](https://github.com/angular/angular) | dependencies | patch | [`15.2.6` -> `15.2.8`](https://renovatebot.com/diffs/npm/@angular%2fforms/15.2.6/15.2.8) |
| [@angular/platform-browser](https://github.com/angular/angular) | dependencies | patch | [`15.2.6` -> `15.2.8`](https://renovatebot.com/diffs/npm/@angular%2fplatform-browser/15.2.6/15.2.8) |
| [@angular/platform-browser-dynamic](https://github.com/angular/angular) | dependencies | patch | [`15.2.6` -> `15.2.8`](https://renovatebot.com/diffs/npm/@angular%2fplatform-browser-dynamic/15.2.6/15.2.8) |

---

### Release Notes

<details>
<summary>angular/angular</summary>

### [`v15.2.8`](https://github.com/angular/angular/blob/HEAD/CHANGELOG.md#&#8203;1528-2023-04-19)

[Compare Source](angular/angular@15.2.7...15.2.8)

##### core

| Commit | Type | Description |
| -- | -- | -- |
| [2fff8fadbe](angular/angular@2fff8fa) | fix | handle invalid classes in class array bindings ([#&#8203;49924](angular/angular#49924)) |

##### http

| Commit | Type | Description |
| -- | -- | -- |
| [05a0225deb](angular/angular@05a0225) | fix | prevent headers from throwing an error when initializing numerical values ([#&#8203;49379](angular/angular#49379)) |

##### router

| Commit | Type | Description |
| -- | -- | -- |
| [09a42d988e](angular/angular@09a42d9) | fix | canceledNavigationResolution: 'computed' with redirects to the current URL ([#&#8203;49793](angular/angular#49793)) |

<!-- CHANGELOG SPLIT MARKER -->

### [`v15.2.7`](https://github.com/angular/angular/blob/HEAD/CHANGELOG.md#&#8203;1527-2023-04-12)

[Compare Source](angular/angular@15.2.6...15.2.7)

##### compiler

| Commit | Type | Description |
| -- | -- | -- |
| [b0c1a90f55](angular/angular@b0c1a90) | fix | Produce diagnositc if directive used in host binding is not exported ([#&#8203;49792](angular/angular#49792)) |

##### compiler-cli

| Commit | Type | Description |
| -- | -- | -- |
| [a40529af2e](angular/angular@a40529a) | fix | Catch FatalDiagnosticError during template type checking ([#&#8203;49792](angular/angular#49792)) |

##### core

| Commit | Type | Description |
| -- | -- | -- |
| [702ec90110](angular/angular@702ec90) | fix | When using setInput, mark view dirty in same way as `markForCheck` ([#&#8203;49747](angular/angular#49747)) |

#### Special Thanks

Alan Agius, Andrew Kushnir, Andrew Scott, Kristiyan Kostadinov, Matthieu Riegler and Nikola Kološnjaji

<!-- CHANGELOG SPLIT MARKER -->

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about these updates again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNS40MS4wIiwidXBkYXRlZEluVmVyIjoiMzUuNjEuMCJ9-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1863
Reviewed-by: Epsilon_02 <epsilon_02@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
@angular-automatic-lock-bot
Copy link

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 May 11, 2023
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 merge: caretaker note Alert the caretaker performing the merge to check the PR for an out of normal action needed or note target: patch This PR is targeted for the next patch release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants