Skip to content

fix(chat): don't throw when reading localStorage is blocked - #252

Merged
mangeshraut712 merged 1 commit into
mainfrom
fix/chat-storage-blocked-localstorage
Nov 25, 2026
Merged

mangeshraut712 merged 1 commit into
mainfrom
fix/chat-storage-blocked-localstorage

Conversation

@mangeshraut712

@mangeshraut712 mangeshraut712 commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Why

Starting a chat calls loadStoredConversations() and createInitialChatState() with no storage argument. Both used storage = globalThis.localStorage as a default parameter, which is evaluated before the try body. In a storage-blocked iframe or similar environment, merely reading localStorage throws SecurityError, so the catch never ran and the app failed to open a conversation.

What changed

Storage is resolved inside the existing try blocks. If that read throws, loadStoredConversations still returns null and createInitialChatState still opens a fresh chat. A test pins the SecurityError path.


Devin Review


Note

Low Risk
Narrow change to storage read timing and graceful degradation; no auth or persistence semantics beyond existing try/catch behavior.

Overview
Fixes chat startup in environments where merely accessing localStorage throws (e.g. blocked iframe SecurityError). Default parameters on loadStoredConversations and createInitialChatState previously evaluated globalThis.localStorage before the try blocks, so errors escaped and the app could not open a chat.

Storage is now resolved inside those try blocks via storage ?? globalThis.localStorage, so a failed read is caught: stored conversations fall back to null and initial state still opens a fresh New Chat. A test mocks a throwing localStorage getter to lock in that behavior.

Reviewed by Cursor Bugbot for commit d0e8554. Bugbot is set up for automated code reviews on this repo. Configure here.

loadStoredConversations and createInitialChatState wrapped storage
access in try/catch so a blocked store could start a fresh chat, but
the default parameter evaluated globalThis.localStorage before the
try ran. In a storage-blocked iframe that throws SecurityError, the
app crashed instead of opening a new conversation.
@chatgpt-codex-connector

chatgpt-codex-connector Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Codex Review Summary: ✅ Completed

This comment shows the latest Codex review activity on this pull request.

Review Status Commit Review trigger
📝 Code Review ✅ Completed 2026-11-25T16:28:53.563997Z d0e8554 PR opened
🔒 Security Review ✅ Completed 2026-11-25T16:29:51.348236Z d0e8554 PR opened
ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review" or "@codex security review".

Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings.

@devin-ai-integration devin-ai-integration 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.

🔍 Devin Review: 1 flag

Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

@codacy-production

Copy link
Copy Markdown

Up to standards ✅

🟢 Issues 0 issues

Results:
0 new issues

View in Codacy

🟢 Metrics 0 complexity · 0 duplication

Metric Results
Complexity 0
Duplication 0

View in Codacy

NEW Get contextual insights on your PRs based on Codacy's metrics, along with PR and Jira context, without leaving GitHub. Enable AI reviewer
TIP This summary will be updated as you push new changes.

@mangeshraut712
mangeshraut712 merged commit 7a8caea into main Nov 25, 2026
12 checks passed
@mangeshraut712
mangeshraut712 deleted the fix/chat-storage-blocked-localstorage branch November 25, 2026 16:31
@kilo-code-bot

kilo-code-bot Bot commented Nov 25, 2026 •

Copy link
Copy Markdown

Code Review Roast 🔥

Verdict: No Issues Found | Recommendation: Merge

Oh wait, this PR is actually clean. I need to sit down. I had my flamethrower warmed up and everything.

📊 Overall: Like finding a unicorn in production — I didn't think clean PRs existed anymore, but here we are.

Files Reviewed (2 files)
  • src/lib/conversations.js
  • src/lib/conversations.test.js

Reviewed by free · Input: 56.3K · Output: 7.3K · Cached: 199.5K

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.

1 participant