Skip to content

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

Merged
joshblack merged 3 commits into
mainfrom
fix/update-blankslate-styles
Jul 25, 2024
Merged

fix(Blankslate): update styles to prevent SSR hydration mismatch#4710
joshblack merged 3 commits into
mainfrom
fix/update-blankslate-styles

Conversation

@joshblack

Copy link
Copy Markdown
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 ownerJuly 1, 2024 17:04
@joshblack
joshblack requested a review from TylerJDevJuly 1, 2024 17:04
@changeset-bot

changeset-botBot commented Jul 1, 2024

Copy link
Copy Markdown

🦋 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
NameType
@primer/reactPatch

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

github-actionsBot commented Jul 1, 2024

Copy link
Copy Markdown
Contributor

size-limit report 📦

PathSize
packages/react/dist/browser.esm.js94.87 KB (0%)
packages/react/dist/browser.umd.js95.11 KB (0%)

@github-actions
github-actionsBottemporarily deployed to storybook-preview-4710 July 1, 2024 17:09 Inactive
@github-actions
github-actionsBottemporarily deployed to storybook-preview-4710 July 1, 2024 17:14 Inactive
@joshblack

Copy link
Copy Markdown
MemberAuthor

bump @TylerJDev!

.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
Copy Markdown
Member

Choose a reason for hiding this comment

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

Nice!

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
Copy Markdown
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 😄

Sign up for freeto 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

@joshblack@broccolinisoup