Skip to content

Commit 7d086c7

Browse files
authored
fix(Blankslate): update styles to prevent SSR hydration mismatch (#4710)
* fix(Blankslate): update styles to prevent SSR mismatch * chore: add changeset --------- Co-authored-by: Josh Black <[email protected]>
1 parent 801ca96 commit 7d086c7

File tree

3 files changed

+143
-16
lines changed

3 files changed

+143
-16
lines changed

.changeset/wild-maps-bathe.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@primer/react': patch
3+
---
4+
5+
Update Blankslate styles to better support server-side rendering

package-lock.json

Lines changed: 120 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/react/src/Blankslate/Blankslate.tsx

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,17 @@ const StyledBlankslate = styled.div`
2626
container-type: inline-size;
2727
2828
.Blankslate {
29-
--blankslate-outer-padding-block: var(--base-size-32);
30-
--blankslate-outer-padding-inline: var(--base-size-32);
29+
--blankslate-outer-padding-block: var(--base-size-32, 2rem);
30+
--blankslate-outer-padding-inline: var(--base-size-32, 2rem);
31+
3132
display: grid;
3233
justify-items: center;
3334
padding: var(--blankslate-outer-padding-block) var(--blankslate-outer-padding-inline);
3435
}
3536
3637
.Blankslate[data-spacious='true'] {
37-
--blankslate-outer-padding-block: var(--base-size-80);
38-
--blankslate-outer-padding-inline: var(--base-size-40);
38+
--blankslate-outer-padding-block: var(--base-size-80, 5rem);
39+
--blankslate-outer-padding-inline: var(--base-size-40, 2.5rem);
3940
}
4041
4142
.Blankslate[data-border='true'] {
@@ -51,29 +52,30 @@ const StyledBlankslate = styled.div`
5152
.Blankslate-Heading,
5253
.Blankslate-Description {
5354
margin: 0;
54-
margin-bottom: var(--stack-gap-condensed);
55+
margin-bottom: var(--stack-gap-condensed, 0.5rem);
5556
}
5657
5758
.Blankslate-Heading {
58-
font-size: var(--text-title-size-medium);
59-
font-weight: var(--text-title-weight-medium);
59+
font-size: var(--text-title-size-medium, 1.25rem);
60+
font-weight: var(--text-title-weight-medium, 600);
6061
}
6162
6263
.Blankslate-Description {
6364
color: var(--fgColor-muted, ${get('colors.fg.muted')});
64-
font-size: var(--text-body-size-large);
65+
font-size: var(--text-body-size-large, 1rem);
66+
line-height: var(--text-body-lineHeight-large, 1.5);
6567
}
6668
6769
.Blankslate-Action {
68-
margin-top: var(--stack-gap-normal);
70+
margin-top: var(--stack-gap-normal, 1rem);
6971
}
7072
7173
.Blankslate-Action:first-of-type {
72-
margin-top: var(--stack-gap-spacious);
74+
margin-top: var(--stack-gap-spacious, 1.5rem);
7375
}
7476
7577
.Blankslate-Action:last-of-type {
76-
margin-bottom: var(--stack-gap-condensed);
78+
margin-bottom: var(--stack-gap-condensed, 0.5rem);
7779
}
7880
`
7981

@@ -92,7 +94,7 @@ const BlankslateContainerQuery = `
9294
}
9395
9496
${StyledBlankslate} .Blankslate-Visual {
95-
margin-bottom: var(--stack-gap-condensed);
97+
margin-bottom: var(--stack-gap-condensed, 0.5rem);
9698
max-width: var(--base-size-24);
9799
}
98100
@@ -109,15 +111,15 @@ const BlankslateContainerQuery = `
109111
}
110112
111113
${StyledBlankslate} .Blankslate-Action {
112-
margin-top: var(--stack-gap-condensed);
114+
margin-top: var(--stack-gap-condensed, 0.5rem);
113115
}
114116
115117
${StyledBlankslate} .Blankslate-Action:first-of-type {
116-
margin-top: var(--stack-gap-normal);
118+
margin-top: var(--stack-gap-normal, 1rem);
117119
}
118120
119121
${StyledBlankslate} .Blankslate-Action:last-of-type {
120-
margin-bottom: calc(var(--stack-gap-condensed) / 2);
122+
margin-bottom: calc(var(--stack-gap-condensed, 0.5rem) / 2);
121123
}
122124
`
123125

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

0 commit comments

Comments
 (0)