Skip to content
This repository was archived by the owner on Jun 16, 2026. It is now read-only.

fix(useBookmarks): add SSR guard before localStorage access in readStorage/writeStorage#9210

Open
tmdeveloper007 wants to merge 1 commit into
SandeepVashishtha:masterfrom
tmdeveloper007:9203-usebookmarks-ssr
Open

fix(useBookmarks): add SSR guard before localStorage access in readStorage/writeStorage#9210
tmdeveloper007 wants to merge 1 commit into
SandeepVashishtha:masterfrom
tmdeveloper007:9203-usebookmarks-ssr

Conversation

@tmdeveloper007

Copy link
Copy Markdown
Contributor

Summary

Add typeof window === 'undefined' guards to the readStorage and writeStorage helper functions in src/hooks/useBookmarks.js. These functions are called during hook state initialization (useState initializer), which runs during SSR in Next.js/Remix environments. Without the guards, localStorage access causes a ReferenceError that crashes the server.

Changes

  • Add SSR guard to readStorage(key) returning [] when typeof window === 'undefined'
  • Add SSR guard to writeStorage(key, value) returning early when typeof window === 'undefined'

Impact

Fixes server-side rendering crashes. All bookmark functionality becomes unavailable during SSR without this fix.

Closes #9203.

@vercel

vercel Bot commented Jun 15, 2026

Copy link
Copy Markdown
Contributor

@tmdeveloper007 is attempting to deploy a commit to the sandeepvashishtha's projects Team on Vercel.

A member of the Team first needs to authorize it.

@tmdeveloper007

Copy link
Copy Markdown
Contributor Author

@SandeepVashishtha Ready for review — PR #9210: Add SSR guards to useBookmarks localStorage access

@github-actions github-actions Bot added the size/XS Extra-small pull request label Jun 15, 2026

@codescene-access codescene-access Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Our agent can fix these. Install it.

Gates Passed
4 Quality Gates Passed

Quality Gate Profile: Clean Code Collective
Install CodeScene MCP: safeguard and uplift AI-generated code. Catch issues early with our IDE extension and CLI tool.

@github-actions github-actions Bot added the bug Something isn't working label Jun 15, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug Something isn't working gssoc:approved gssoc approved PR level:beginner 20pts quality:clean 1.2x size/XS Extra-small pull request type:bug type:feature type:testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(src/hooks/useBookmarks.js): add SSR guard before localStorage access in readStorage

1 participant