Skip to content

Commit c139634

Browse files
Refactor development settings management in HomeClient component
1 parent 2874d73 commit c139634

File tree

1 file changed

+23
-14
lines changed

1 file changed

+23
-14
lines changed

src/components/HomeClient.tsx

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -65,28 +65,37 @@ export default function HomeClient({ content }: HomeClientProps) {
6565
const heroRef = useRef<HTMLElement>(null);
6666
const scrollProgress = useScrollProgress(heroRef);
6767
const isMobile = useMediaQuery("(max-width: 900px)");
68-
const [devEnabled] = useState(() => {
69-
const params = new URLSearchParams(window.location.search);
70-
return params.get("dev") === "1" || process.env.NEXT_PUBLIC_DEVTOOLS === "1";
68+
const [devEnabled, setDevEnabled] = useState(false);
69+
const [devSettings, setDevSettings] = useState<DevSettings>(defaultDevSettings);
70+
const [terminalApi, setTerminalApi] = useState<TerminalApi | null>(null);
71+
const [terminalFocused, setTerminalFocused] = useState(false);
72+
const [debugInfo, setDebugInfo] = useState<SceneDebugInfo>({
73+
meshNames: [],
74+
screenMeshName: null,
75+
fallbackPlane: false,
7176
});
72-
const [devSettings, setDevSettings] = useState<DevSettings>(() => {
77+
78+
useEffect(() => {
79+
if (typeof window === "undefined") {
80+
return;
81+
}
82+
const params = new URLSearchParams(window.location.search);
83+
setDevEnabled(params.get("dev") === "1" || process.env.NEXT_PUBLIC_DEVTOOLS === "1");
84+
}, []);
85+
86+
useEffect(() => {
87+
if (typeof window === "undefined") {
88+
return;
89+
}
7390
try {
7491
const raw = localStorage.getItem("devtools");
7592
if (raw) {
76-
return { ...defaultDevSettings, ...JSON.parse(raw) } as DevSettings;
93+
setDevSettings((prev) => ({ ...prev, ...JSON.parse(raw) } as DevSettings));
7794
}
7895
} catch {
7996
// ignore
8097
}
81-
return defaultDevSettings;
82-
});
83-
const [terminalApi, setTerminalApi] = useState<TerminalApi | null>(null);
84-
const [terminalFocused, setTerminalFocused] = useState(false);
85-
const [debugInfo, setDebugInfo] = useState<SceneDebugInfo>({
86-
meshNames: [],
87-
screenMeshName: null,
88-
fallbackPlane: false,
89-
});
98+
}, []);
9099

91100
const projectsMd = useMemo(() => {
92101
return [

0 commit comments

Comments
 (0)