Repository navigation
fix(chat): don't throw when reading localStorage is blocked - #252
Conversation
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.
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
🔍 Devin Review: 1 flag
Not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
Up to standards ✅🟢 Issues
|
| Metric | Results |
|---|---|
| Complexity | 0 |
| Duplication | 0 |
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.
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)
Reviewed by free · Input: 56.3K · Output: 7.3K · Cached: 199.5K |
Why
Starting a chat calls
loadStoredConversations()andcreateInitialChatState()with no storage argument. Both usedstorage = globalThis.localStorageas a default parameter, which is evaluated before thetrybody. In a storage-blocked iframe or similar environment, merely readinglocalStoragethrowsSecurityError, so the catch never ran and the app failed to open a conversation.What changed
Storage is resolved inside the existing
tryblocks. If that read throws,loadStoredConversationsstill returnsnullandcreateInitialChatStatestill opens a fresh chat. A test pins the SecurityError path.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
localStoragethrows (e.g. blocked iframeSecurityError). Default parameters onloadStoredConversationsandcreateInitialChatStatepreviously evaluatedglobalThis.localStoragebefore thetryblocks, so errors escaped and the app could not open a chat.Storage is now resolved inside those
tryblocks viastorage ?? globalThis.localStorage, so a failed read is caught: stored conversations fall back tonulland initial state still opens a fresh New Chat. A test mocks a throwinglocalStoragegetter 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.