The Postgres development platform. Supabase gives you a dedicated Postgres database to build your web, mobile, and AI applications.
TypeScript aialternativeauthdatabasedenoembeddingsexamplefirebasenextjsoauth2pgvectorpostgispostgrespostgresqlpostgrestrealtimesupabasevectorswebsockets
no longer forcing theme in next/theme (#22817)
Jonathan Summers-Muir919427231b6c
diff --git a/apps/www/components/Layouts/Default.tsx b/apps/www/components/Layouts/Default.tsxindex 375cb1fd2d0..e20d3563378 100644--- a/apps/www/components/Layouts/Default.tsx+++ b/apps/www/components/Layouts/Default.tsx@@ -1,6 +1,7 @@import Nav from 'components/Nav/index'import Footer from 'components/Footer/index'import { cn } from 'ui'+import { useForceDeepDark } from '~/lib/theme.utils'type Props = {hideHeader?: boolean@@ -19,6 +20,8 @@ const DefaultLayout = (props: Props) => {children,} = props+ useForceDeepDark()+return (<><Nav hideNavbar={hideHeader} />diff --git a/apps/www/lib/theme.utils.ts b/apps/www/lib/theme.utils.tsnew file mode 100644index 00000000000..d724e802406--- /dev/null+++ b/apps/www/lib/theme.utils.ts@@ -0,0 +1,43 @@+import { useEffect } from 'react'+import { useTheme } from 'next-themes'+import { useRouter } from 'next/router'++export function useForceDeepDark() {+ const router = useRouter()+ const { resolvedTheme, theme } = useTheme()++ const isDarkTheme = resolvedTheme?.includes('dark')+ const isGaSection = router.pathname.includes('/ga-week') || router.pathname === '/ga'++ useEffect(() => {+ const handleDocumentLoad = () => {+ // Update the HTML element attributes+ const theme = isDarkTheme ? (isGaSection ? 'deep-dark' : 'dark') : 'light'++ document.documentElement.setAttribute('data-theme', theme)+ document.documentElement.style.colorScheme = theme++ // wait before setting the theme+ setTimeout(() => {+ document.documentElement.setAttribute('data-theme', theme)+ document.documentElement.style.colorScheme = theme+ }, 200)++ // Clean up the event listener+ window.removeEventListener('load', handleDocumentLoad)+ }++ // Check if document is already loaded+ if (document.readyState === 'complete') {+ handleDocumentLoad()+ } else {+ // Add a global load event listener+ window.addEventListener('load', handleDocumentLoad)+ }++ // Clean up the event listener on component unmount+ return () => {+ window.removeEventListener('load', handleDocumentLoad)+ }+ }, [resolvedTheme, theme, isDarkTheme, router])+}diff --git a/apps/www/pages/ga-week/index.tsx b/apps/www/pages/ga-week/index.tsxindex 706f20c4fec..5cb1a9c4d5e 100644--- a/apps/www/pages/ga-week/index.tsx+++ b/apps/www/pages/ga-week/index.tsx@@ -14,7 +14,6 @@ import { Meetup } from '~/components/LaunchWeek/11/LW11Meetups'import LW11StickyNav from '~/components/LaunchWeek/11/Releases/LW11StickyNav'import LW11Header from '~/components/LaunchWeek/11/Releases/LW11Header'import MainStage from '~/components/LaunchWeek/11/Releases/MainStage'-import { useTheme } from 'next-themes'const BuildStage = dynamic(() => import('~/components/LaunchWeek/11/Releases/BuildStage'))const LW11Meetups = dynamic(() => import('~/components/LaunchWeek/11/LW11Meetups'))@@ -29,7 +28,6 @@ interface Props {export default function GAWeekIndex({ meetups }: Props) {const { query } = useRouter()- const { resolvedTheme, setTheme } = useTheme()const TITLE = 'Supabase GA Week | 15-19 April 2024'const DESCRIPTION = 'Join us for a week of announcing new features, every day at 7 AM PT.'@@ -65,19 +63,6 @@ export default function GAWeekIndex({ meetups }: Props) {}}, [supabase])- const isDark = resolvedTheme?.includes('dark')- const isDarkTheme = resolvedTheme === 'dark'-- useEffect(() => {- isDarkTheme && setTheme('deep-dark')- }, [isDarkTheme])-- useEffect(() => {- return () => {- isDark && setTheme('dark')- }- }, [])-useEffect(() => {if (session?.user) {if (userData?.id) {diff --git a/apps/www/pages/ga.tsx b/apps/www/pages/ga.tsxindex 48d367ff2eb..9624ae133bc 100644--- a/apps/www/pages/ga.tsx+++ b/apps/www/pages/ga.tsx@@ -1,4 +1,4 @@-import React, { useEffect } from 'react'+import React from 'react'import dynamic from 'next/dynamic'import Link from 'next/link'import { useRouter } from 'next/router'@@ -19,7 +19,7 @@ const CTABanner = dynamic(() => import('~/components/CTABanner'))export default function IndexPage() {const router = useRouter()- const { resolvedTheme, setTheme } = useTheme()+ const { resolvedTheme } = useTheme()const isDark = resolvedTheme?.includes('dark')const data = pageData(isDark!)@@ -27,18 +27,6 @@ export default function IndexPage() {const meta_description = 'Supabase is officially launching into General Availability.'const meta_image = '/images/ga/ga-og-alt.png'- const isDarkTheme = resolvedTheme === 'dark'-- useEffect(() => {- isDarkTheme && setTheme('deep-dark')- }, [isDarkTheme])-- useEffect(() => {- return () => {- isDark && setTheme('dark')- }- }, [])-return (<DefaultLayout><NextSeo