Skip to content

Commit 03859a7

Browse files
Apply suggestions from code review
Co-authored-by: Sarah <sali@twilio.com>
1 parent f0ceb10 commit 03859a7

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

packages/paste-website/src/pages/blog/2025-03-20-css-variables-ssr-ssg.mdx

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ This section will cover how we implemented this solution on the Paste documentat
105105

106106
### _documents.tsx
107107

108-
We added a script to the <InlineCode>head</InlineCode> of our <InlineCode>_documents.tsx</InlineCode> file to set the <InlineCode>data-theme</InlineCode> attribute on the <InlineCode>body</InlineCode> element element using a script. This script will check to see if they have a cookie set and if not check the systme prefernces to determine whether users prefer dark or light themes and apply the dark theme if they do. Otherwise we do not set a value. You will see in <InlineCode>_app.tsx</InlineCode> how we handle the default value.
108+
We added a script to the <InlineCode>head</InlineCode> of our <InlineCode>_documents.tsx</InlineCode> file to set the <InlineCode>data-theme</InlineCode> attribute on the <InlineCode>body</InlineCode> element using a script. This script will check to see if users have a cookie set and if not check the system preferences to determine whether users prefer dark or light themes, and apply the dark theme if they do. Otherwise we do not set a value. You will see in <InlineCode>_app.tsx</InlineCode> how we handle the default value.
109109

110110
Here is the script that is found in <Anchor showExternal={true} href="https://github.com/twilio-labs/paste/blob/main/packages/paste-website/src/pages/_document.tsx"><InlineCode>_documents.tsx</InlineCode></Anchor>:
111111

@@ -132,9 +132,9 @@ Here is the script that is found in <Anchor showExternal={true} href="https://gi
132132

133133
### _app.tsx
134134

135-
In our <InlineCode>_app.tsx</InlineCode> file we import the CSS files that should be applues. We have 2, one that applies the values to root and is considered the default theme and the other that uses the new <InlineCode>tokens.data-theme.css</InlineCode> attribute to apply the theme based on the value set in the <InlineCode>data-theme</InlineCode> attribute.
135+
In our <InlineCode>_app.tsx</InlineCode> file we import the CSS files that should be applied. We have 2: One that applies the values to root and is considered the default theme, and the other that uses the new <InlineCode>tokens.data-theme.css</InlineCode> attribute to apply the theme based on the value set in the <InlineCode>data-theme</InlineCode> attribute.
136136

137-
You can find the source code <Anchor showExternal={true} href="https://github.com/twilio-labs/paste/blob/main/packages/paste-website/src/pages/_app.tsx">here</Anchor>.
137+
You can find the <Anchor showExternal={true} href="https://github.com/twilio-labs/paste/blob/main/packages/paste-website/src/pages/_app.tsx">source code for _app.tsx here</Anchor>.
138138

139139
<Box marginBottom="space60">
140140
<CodeBlockWrapper>
@@ -149,7 +149,7 @@ Note here that the import <InlineCode>"@twilio-paste/design-tokens/dist/themes/t
149149

150150
#### ThemeProvider
151151

152-
In this same file we set the ThemeProvider to use CSS variables instead of the theme files we previously configured. Note that we only want to use CSS variables when encoutnering this issue and not as a standard. For all other use cases we recommend using the <InlineCode>theme</InlineCode> prop.
152+
In this same file we set the ThemeProvider to use CSS variables instead of the theme files we previously configured. Note that we only want to use CSS variables when encountering this issue and not as a standard. For all other use cases we recommend using the <InlineCode>theme</InlineCode> prop.
153153

154154
<Box marginBottom="space60">
155155
<CodeBlockWrapper>
@@ -163,7 +163,7 @@ In this same file we set the ThemeProvider to use CSS variables instead of the t
163163

164164
### Switching the theme
165165

166-
We have a hook that is used to switch the themes in <Anchor showExternal={true} href="https://github.com/twilio-labs/paste/blob/main/packages/paste-website/src/hooks/useDarkMode.tsx"><InlineCode>useDarkMode.tsx</InlineCode></Anchor>. It is in the <InlineCode>setMode</InlineCode> function we handle setting the data attribute on the body element. This occurs when the user intentionally changes the theme using the theme switcher in the header as this will run client side it cannot be used to set the default value. That comes from the script in the <InlineCode>_document.tsx</InlineCode>.
166+
We have a hook that is used to switch the themes in <Anchor showExternal={true} href="https://github.com/twilio-labs/paste/blob/main/packages/paste-website/src/hooks/useDarkMode.tsx"><InlineCode>useDarkMode.tsx</InlineCode></Anchor>. In the <InlineCode>setMode</InlineCode> function, we handle setting the data attribute on the body element. This occurs when the user intentionally changes the theme using the theme switcher in the header. As this will run client side, it cannot be used to set the default value. That comes from the script in the <InlineCode>_document.tsx</InlineCode>.
167167

168168
<Box marginBottom="space60">
169169
<CodeBlockWrapper>

packages/paste-website/src/pages/theme/changing-theme.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ Alternatively, Paste will automatically load the default theme's font via JavaSc
6565

6666
## SSR and SSG
6767

68-
If you are using server-side rendering (SSR) or static site generation (SSG), <strong>and</strong> you support theme switching you will need to use CSS variables and setting a body data-theme attribute instead to avoid theme flicker on initial renders. You can view our <Anchor href="/blog/2025-03-20-css-variables-ssr-ssg/">blog post</Anchor> on this topic, dicussing the problem and demonstrating how we solved it in the Paste website.
68+
If you are using server-side rendering (SSR) or static site generation (SSG), <strong>and</strong> you support theme switching, you will need to use CSS variables and setting a body data-theme attribute instead to avoid theme flicker on initial renders. You can view our <Anchor href="/blog/2025-03-20-css-variables-ssr-ssg/">blog post</Anchor> on this topic, discussing the problem and demonstrating how we solved it in the Paste website.
6969

7070
```jsx
7171
<Theme.Provider

0 commit comments

Comments
 (0)