Skip to content

Commit 946484c

Browse files
author
Rajat
committed
Fixed nextTheme detection
1 parent 7916e23 commit 946484c

File tree

2 files changed

+15
-5
lines changed

2 files changed

+15
-5
lines changed

apps/web/components/public/base-layout/template/widget-by-name.tsx

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import React from "react";
1+
import React, { useState, useEffect } from "react";
22
import widgets from "@/ui-config/widgets";
33
import { COMPONENT_MISSING_SUFFIX } from "@/ui-config/strings";
44
import 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

packages/components-library/src/section-background-panel.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff 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
/>

0 commit comments

Comments
 (0)