Repository navigation
perf(ActionList, TreeView): avoid whole-subtree style invalidation on hover, focus and attribute changes #8682
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
Open
mattcosta7
wants to merge
7
commits into
main
Choose a base branch
from
mattcosta7-actionlist-treeview-invalidation-fix
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
780b0a3
perf(ActionList, TreeView): avoid whole-subtree style invalidation on…
mattcosta7 203b237
fix(ActionList): keep inactive hover color on items that also set ari…
mattcosta7 7dda141
Merge branch 'main' into mattcosta7-actionlist-treeview-invalidation-fix
mattcosta7 a94cc7b
Merge branch 'main' into mattcosta7-actionlist-treeview-invalidation-fix
mattcosta7 dbe493f
TreeView: drive level-line focus state from data-focus-within
mattcosta7 3c097e2
Merge branch 'main' into mattcosta7-actionlist-treeview-invalidation-fix
mattcosta7 d50a467
Merge branch 'main' into mattcosta7-actionlist-treeview-invalidation-fix
mattcosta7 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@primer/react': patch | ||
| --- | ||
|
|
||
| ActionList: Reduce style recalculation when unrelated elements on the page change hover state or attributes |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
| '@primer/react': patch | ||
| --- | ||
|
|
||
| TreeView: Reduce style recalculation when the pointer or focus enters or leaves the tree, and when focus moves between items in Safari |
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
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| import type React from 'react' | ||
| import {useEffect} from 'react' | ||
|
|
||
| /** | ||
| * Mirrors `:focus-within` onto the tree root as `data-focus-within`. | ||
| * | ||
| * WebKit clears and re-sets `:focus-within` up the ancestor chain on every focus move, so a | ||
| * `:focus-within` rule on the root restyles every level line on each arrow key press. This | ||
| * attribute only changes when focus enters or leaves the tree. It is written to the DOM | ||
| * directly so the tree doesn't re-render. | ||
| */ | ||
| export function useFocusWithinAttribute(containerRef: React.RefObject<HTMLElement | null>) { | ||
| useEffect(() => { | ||
| const root = containerRef.current | ||
| if (!root) return | ||
|
|
||
| const sync = (event?: FocusEvent) => { | ||
| const focused = event | ||
| ? event.type === 'focusin' || root.contains(event.relatedTarget as Node | null) | ||
| : root.matches(':focus-within') | ||
| root.toggleAttribute('data-focus-within', focused) | ||
| } | ||
|
|
||
| sync() | ||
| root.addEventListener('focusin', sync) | ||
| root.addEventListener('focusout', sync) | ||
| return () => { | ||
| root.removeEventListener('focusin', sync) | ||
| root.removeEventListener('focusout', sync) | ||
| root.removeAttribute('data-focus-within') | ||
| } | ||
| }, [containerRef]) | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.