Skip to content

Conversation

@zeddy303
Copy link
Contributor

What this Pull Request (PR) does

This PR fixes a server-side rendering (SSR) error that occurs when running the Fabric web interface in development mode.

The Problem:
When running pnpm run dev and accessing http://localhost:5173/, the application crashes with:

TypeError: localStorage.getItem is not a function
    at /var/home/zane/git/fabric/web/src/lib/store/favorites-store.ts:5:29

The Fix:
Replaced typeof localStorage !== 'undefined' checks with SvelteKit's built-in browser constant from $app/environment. This is the proper SvelteKit way to differentiate between server-side and client-side execution contexts.

Changes:

  • Added import: import { browser } from '$app/environment';
  • Replaced all typeof localStorage !== 'undefined' checks with browser

This prevents the application from attempting to access localStorage during server-side rendering, where it doesn't exist.

Related issues

N/A - Discovered during fresh setup following the web/README.md instructions.

Screenshots

Before: Application crashes with localStorage.getItem is not a function error
After: Application loads successfully at http://localhost:5173/

Use SvelteKit's browser constant instead of typeof localStorage check
to properly handle server-side rendering. Prevents 'localStorage.getItem
is not a function' error when running dev server.
@ksylvan
Copy link
Collaborator

ksylvan commented Dec 1, 2025

Great! Was just about to fix this. Thank you. Will merge soon.

@ksylvan ksylvan self-assigned this Dec 1, 2025
@ksylvan ksylvan merged commit e2d4aab into danielmiessler:main Dec 1, 2025
1 check passed
@ksylvan
Copy link
Collaborator

ksylvan commented Dec 1, 2025

@zeddy303 In the latest release. Thanks for your contribution.

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.

2 participants