File tree Expand file tree Collapse file tree 2 files changed +15
-5
lines changed
apps/web/components/public/base-layout/template
packages/components-library/src Expand file tree Collapse file tree 2 files changed +15
-5
lines changed Original file line number Diff line number Diff line change 1- import React from "react" ;
1+ import React , { useState , useEffect } from "react" ;
22import widgets from "@/ui-config/widgets" ;
33import { COMPONENT_MISSING_SUFFIX } from "@/ui-config/strings" ;
44import WidgetErrorBoundary from "@/components/public/base-layout/template/widget-error-boundary" ;
@@ -13,10 +13,21 @@ const WidgetByName = ({
1313 pageData,
1414 editing = false ,
1515} : Omit < WidgetProps < WidgetDefaultSettings > , "toggleTheme" | "nextTheme" > ) => {
16- const { resolvedTheme : nextTheme , setTheme : setNextTheme } = useTheme ( ) ;
16+ const { resolvedTheme, setTheme : setNextTheme } = useTheme ( ) ;
17+ const [ mounted , setMounted ] = useState ( false ) ;
18+
19+ useEffect ( ( ) => {
20+ // This is the recommended pattern from next-themes to avoid hydration mismatch.
21+ // The effect intentionally runs once to trigger a re-render with the correct theme.
22+ // eslint-disable-next-line react-hooks/set-state-in-effect
23+ setMounted ( true ) ;
24+ } , [ ] ) ;
25+
26+ // Use undefined during SSR/hydration to match server, then switch to actual theme after mount
27+ const nextTheme = mounted ? resolvedTheme : undefined ;
1728
1829 const toggleTheme = ( ) => {
19- const themeNext = nextTheme === "dark" ? "light" : "dark" ;
30+ const themeNext = resolvedTheme === "dark" ? "light" : "dark" ;
2031 setNextTheme ( themeNext ) ;
2132 } ;
2233
Original file line number Diff line number Diff line change @@ -146,8 +146,7 @@ export function SectionBackgroundPanel({
146146 value = { value . backgroundColor || "" }
147147 onChange = { ( color ) =>
148148 handleColorBackgroundChange ( {
149- backgroundColor :
150- color || "#ffffff" ,
149+ backgroundColor : color ,
151150 } )
152151 }
153152 />
You can’t perform that action at this time.
0 commit comments