You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+18-11Lines changed: 18 additions & 11 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -77,20 +77,25 @@ Check out examples for advanced usage.
77
77
78
78
### With Next.js `app` router (Server Components)
79
79
80
-
Update your `app/layout.jsx` to add `ThemeSwitcher` from `react18-themes`, and `NextJsSSRThemeSwitcher` from `react18-themes/server`. `NextJsSSRThemeSwitcher` is required to avoid flash of un-themed content on reload.
80
+
#### Prefer static generation over SSR - No wrapper component
81
+
82
+
> If your app is mostly serving static content, you do not want the overhead of SSR. Use `NextJsSSGThemeSwitcher` in this case.
83
+
> When using this approach, you need to use CSS general sibling Combinator (~) to make sure your themed CSS is properly applied. See (HTML & CSS)[#html--css].
84
+
85
+
Update your `app/layout.jsx` to add `ThemeSwitcher` from `react18-themes`, and `NextJsSSGThemeSwitcher` from `react18-themes/server`. `NextJsSSGThemeSwitcher` is required to avoid flash of un-themed content on reload.
/** use NextJsSSRThemeSwitcher as first element inside body */
93
-
<NextJsSSRThemeSwitcher />
97
+
/** use NextJsSSGThemeSwitcher as first element inside body */
98
+
<NextJsSSGThemeSwitcher />
94
99
<ThemeSwitcher />
95
100
{children}
96
101
</body>
@@ -101,11 +106,13 @@ export default function Layout({ children }) {
101
106
102
107
Woohoo! You just added multiple theme modes and you can also use Server Component! Isn't that awesome!
103
108
104
-
#### Version 1 (Legacy)
109
+
#### Prefer SSR over SSG - Use wrapper component
110
+
111
+
> If your app is serving dynamic content and you want to utilize SSR, continue using `ServerSideWrapper` component to replace `html` tag in `layout.tsx` file.
105
112
106
113
Update your `app/layout.jsx` to add `ThemeSwitcher` and `ServerSideWrapper` from `react18-themes`. `ServerSideWrapper` is required to avoid flash of un-themed content on reload.
@@ -141,7 +148,7 @@ That's it, your Next.js app fully supports dark mode, including System preferenc
141
148
--foreground: white;
142
149
}
143
150
144
-
// v2 onwards when using React18 server components, we need to use CSS Combinators
151
+
// v2 onwards when using NextJsSSGThemeSwitcher, we need to use CSS Combinators
145
152
[data-theme="dark"] ~* {
146
153
--background: black;
147
154
--foreground: white;
@@ -212,14 +219,14 @@ Forcing color scheme will apply your defaultDark or defaultLight theme, configur
212
219
213
220
#### Motivation:
214
221
215
-
For server side syncing, we need to use cookies and headers. This means that this component and its children can not be static. They will be rendered server side for each request. Thus, we are avoiding the wrapper. Now, only the `NextJsSSRThemeSwitcher` will be rendered server side for each request and rest of your app can be server statically.
222
+
For server side syncing, we need to use cookies and headers. This means that this component and its children can not be static. They will be rendered server side for each request. Thus, we are avoiding the wrapper. Now, only the `NextJsSSGThemeSwitcher` will be rendered server side for each request and rest of your app can be server statically.
216
223
217
224
Take care of the following while migrating to `v2`.
218
225
219
-
- No changes required for projects not using `Next.js` app router or server components.
226
+
- No changes required for projects not using `Next.js` app router or server components other than updating cookies policy if needed.
220
227
- The persistent storage is realized with `cookies` in place of `localStorage`. (You might want to update cookies policy accordingly.)
221
-
-`ServerSideWrapper` for `Next.js` is rebranded to `NextJsSSRThemeSwitcher`. No longer need to use this as a wrapper.
-We have provided `NextJsSSGThemeSwitcher` in addition to `ServerSideWrapper` for `Next.js`. You no longer need to use a wrapper component which broke static generation and forced SSR.
Copy file name to clipboardExpand all lines: examples/nextjs/README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -19,7 +19,7 @@ To learn more about Next.js, take a look at the following resources:
19
19
-[Next.js Documentation](https://nextjs.org/docs) - Learn about Next.js features and API.
20
20
-[Learn Next.js](https://www.udemy.com/course/react-and-next-js-with-typescript/?referralCode=7202184A1E57C3DCA8B2) - an interactive Next.js course.
21
21
22
-
You can check out [the Turbo Template GitHub repository](https://github.com/mayank1513/turborepo-template/) - your feedback and contributions are welcome!
22
+
You can check out [the Turbo Template GitHub repository](https://github.com/react18-tools/turborepo-template/) - your feedback and contributions are welcome!
Copy file name to clipboardExpand all lines: examples/vite/README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -16,7 +16,7 @@ To learn more about Next.js, take a look at the following resources:
16
16
-[Next.js Documentation](https://nextjs.org/docs) - Learn about Next.js features and API.
17
17
-[Learn Next.js](https://www.udemy.com/course/react-and-next-js-with-typescript/?referralCode=7202184A1E57C3DCA8B2) - an interactive Next.js course.
18
18
19
-
You can check out [the Turbo Template GitHub repository](https://github.com/mayank1513/turborepo-template/) - your feedback and contributions are welcome!
19
+
You can check out [the Turbo Template GitHub repository](https://github.com/react18-tools/turborepo-template/) - your feedback and contributions are welcome!
0 commit comments