Skip to content

fix: handle invalid bookmark storage#260

Open
saurabhhhcodes wants to merge 1 commit into
pushkarscripts:mainfrom
saurabhhhcodes:fix/bookmarks-invalid-json-236
Open

fix: handle invalid bookmark storage#260
saurabhhhcodes wants to merge 1 commit into
pushkarscripts:mainfrom
saurabhhhcodes:fix/bookmarks-invalid-json-236

Conversation

@saurabhhhcodes
Copy link
Copy Markdown

Summary

  • guard bookmark initialization against malformed openCSE_bookmarks localStorage data
  • clear corrupted bookmark storage instead of letting JSON.parse crash the page
  • ignore malformed bookmark entries while preserving valid saved bookmarks

Fixes #236

Root Cause

The useBookmarks hook directly parsed localStorage.getItem("openCSE_bookmarks") with JSON.parse() during initialization. If that stored value was not valid JSON, React hit a runtime exception before the bookmarks UI could render.

Changes Made

  • Added a shared BOOKMARKS_STORAGE_KEY constant
  • Added a small parser helper that validates the saved value is an array
  • Wrapped stored bookmark parsing in try/catch
  • Removed corrupted storage and reset bookmarks to an empty list on parse failure

Testing

  • npm run lint passes with existing repo warnings only
  • npm run build passes
  • git diff --check
  • Started local dev server on http://127.0.0.1:3026
  • Verified in headless Chrome via DevTools Protocol:
    • set localStorage.openCSE_bookmarks = "abc"
    • reloaded /bookmarks
    • confirmed the page still renders My Bookmarks
    • confirmed the corrupted storage key is cleared
    • confirmed zero runtime exceptions

Impact

Users with corrupted or manually edited bookmark storage no longer get blocked by a bookmarks initialization crash. The app recovers automatically and continues loading normally.

@vercel
Copy link
Copy Markdown
Contributor

vercel Bot commented Jun 6, 2026

Someone is attempting to deploy a commit to the PushkarScripts Team on Vercel.

A member of the Team first needs to authorize it.

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.

[BUG] Bookmarks feature crashes when localStorage contains invalid JSON

1 participant