Skip to content

fix(pinned): ignore a corrupted pinned subjects value - #566

Open
Dx-Alz-xD wants to merge 1 commit into
CodeChefVIT:stagingfrom
Dx-Alz-xD:krish/safe-pinned-subjects
Open

Dx-Alz-xD wants to merge 1 commit into
CodeChefVIT:stagingfrom
Dx-Alz-xD:krish/safe-pinned-subjects

Conversation

@Dx-Alz-xD

Copy link
Copy Markdown

📌 Purpose

12 places parsed userSubjects from localStorage without a try/catch, so a value that wasnt a JSON array crashed the page


Corresponding issue: closes #559


🖼️ Showcase

After localStorage.setItem("userSubjects", "oops") and a reload of the home page

  • staging: blank page with the Next.js error overlay
  • this branch: page renders the bad value is cleared, and pinning still saves normally

🔧 Changes

  • New readPinnedSubjects() in src/lib/utils/pinned-subjects.ts: returns the saved list, or [] and clears the key if its invalid
  • Used in CatalogueContent, PinnedPapersCarousel, pinned-searchbar, PinnedModal and UpcomingPaper

➕ Additional Notes

  • No change for users whose saved value is valid

components parsed userSubjects from localStorage without a try/catch,
so a value that was not a json array crashed the page. read it through
readPinnedSubjects, which falls back to an empty list and clears the bad
value

This branch has not been deployed

No deployments
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.

Pinned subjects: a bad localStorage value crashes the page

1 participant