Repository navigation
perf(focus-monitor): optimize event registration - #18667
Merged
Merged
Conversation
devversion
approved these changes
Mar 2, 2020
devversion
left a comment
Member
There was a problem hiding this comment.
LGTM. @mmalerba should have a look too.
jelbourn
approved these changes
Mar 2, 2020
crisbeto
reviewed
Mar 2, 2020
mmalerba
suggested changes
Mar 2, 2020
mmalerba
suggested changes
Mar 2, 2020
Improve focus-monitor scalability by implementing event delegation instead of adding individual 'focus' and 'blur' event listeners to each monitored element.
mmalerba
force-pushed
the
perf-focusmonitor
branch
from
April 7, 2020 17:28
d408ec4 to
4513fb3
Compare
mmalerba
pushed a commit
that referenced
this pull request
Apr 14, 2020
* perf(focus-monitor): optimize event registration Improve focus-monitor scalability by implementing event delegation instead of adding individual 'focus' and 'blur' event listeners to each monitored element. * Fix a bug in _getFocusOrigin(). * Add a comment explaining why we need to walk up the tree * Cleanup
crisbeto
added a commit
to crisbeto/material2
that referenced
this pull request
Apr 21, 2020
In angular#18667 event delegation was implemented for the `FocusMonitor` which is based around binding a single event on the `document`. The problem is that the browser won't invoke the `focus` and `blur` handlers on the `document`, if focus is moved within the same shadow root. These changes switch to delegating the events either through the closest shadow root or the `document`. Fixes angular#19133.
jelbourn
pushed a commit
that referenced
this pull request
Apr 24, 2020
In #18667 event delegation was implemented for the `FocusMonitor` which is based around binding a single event on the `document`. The problem is that the browser won't invoke the `focus` and `blur` handlers on the `document`, if focus is moved within the same shadow root. These changes switch to delegating the events either through the closest shadow root or the `document`. Fixes #19133.
jelbourn
pushed a commit
that referenced
this pull request
Apr 24, 2020
In #18667 event delegation was implemented for the `FocusMonitor` which is based around binding a single event on the `document`. The problem is that the browser won't invoke the `focus` and `blur` handlers on the `document`, if focus is moved within the same shadow root. These changes switch to delegating the events either through the closest shadow root or the `document`. Fixes #19133.
soro-google
pushed a commit
to soro-google/components
that referenced
this pull request
Apr 24, 2020
In angular#18667 event delegation was implemented for the `FocusMonitor` which is based around binding a single event on the `document`. The problem is that the browser won't invoke the `focus` and `blur` handlers on the `document`, if focus is moved within the same shadow root. These changes switch to delegating the events either through the closest shadow root or the `document`. Fixes angular#19133.
|
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. |
This file contains hidden or 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
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
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.
Improve
FocusMonitorscalability by implementing event delegation instead of adding individualfocusandblurevent listeners to each monitored element.The global listeners do have to walk up the ancestor chain of event target in order to support
checkChildren, but this is extremely fast even for very deeply nested DOM trees since all it has to do is callMap.has(element)for each one.Another potential improvement may be to store the tracked elements in a
WeakMapand remove the need to callstopMonitoring(), making the API easier, but this would require always keeping the 6 global event listeners active. Right now, they are removed if there are no tracked elements.