Skip to content

Improve PageLayout performance #5942

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 1 commit into from
Apr 23, 2025

Conversation

hectahertz
Copy link
Contributor

@hectahertz hectahertz commented Apr 20, 2025

Closes #4591

Changelog

Changed

Fixes the extra re-renders caused by the useStickyPaneHeight hook on PageLayout and its contents.

The cause of the re-renders was re-creation of objects and functions on every hook call, which cause the context consumers to re-render.

Further improvements could (and should) be made by:

  • Removing all the Styled Components code
  • Switching to a CSS solution for the sticky header

Before:

Screenshot 2025-04-20 at 16 10 04
Screen.Recording.2025-04-20.at.16.03.25.mov

After:

Screenshot 2025-04-20 at 16 08 52
Screen.Recording.2025-04-20.at.16.01.59.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

@Copilot Copilot AI review requested due to automatic review settings April 20, 2025 14:03
@hectahertz hectahertz requested a review from a team as a code owner April 20, 2025 14:03
@hectahertz hectahertz requested a review from joshblack April 20, 2025 14:03
Copy link

changeset-bot bot commented Apr 20, 2025

🦋 Changeset detected

Latest commit: fd2ae7a

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 Patch

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

@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

Improve PageLayout performance by reducing unnecessary re-renders caused by the re-creation of objects and functions.

  • Wrapped enableStickyPane and disableStickyPane in React.useCallback in useStickyPaneHeight for consistent references.
  • Introduced memoization of the context value in PageLayout to prevent needless re-renders of consumers.
  • Added a changeset for a patch release.

Reviewed Changes

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

File Description
packages/react/src/PageLayout/useStickyPaneHeight.ts Introduces useCallback wrappers and memoizes the hook's returned object.
packages/react/src/PageLayout/PageLayout.tsx Uses React.useMemo for the context value to reduce re-rendering overhead.
.changeset/clean-fried-eggs.md Provides a changeset for the patch release focused on performance improvements.

@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 Apr 20, 2025
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!

Copy link
Contributor

github-actions bot commented Apr 20, 2025

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 102.35 KB (+0.07% 🔺)
packages/react/dist/browser.umd.js 102.59 KB (+0.06% 🔺)

Copy link
Contributor

Uh oh! @hectahertz, at least one image you shared is missing helpful alt text. Check your pull request body to fix the following violations:

  • Images should have meaningful alternative text (alt text) at line 24
  • Images should have meaningful alternative text (alt text) at line 35

Alt text is an invisible description that helps screen readers describe images to blind or low-vision users. If you are using markdown to display images, add your alt text inside the brackets of the markdown image.

Learn more about alt text at Basic writing and formatting syntax: images on GitHub Docs.

🤖 Beep boop! This comment was added automatically by github/accessibility-alt-text-bot.

@hectahertz hectahertz enabled auto-merge April 23, 2025 07:05
@hectahertz hectahertz force-pushed the hectahertz/fix-pagelayout-performance branch from 9ff343f to fd2ae7a Compare April 23, 2025 16:38
@hectahertz hectahertz added this pull request to the merge queue Apr 23, 2025
Merged via the queue into main with commit 596388d Apr 23, 2025
44 of 45 checks passed
@hectahertz hectahertz deleted the hectahertz/fix-pagelayout-performance branch April 23, 2025 17:05
@primer primer bot mentioned this pull request Apr 23, 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.

3 participants