perf(ActionList): replace :has(~ .SubGroup [data-active]) collapsed-parent indicator with attribute selector#7902
Draft
mattcosta7 wants to merge 1 commit into
Draft
Conversation
🦋 Changeset detectedLatest commit: 76fdb17 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Contributor
|
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 join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #
Replaces the most expensive
:has()selector remaining inpackages/react/src/ActionList/ActionList.module.css—&:has(~ .SubGroup [data-active='true'])— with a plain attribute + child-combinator selector. This was the worst-shape:has()left in the package: it combined a general sibling combinator with a descendant search, and the engine had to re-run that walk against every collapsed parent any time a descendantdata-activeattribute changed.Before:
After:
The selector goes from a sibling walk + descendant subtree search (re-evaluated on every
data-activemutation inside the subtree) to a constant-time attribute lookup on the same<li>that the consumer already controls.Why this is safe:
The new selector depends on
data-activebeing set on the parent<li>. The only in-repo consumer that renders anActionList.ItemwithActionList.SubItemisNavList.ItemWithSubNav, which already does its ownhasCurrentNavItemrecursion and passesactive={!isOpen && containsCurrentItem}to the parent — exactly matching the condition the old:has()was detecting. Net visual output is identical forNavList.SubNavusage.Behavior change for direct
ActionList.Item+ActionList.SubItemconsumersIf a consumer renders
ActionList.SubItemdirectly (withoutNavList.SubNav) and relied on the:has()selector to auto-light-up a collapsed parent when a descendant haddata-active='true', they will now need to passactive={true}to the parentActionList.Itemthemselves. This is the same patternNavList.ItemWithSubNavalready implements; no other in-repo usage exists.Changelog
Changed
ActionList.module.cssno longer uses:has()to detect an active descendant in a collapsed parent's sub-group; the same styles fire when the parentActionList.Itemitself hasactive={true}(whichNavList.ItemWithSubNavalready sets via its existingcontainsCurrentItemwalk).Removed
&:has(~ .SubGroup [data-active='true'])selector fromActionList.module.css.Rollout strategy
Testing & Reviewing
packages/react/src/ActionList/**+packages/react/src/NavList/**unit tests pass.tsc --noEmitonpackages/reactis clean.-webkit-tap-highlight-colorbrowser-compat warning at line 509, unrelated to this change).VRT expectations: No change to
NavList.WithSubItems/NavList.WithNestedSubItems/NavList.WithTrailingActionInSubItemrenderings — the parentActionList.Itemalready carriesdata-active='true'whenever the previous:has()would have matched.Companion to #7901 (PageHeader) and #7894 (other ActionList
:has()selectors).Merge checklist