Pinned subjects: a bad localStorage value crashes the page

未關閉
#559 0 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

@Dx-Alz-xD 已經在處理了。

開始於 2026年11月11日。

  • #566 來自 @Dx-Alz-xD —— 未關閉

評估

難度
2/5
預估耗時
1-3 小時
新手友好度
35/100
Issue 類型
缺陷
描述清晰度
描述清楚
活躍度
停滯
技術堆疊
react, typescript
領域
frontend

研究方向

Start with the listed reads in src/components/Searchbar/pinned-searchbar.tsx, src/components/CatalogueContent.tsx, src/components/PinnedPapersCarousel.tsx, and src/components/ui/PinnedModal.tsx, then check whether the project has a shared utility pattern. The issue calls for a helper that returns an empty list and clears the key when stored data is missing, invalid, or not an array of strings; done means all listed reads use it and the reproduction no longer crashes. An open linked pull request (#566) means this work is already under way.

由索引模型根據 Issue 內容生成。

描述

Describe the bug
several components read pinned subjects with JSON.parse(localStorage.getItem("userSubjects") ?? "[]") w/o a try or catch and assume the result is an array

  • src/components/Searchbar/pinned-searchbar.tsx (lines 56, 97, 136 and 155)
  • src/components/CatalogueContent.tsx (lines 97 and 139)
  • src/components/PinnedPapersCarousel.tsx (lines 66 and119)
  • src/components/ui/PinnedModal.tsx (lines 105 and 147)

If the stored value isntt valid JSON, or isnt an array JSON.parse throws or .length/.filter fails, and the component crashes bad

To Reproduce

  1. In the browser console put localStorage.setItem("userSubjects", "oops")
  2. Reload a page that shows pinned subjects
  3. The page errors instead of showing an empty pinned list

Expected behavior
A small shared helper that returns [] (and clears the key) when the value is missing invalid or not an array of strings used everywhere these components read userSubjects

主要語言
TypeScript
星號
22
分支
66
PR 合併指標
30 天內沒有已合併 PR

環境準備

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

CodeChefVIT/papers-codechef 的其他 Issue

查看 CodeChefVIT/papers-codechef 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。