-
Notifications
You must be signed in to change notification settings - Fork 24.8k
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): error if detectChanges is called at the wrong time under specific circumstances #40206
Closed
crisbeto
wants to merge
1
commit into
angular:master
from
crisbeto:38611-hook-detect-changes-error-again
Closed
fix(core): error if detectChanges is called at the wrong time under specific circumstances #40206
crisbeto
wants to merge
1
commit into
angular:master
from
crisbeto:38611-hook-detect-changes-error-again
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…pecific circumstances Internally we store lifecycle hooks in the format `[index, hook, index, hook]` and when iterating over them, we check one place ahead to figure out whether we've hit found a hook or an index. The problem is that the loop is set up to iterate up to `hooks.length` which means that we may go out of bounds on the last iteration, depending on where we started. This appears to happen under a specific set of circumstances where a directive calls `detectChanges` from an input setter while it has `ngOnChanges` and `ngAfterViewInit` hooks. These changes resolve the issue by only iterating up to `length - 1` which guarantees that we can always look one place ahead. This appears to have regressed some time in version 10. Fixes angular#38611.
crisbeto
force-pushed
the
38611-hook-detect-changes-error-again
branch
from
December 19, 2020 13:02
d5b60d3
to
2529e96
Compare
crisbeto
added
action: review
The PR is still awaiting reviews from at least one requested reviewer
target: patch
This PR is targeted for the next patch release
type: bug/fix
labels
Dec 19, 2020
Note for reviewer: the |
atscott
approved these changes
Dec 21, 2020
crisbeto
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 21, 2020
josephperrott
pushed a commit
that referenced
this pull request
Dec 22, 2020
…pecific circumstances (#40206) Internally we store lifecycle hooks in the format `[index, hook, index, hook]` and when iterating over them, we check one place ahead to figure out whether we've hit found a hook or an index. The problem is that the loop is set up to iterate up to `hooks.length` which means that we may go out of bounds on the last iteration, depending on where we started. This appears to happen under a specific set of circumstances where a directive calls `detectChanges` from an input setter while it has `ngOnChanges` and `ngAfterViewInit` hooks. These changes resolve the issue by only iterating up to `length - 1` which guarantees that we can always look one place ahead. This appears to have regressed some time in version 10. Fixes #38611. PR Close #40206
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
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
cla: yes
target: patch
This PR is targeted for the next patch release
type: bug/fix
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.
Internally we store lifecycle hooks in the format
[index, hook, index, hook]
and when iterating over them, we check one place ahead to figure out whether we've hit found a hook or an index. The problem is that the loop is set up to iterate up tohooks.length
which means that we may go out of bounds on the last iteration, depending on where we started. This appears to happen under a specific set of circumstances where a directive callsdetectChanges
from an input setter while it hasngOnChanges
andngAfterViewInit
hooks.These changes resolve the issue by only iterating up to
length - 1
which guarantees that we can always look one place ahead.This appears to have regressed some time in version 10.
Fixes #38611.