fix(mothership): catch draft restore errors instead of crashing /home#4433
fix(mothership): catch draft restore errors instead of crashing /home#4433waleedlatif1 merged 2 commits intostagingsimstudioai/sim:stagingfrom waleedlatif1/mothership-draft-bugsimstudioai/sim:waleedlatif1/mothership-draft-bugCopy head branch name to clipboard
Conversation
Wrap the mount-time draft restore in try/catch with clearDraft on throw, and coerce text to a string in the useState initializer. A corrupt entry in mothership-drafts:v1 localStorage previously took down the entire workspace via the error boundary.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryLow Risk Overview Draft text is now coerced to a string during initial state setup, and the mount-time draft restore (text caret positioning, contexts, and file attachments) is wrapped in a Reviewed by Cursor Bugbot for commit b375d99. Configure here. |
Greptile SummaryThis PR hardens the draft restore path in Confidence Score: 5/5Safe to merge — targeted, well-scoped bug fix with no new risks introduced. No P0 or P1 findings. All concerns from the previous review round are addressed: state setters are only called after the entire read succeeds, and errors are surfaced via the project-standard logger. The typeof guard in the initializer and the try/catch in the effect together cover both failure modes described in the PR. No files require special attention. Important Files Changed
Sequence DiagramsequenceDiagram
participant C as Component Mount
participant S as MothershipDraftsStore
participant R as React State Setters
participant L as Logger
C->>C: useState initializer (typeof guard)
C->>S: getState().drafts[key]?.text
S-->>C: text (string | undefined | unknown)
C->>C: typeof text === 'string' ? text : ''
C->>C: useEffect (mount-only)
C->>S: getState().drafts[key]
alt draft exists & readable
S-->>C: draft object
C->>C: build restoredContexts / restoredFiles / caretText locally
C->>R: setSelectedContexts(restoredContexts)
C->>R: restoreAttachedFiles(restoredFiles)
C->>C: textarea.setSelectionRange(caretText.length, ...)
else draft missing
S-->>C: undefined
C->>C: return early (no state applied)
else read throws (corrupt localStorage)
S-->>C: throws
C->>L: logger.error('Failed to read draft, clearing', { err })
C->>S: clearDraft(draftScopeKey)
C->>C: return early (no state applied)
end
Reviews (2): Last reviewed commit: "fix(mothership): defer state writes and ..." | Re-trigger Greptile |
Build the restored state in locals first and only apply on success so a partial throw can't leave stale contexts in the UI with the draft already cleared. Switch the empty catch to logger.error so corrupt-draft incidents surface in production logs.
|
@greptile |
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit b375d99. Configure here.
Summary
clearDrafton throw, so a corruptmothership-drafts:v1localStorage entry no longer takes down the entire workspace via the error boundarytextto a string in theuseStateinitializer so a non-string truthy value doesn't crash render before the effect runsType of Change
Testing
Tested manually — set
mothership-drafts:v1to malformed values in DevTools, page renders and the bad draft is silently dropped on next interaction.Checklist