Skip to content

Commit a8a8968

Browse files
dschoepelclaude
andcommitted
fix(ssr): guard localStorage in useState initializers to fix static build
useState lazy initializers run during Next.js server-side rendering (even in 'use client' components), causing ReferenceError: localStorage is not defined during static page generation for the YAML utility page. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
1 parent 4acd512 commit a8a8968

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

app/utilities/_components/hooks/useYamlUtilityFiles.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { checkFileExists as checkFileExistsService, readFile } from '../../../..
1010
export const useYamlUtilityFiles = () => {
1111
const [selectedFiles, setSelectedFiles] = useState(() => {
1212
try {
13+
if (typeof window === 'undefined') return [];
1314
const saved = localStorage.getItem('yaml-utility-files');
1415
if (saved) {
1516
const files = JSON.parse(saved);
@@ -28,6 +29,7 @@ export const useYamlUtilityFiles = () => {
2829

2930
const [showViewer, setShowViewer] = useState(() => {
3031
try {
32+
if (typeof window === 'undefined') return false;
3133
const saved = localStorage.getItem('yaml-utility-viewer-open');
3234
const savedFiles = localStorage.getItem('yaml-utility-files');
3335
return saved === 'true' && savedFiles && JSON.parse(savedFiles).length > 0;

0 commit comments

Comments
 (0)