Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/tricky-cougars-retire.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@layerstack/tailwind': patch
---

fix(createHeadSnippet): Resolve `[svelte] hydration_html_changed` issue. Resolves #25
8 changes: 5 additions & 3 deletions packages/tailwind/src/lib/theme.ts
Original file line number Diff line number Diff line change
Expand Up @@ -261,9 +261,10 @@ export function themeStylesString(theme: NestedColors, colorSpace: SupportedColo
* but it's the only way to inject the `darkThemes` array into the function.
**/
export function createHeadSnippet(darkThemes: string[]) {
function _applyInitialStyle(darkThemes: string[]) {
const applyInitialStyle = `
function applyInitialStyle(darkThemes) {
let theme = localStorage.getItem('theme');
// Ignore if no dark things registered (default `dark` removed)
// Ignore if no dark things registered (default 'dark' removed)
if (darkThemes.length > 0) {
if (theme) {
document.documentElement.dataset.theme = theme;
Expand All @@ -275,8 +276,9 @@ export function createHeadSnippet(darkThemes: string[]) {
}
}
}
`;

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

return `<script>(${_applyInitialStyle.toString()})([${darkThemeList}])</script>`;
return `<script>${applyInitialStyle}([${darkThemeList}])</script>`;
}