Skip to content

Commit f180a63

Browse files
authored
Merge pull request #26 from techniq/fix-head-snippet-hydration
Resolve `[svelte] hydration_html_changed` issue
2 parents 1661f47 + ad843a4 commit f180a63

File tree

2 files changed

+10
-3
lines changed

2 files changed

+10
-3
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@layerstack/tailwind': patch
3+
---
4+
5+
fix(createHeadSnippet): Resolve `[svelte] hydration_html_changed` issue. Resolves #25

packages/tailwind/src/lib/theme.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,10 @@ export function themeStylesString(theme: NestedColors, colorSpace: SupportedColo
261261
* but it's the only way to inject the `darkThemes` array into the function.
262262
**/
263263
export function createHeadSnippet(darkThemes: string[]) {
264-
function _applyInitialStyle(darkThemes: string[]) {
264+
const applyInitialStyle = `
265+
function applyInitialStyle(darkThemes) {
265266
let theme = localStorage.getItem('theme');
266-
// Ignore if no dark things registered (default `dark` removed)
267+
// Ignore if no dark things registered (default 'dark' removed)
267268
if (darkThemes.length > 0) {
268269
if (theme) {
269270
document.documentElement.dataset.theme = theme;
@@ -275,8 +276,9 @@ export function createHeadSnippet(darkThemes: string[]) {
275276
}
276277
}
277278
}
279+
`;
278280

279281
let darkThemeList = darkThemes.map((theme) => `'${theme}'`).join(', ');
280282

281-
return `<script>(${_applyInitialStyle.toString()})([${darkThemeList}])</script>`;
283+
return `<script>${applyInitialStyle}([${darkThemeList}])</script>`;
282284
}

0 commit comments

Comments
 (0)