Fix localStorage SSR error in favorites-store #1848
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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 devand accessinghttp://localhost:5173/, the application crashes with:The Fix:
Replaced
typeof localStorage !== 'undefined'checks with SvelteKit's built-inbrowserconstant from$app/environment. This is the proper SvelteKit way to differentiate between server-side and client-side execution contexts.Changes:
import { browser } from '$app/environment';typeof localStorage !== 'undefined'checks withbrowserThis prevents the application from attempting to access
localStorageduring 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 functionerrorAfter: Application loads successfully at http://localhost:5173/