Skip to content

Commit 5653f9c

Browse files
committed
chore: fix ssr flash
1 parent 4c08bb5 commit 5653f9c

File tree

3 files changed

+13
-14
lines changed

3 files changed

+13
-14
lines changed

resources/js/components/AppearanceTabs.vue

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useCookies } from "@vueuse/integrations/useCookies";
44
import { Monitor, Moon, Sun } from "lucide-vue-next";
55
import { watchEffect } from "vue";
66
7-
const { store } = useColorMode({});
7+
const { store } = useColorMode();
88
const cookies = useCookies(["appearance"]);
99
const tabs = [
1010
{ value: "light", Icon: Sun, label: "Light" },

resources/js/ssr.ts

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,17 +39,16 @@ createServer(page =>
3939
// @ts-expect-error: global will be available
4040
globalThis.route = route;
4141
}
42+
43+
const cookie = useCookies(["appearance"]);
44+
const { store } = useColorMode();
45+
const appearance: "light" | "dark" | "auto" | null = cookie.get("appearance") ?? null;
46+
47+
if (appearance) {
48+
store.value = appearance;
49+
}
4250
else {
43-
const cookie = useCookies(["appearance"]);
44-
const { store } = useColorMode();
45-
const appearance: "light" | "dark" | "auto" | null = cookie.get("appearance") ?? null;
46-
47-
if (appearance) {
48-
store.value = appearance;
49-
}
50-
else {
51-
store.value = "auto";
52-
}
51+
store.value = "auto";
5352
}
5453

5554
app.use(plugin);

resources/views/app.blade.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<!DOCTYPE html>
2-
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}" @class(['dark' => ($appearance ?? 'auto') == 'dark'])>
2+
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}" @class(['dark' => ($appearance ?? 'auto') === 'dark'])>
33
<head>
44
<meta charset="utf-8">
55
<meta name="viewport" content="width=device-width, initial-scale=1">
@@ -9,9 +9,9 @@
99
(function() {
1010
const appearance = '{{ $appearance ?? "auto" }}';
1111
12-
if (appearance === 'system') {
12+
if (appearance === 'auto') {
1313
const prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches;
14-
14+
1515
if (prefersDark) {
1616
document.documentElement.classList.add('dark');
1717
}

0 commit comments

Comments
 (0)