Skip to content

Conversation

@domfahey
Copy link

Summary

  • Fixes localStorage.getItem is not a function errors in Next.js 15
  • Adds safe localStorage utility with SSR compatibility checks
  • Adds comprehensive CLAUDE.md documentation for codebase architecture

Problem

Next.js 15 with Node.js v25 causes SSR errors when accessing localStorage:

  • Error: localStorage.getItem is not a function
  • Warning: --localstorage-file was provided without a valid path

This occurs because Node.js v25 provides a broken localStorage polyfill during server-side rendering.

Solution

  1. Created lib/utils/storage.ts - Safe localStorage wrapper that:

    • Checks typeof window !== 'undefined'
    • Verifies window.localStorage exists and has correct function types
    • Wraps all access in try-catch blocks
    • Returns null safely when localStorage is unavailable
  2. Updated all localStorage calls in:

    • app/page.tsx - Main page component
    • app/fire-enrich/page.tsx - Fire Enrich page
    • app/fire-enrich/enrichment-table.tsx - Enrichment table component
  3. Added CLAUDE.md - Complete codebase documentation including:

    • Architecture overview of multi-agent system
    • Development commands and troubleshooting
    • Node.js v22 requirement documentation
    • Configuration details

Node.js Compatibility

  • Works with Node.js v22 (recommended)
  • Broken with Node.js v25 (known Next.js 15 incompatibility)

Test Plan

  • Tested with Node.js v22.21.1
  • Dev server starts without errors
  • Homepage loads successfully (HTTP 200)
  • No localStorage errors in console
  • Storage utility properly returns null on server-side
  • Client-side localStorage access works correctly

Breaking Changes

None - this is a bug fix that improves SSR compatibility.

Additional Notes

The package-lock.json was updated after switching to Node.js v22, which is the recommended version for Next.js 15.

🤖 Generated with Claude Code

- Add safe localStorage utility (lib/utils/storage.ts) with SSR checks
- Replace direct localStorage calls with getLocalStorageItem/setLocalStorageItem helpers
- Add comprehensive CLAUDE.md documentation for codebase architecture
- Update package-lock.json and pnpm-lock.yaml for Node.js v22

This fixes "localStorage.getItem is not a function" errors caused by
Next.js 15 incompatibility with Node.js v25. The new storage utility
properly checks for window.localStorage availability and function types
before accessing, ensuring compatibility across server and client environments.

Files changed:
- app/page.tsx: Use storage helpers in useEffect and event handlers
- app/fire-enrich/page.tsx: Use storage helpers for API key management
- app/fire-enrich/enrichment-table.tsx: Use storage helpers in callbacks
- lib/utils/storage.ts: New safe localStorage wrapper with SSR guards
- CLAUDE.md: Complete architecture documentation and troubleshooting guide

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
Copilot AI review requested due to automatic review settings November 18, 2025 11:00
Copilot finished reviewing on behalf of domfahey November 18, 2025 11:02
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR fixes localStorage SSR errors that occur when using Next.js 15 with Node.js v25 by implementing safe localStorage access utilities and comprehensive documentation.

Key Changes:

  • Created a new lib/utils/storage.ts module with SSR-safe localStorage wrappers that check for browser environment and function availability
  • Replaced all direct localStorage calls across three components with the new safe utilities
  • Added complete CLAUDE.md documentation covering architecture, development workflows, and Node.js compatibility requirements

Reviewed Changes

Copilot reviewed 5 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
lib/utils/storage.ts New utility module with SSR-safe localStorage wrapper functions
app/page.tsx Updated to use safe localStorage utilities for API key retrieval and storage
app/fire-enrich/page.tsx Updated to use safe localStorage utilities for API key retrieval and storage
app/fire-enrich/enrichment-table.tsx Updated to use safe localStorage utilities for API key retrieval
CLAUDE.md Comprehensive documentation of codebase architecture, development commands, and requirements
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant