Refactor PageLayout drag/resize optimizations to use CSS attribute selectors #7385
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.
PR #7349 introduced inline style manipulation to avoid O(n) descendant selector matching during drag/resize. However, the issue was descendant selectors specifically—direct attribute selectors like
.Pane[data-dragging='true']are O(1) and only invalidate the attributed element.This refactor moves containment properties from JavaScript to CSS, reducing code complexity while maintaining performance.
Changes
Before:
After:
Changelog
Changed
PageLayout: Containment optimizations during drag/resize now use CSS attribute selectors instead of inline stylesRemoved
paneUtils.setContainmentOptimizations()function (internal)paneUtils.removeContainmentOptimizations()function (internal)contain-intrinsic-sizecalculation (acceptable—optimization active <1s during drag)Rollout strategy
Internal optimization change with no API impact. Same performance characteristics, simpler implementation.
Testing & Reviewing
All existing PageLayout drag/resize tests pass. Tests updated to check
data-draggingattribute presence instead of inline styles.Merge checklist
Original prompt
Summary
Simplify the drag/resize performance optimizations in PR #7349 by using direct CSS attribute selectors instead of inline styles for containment properties. This maintains O(1) performance while reducing code complexity.
Background
PR #7349 introduced inline style manipulation via
paneUtils.tsto avoid O(n) descendant selector matching. However, the original problem was descendant selectors, not attribute selectors themselves. A direct attribute selector like.Pane[data-dragging='true']is O(1) because it only invalidates the element with the attribute, not all descendants.Changes Required
1. Add CSS rules with direct attribute selectors
In
packages/react/src/PageLayout/PageLayout.module.css, add:2. Simplify
paneUtils.tsRemove
setContainmentOptimizationsandremoveContainmentOptimizationsfunctions. Keep only the drag handle visual feedback:3. Update
usePaneWidth.tsReplace inline style containment with attribute toggling for window resize:
In the resize handler, instead of calling
setContainmentOptimizations(paneRef.current)andsetContainmentOptimizations(contentRef.current), set the data attribute:4. Update tests
Update tests in
PageLayout.test.tsxandusePaneWidth.test.tsto check for thedata-draggingattribute instead of inlinecontainstyles:Why This Is Better
setContainmentOptimizations,removeContainmentOptimizationsfunctionssetAttribute/removeAttributecontain-intrinsic-sizeoffsetHeightTradeoff
We lose the ability to set
contain-intrinsic-size: auto ${element.offsetHeight}pxdynamically. However, this is acceptable because:content-visibility: autois only applied during drag (~1 second typically)contain-intrinsic-sizeentirely is fine — the browser handles it gracefullyFiles to Modify
packages/react/src/PageLayout/PageLayout.module.css— Add direct attribute selector rulespackages/react/src/PageLayout/paneUtils.ts— Simplify to attribute-based approachpackages/react/src/PageLayout/usePaneWidth.ts— Use attributes instead of inline styles for res...This pull request was created from Copilot chat.
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.