Skip to content

Commit

Permalink
fix dark mode FOUC!!!!!
Browse files Browse the repository at this point in the history
  • Loading branch information
gutenfries committed Mar 11, 2024
1 parent 3fe4caf commit b13a70f
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 30 deletions.
4 changes: 2 additions & 2 deletions components/Head.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { asset, Head as FreshHead } from '$fresh/runtime.ts';
import { ErrorPageProps, PageProps, UnknownPageProps } from '$fresh/server.ts';
import { PageProps } from '$fresh/server.ts';

interface HeadProps {
PageProps: PageProps | UnknownPageProps | ErrorPageProps;
PageProps: PageProps;
}

function Head({ PageProps }: HeadProps) {
Expand Down
2 changes: 0 additions & 2 deletions fresh.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import { defineConfig } from '$fresh/server.ts';
import tailwind from '$fresh/plugins/tailwind.ts';
import tailwindConfig from '@/tailwind.config.ts';
import themeMode from '@/plugins/themeMode.ts';

export default defineConfig({
plugins: [
tailwind(tailwindConfig), // ignore error, bug within the framework plugin
// themeMode(),
],
});
26 changes: 0 additions & 26 deletions plugins/themeMode.ts

This file was deleted.

12 changes: 12 additions & 0 deletions routes/_app.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,18 @@ import { PageProps } from '$fresh/server.ts';
export default function App({ Component /* state */ }: PageProps) {
return (
<>
{/* SSR for dark/light mode */}
<script>
{`(function () {
try {
const mode = localStorage.getItem('theme');
document.getElementsByTagName('html')[0].className = mode === 'dark' ? 'dark' : 'light';
} catch (e) {
console.error(e);
}
})();
`}
</script>
<link rel='stylesheet' href='/styles/tailwind.css' />
<Component />
</>
Expand Down

0 comments on commit b13a70f

Please # to comment.