Skip to content

Switch to a CSS based solution for the PageLayout sticky pane #6050

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

Merged
merged 5 commits into from
May 20, 2025

Conversation

hectahertz
Copy link
Contributor

@hectahertz hectahertz commented May 15, 2025

Closes https://github.com/github/primer/issues/5174

This change removes the useResizeObserver and useEffect hooks previously used to calculate and set the --sticky-pane-height CSS custom property.

Problem:
The constant recalculation and application of this style on scroll and resize events were triggering frequent and costly style recalculations (observed at 60ms+ per recalc). This significantly impacted page performance during scrolling near the top of the page. This is not even counting the React component re-render time.

Solution:
By replacing this JS code with a CSS based solution we eliminate the continuous style updates, thereby preventing the performance bottleneck caused by excessive style recalculations. The underlying layout or component manages the sticky pane's height without requiring this dynamic JavaScript-driven height adjustment.

This is a small compromise in UX that gets us big performance gains.

More context on the original implementation:
https://share.cleanshot.com/O9uSpc

Changelog

Changed

The only difference in behaviour happens on a very specific scenario:

  • The pane doesn't fit in the viewport
  • The pane is sticky
  • The user hasn't scrolled past the header yet

Existing behavior:

  • We can directly scroll to the bottom of the pane (This is what the JS code compensates for)
Screen.Recording.2025-05-20.at.16.30.03.mov

New behavior:

  • To scroll to the bottom of the pane, we have to scroll past the header or attempt to scroll through the pane again, then the scroll interaction bubbles to the parent and we scroll past the header (see video)
Screen.Recording.2025-05-20.at.16.30.29.mov

Rollout strategy

  • Patch release
  • Minor release
  • Major release; if selected, include a written rollout or migration plan
  • None; if selected, include a brief description as to why

Testing & Reviewing

Merge checklist

Copy link

changeset-bot bot commented May 15, 2025

🦋 Changeset detected

Latest commit: e3bbb4d

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@primer/react Minor

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

Copy link
Contributor

👋 Hi, this pull request contains changes to the source code that github/github depends on. If you are GitHub staff, we recommend testing these changes with github/github using the integration workflow. Thanks!

@github-actions github-actions bot added the integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm label May 15, 2025
Copy link
Contributor

github-actions bot commented May 15, 2025

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 95.26 KB (-0.98% 🔽)
packages/react/dist/browser.umd.js 95.31 KB (-1.16% 🔽)

@hectahertz hectahertz changed the title Hectahertz/pagelayout css solution Switch to a CSS based solution for the PageLayout sticky pane May 20, 2025
@hectahertz hectahertz marked this pull request as ready for review May 20, 2025 14:35
@Copilot Copilot AI review requested due to automatic review settings May 20, 2025 14:35
@hectahertz hectahertz requested a review from a team as a code owner May 20, 2025 14:35
@hectahertz hectahertz requested a review from joshblack May 20, 2025 14:35
@hectahertz hectahertz marked this pull request as draft May 20, 2025 14:35
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR replaces the JavaScript-driven sticky pane height calculation with a pure CSS-based solution, eliminating expensive scroll/resize listeners and dynamic style recalculations.

  • Removed useStickyPaneHeight hook and all related context plumbing
  • Updated PageLayout.module.css to use a fixed CSS max-height instead of a CSS variable
  • Updated PageLayout.tsx to drop the obsolete props, refs, and effects

Reviewed Changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.

File Description
packages/react/src/PageLayout/useStickyPaneHeight.ts Deleted the JS hook that calculated pane height
packages/react/src/PageLayout/PageLayout.tsx Removed hook import, context values, and effects
packages/react/src/PageLayout/PageLayout.module.css Changed max-height to 100vh
.changeset/warm-seals-obey.md Added changelog entry for CSS-based solution

@github-actions github-actions bot requested a deployment to storybook-preview-6050 May 20, 2025 14:38 Abandoned
@github-actions github-actions bot temporarily deployed to storybook-preview-6050 May 20, 2025 14:52 Inactive
Copy link
Member

@joshblack joshblack left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM! Just would want design to 👍 the UX changes. Is there a good way for us to test this in dotcom? Changes layout-wise terrify me lol

@hectahertz
Copy link
Contributor Author

hectahertz commented May 20, 2025

@joshblack Thanks for reviewing! Yes, we'll be review-labing this :)

@mperrotti This is what we reviewed together, does it look ok?

@hectahertz hectahertz added this pull request to the merge queue May 20, 2025
Merged via the queue into main with commit 53ef8ea May 20, 2025
35 checks passed
@hectahertz hectahertz deleted the hectahertz/pagelayout-css-solution branch May 20, 2025 18:14
@primer primer bot mentioned this pull request May 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
integration-tests: recommended This change needs to be tested for breaking changes. See https://arc.net/l/quote/tdmpakpm
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants