Skip to content
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

Use SSR-compatible slot implementation in PageLayout #3036

Merged
merged 10 commits into from
Mar 16, 2023
Merged

Conversation

colebemis
Copy link
Contributor

@colebemis colebemis commented Mar 15, 2023

Problem

PageLayout.Header and PageLayout.Footer don't render server-side because PageLayout uses an SSR-incompatible approach to implement its slots API (issue).

Screen.Recording.2023-03-14.at.2.58.43.PM.mov

Notice that the layout shifts because the header appears after the page loads.

Slack discussion for context

Solution

This PR updates PageLayout to use an SSR-compatible slots implementation.

Tradeoff

In this new implementation, PageLayout.Header and PageLayout.Footer must be direct children of PageLayout. This feels like a reasonable tradeoff because PageLayout.Header and PageLayout.Footer aren't used often, and when they are used, they're almost always a direct child of PageLayout.

  • Dotcom uses PageLayout.Header in 3 places. In 2 of 3 usages, PageLayout.Header is a direct child of PageLayout. In the 3rd case, PageLayout.Header can easily be refactored to be direct child of PageLayout.
  • Dotcom doesn't use PageLayout.Footer.

Merge checklist

  • Added/updated tests
  • Added/updated documentation
  • Tested in Chrome
  • Tested in Firefox
  • Tested in Safari
  • Tested in Edge

Take a look at the What we look for in reviews section of the contributing guidelines for more information on how we review PRs.

@colebemis colebemis requested review from a team and josepmartins March 15, 2023 19:21
@changeset-bot
Copy link

changeset-bot bot commented Mar 15, 2023

🦋 Changeset detected

Latest commit: 5dcc159

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

@github-actions
Copy link
Contributor

github-actions bot commented Mar 15, 2023

size-limit report 📦

Path Size
dist/browser.esm.js 94.61 KB (+0.09% 🔺)
dist/browser.umd.js 95.22 KB (+0.12% 🔺)

@colebemis colebemis temporarily deployed to github-pages March 15, 2023 19:28 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3036 March 15, 2023 19:28 Inactive
@colebemis colebemis requested review from joshblack and siddharthkp and removed request for josepmartins March 15, 2023 20:04
@colebemis colebemis temporarily deployed to github-pages March 15, 2023 20:10 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3036 March 15, 2023 20:11 Inactive
@colebemis colebemis temporarily deployed to github-pages March 15, 2023 20:20 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3036 March 15, 2023 20:20 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.

Looks great 🔥 Just left some comments for some ideas while going through the code, feel free to ignore if they're not helpful 👍

src/hooks/unstable_useSlots.ts Outdated Show resolved Hide resolved
src/hooks/unstable_useSlots.ts Outdated Show resolved Hide resolved
src/hooks/unstable_useSlots.ts Outdated Show resolved Hide resolved
@colebemis colebemis temporarily deployed to github-pages March 15, 2023 21:22 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3036 March 15, 2023 21:23 Inactive
@colebemis colebemis temporarily deployed to github-pages March 15, 2023 21:33 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3036 March 15, 2023 21:33 Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3036 March 16, 2023 00:43 Inactive
@siddharthkp
Copy link
Member

Hi!

Just leaving it here in case we need it: In case this change isn't backward compatible with instances of PageLayout in gh/gh, we can unblock this team by putting this in drafts/experimental first.

@colebemis
Copy link
Contributor Author

@prashkan verified that this fixes SSR issues with PageLayout in gh/gh ✅ Slack

@colebemis colebemis temporarily deployed to github-pages March 16, 2023 18:26 — with GitHub Actions Inactive
@github-actions github-actions bot temporarily deployed to storybook-preview-3036 March 16, 2023 18:27 Inactive
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants