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

fix(Blankslate): update styles to prevent SSR hydration mismatch #4710

Merged
merged 3 commits into from
Jul 25, 2024

Conversation

joshblack
Copy link
Member

Update Blankslate to address an SSR hydration mismatch issue that was occurring. When the styles were present as children of a <style> tag, they were being serialized in a way that transformed the ' to escaped sequences leading to a hydration mismatch. Updating this to use dangerouslySetInnerHTML addresses this issue.

I also updated the styles to use fallbacks, where appropriate, so the component would render as expected without an explicit import to primitives.

Changelog

New

Changed

  • Update the style tag in Blankslate to better support SSR
  • Add fallback values to CSS Custom Properties used in Blankslate.

Removed

Rollout strategy

  • Patch release

@joshblack joshblack requested a review from a team as a code owner July 1, 2024 17:04
@joshblack joshblack requested a review from TylerJDev July 1, 2024 17:04
Copy link

changeset-bot bot commented Jul 1, 2024

🦋 Changeset detected

Latest commit: 9a3040c

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

github-actions bot commented Jul 1, 2024

size-limit report 📦

Path Size
packages/react/dist/browser.esm.js 94.87 KB (0%)
packages/react/dist/browser.umd.js 95.11 KB (0%)

@joshblack
Copy link
Member Author

bump @TylerJDev!

display: grid;
justify-items: center;
padding: var(--blankslate-outer-padding-block) var(--blankslate-outer-padding-inline);
}

.Blankslate[data-spacious='true'] {
--blankslate-outer-padding-block: var(--base-size-80);
--blankslate-outer-padding-inline: var(--base-size-40);
--blankslate-outer-padding-block: var(--base-size-80, 5rem);
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

@@ -128,7 +130,7 @@ function Blankslate({border, children, narrow, spacious}: BlankslateProps) {
This is a workaround so we can use `@container` without upgrading `styled-components` to 6.x
See [this comment](https://github.com/primer/react/pull/3869#discussion_r1392523030) for more info
*/}
<style type="text/css">{BlankslateContainerQuery}</style>
<style type="text/css" dangerouslySetInnerHTML={{__html: BlankslateContainerQuery}} />
Copy link
Member

Choose a reason for hiding this comment

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

This is very smart 🔥

I also think it is obscure to cause hydration mismatch when it is passed as children 😄

@joshblack joshblack enabled auto-merge July 25, 2024 15:17
@joshblack joshblack added this pull request to the merge queue Jul 25, 2024
Merged via the queue into main with commit 7d086c7 Jul 25, 2024
30 checks passed
@joshblack joshblack deleted the fix/update-blankslate-styles branch July 25, 2024 15:43
@primer primer bot mentioned this pull request Jul 25, 2024
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.

2 participants