Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

fix(mothership): catch draft restore errors instead of crashing /home#4433

Merged
waleedlatif1 merged 2 commits intostagingsimstudioai/sim:stagingfrom
waleedlatif1/mothership-draft-bugsimstudioai/sim:waleedlatif1/mothership-draft-bugCopy head branch name to clipboard
May 4, 2026
Merged

fix(mothership): catch draft restore errors instead of crashing /home#4433
waleedlatif1 merged 2 commits intostagingsimstudioai/sim:stagingfrom
waleedlatif1/mothership-draft-bugsimstudioai/sim:waleedlatif1/mothership-draft-bugCopy head branch name to clipboard

Conversation

@waleedlatif1
Copy link
Copy Markdown
Collaborator

Summary

  • Wrap the mount-time draft restore effect in try/catch and call clearDraft on throw, so a corrupt mothership-drafts:v1 localStorage entry no longer takes down the entire workspace via the error boundary
  • Coerce text to a string in the useState initializer so a non-string truthy value doesn't crash render before the effect runs

Type of Change

  • Bug fix

Testing

Tested manually — set mothership-drafts:v1 to malformed values in DevTools, page renders and the bad draft is silently dropped on next interaction.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

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.
@vercel
Copy link
Copy Markdown

vercel Bot commented May 4, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped May 4, 2026 6:47pm

Request Review

@cursor
Copy link
Copy Markdown

cursor Bot commented May 4, 2026

PR Summary

Low Risk
Low risk UI-state change: it only adds defensive checks and error handling around reading persisted drafts, but could cause some drafts/attachments to be dropped if the stored data is malformed.

Overview
Prevents the /home user input from crashing when restoring a persisted mothership draft from localStorage.

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 try/catch that logs and calls clearDraft if the stored draft payload is corrupt.

Reviewed by Cursor Bugbot for commit b375d99. Configure here.

@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented May 4, 2026

Greptile Summary

This PR hardens the draft restore path in UserInput against corrupt mothership-drafts:v1 localStorage entries. The mount-time effect now builds all restored state into locals before applying any setters, logs errors via logger.error, and calls clearDraft on throw; the useState initializer adds a typeof guard so a non-string draft text no longer crashes render. Both concerns raised in the previous review round have been properly addressed.

Confidence Score: 5/5

Safe 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

Filename Overview
apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx Wraps draft restore effect in try/catch with logger.error on failure, builds restored state in locals before applying any setters, and adds typeof guard in useState initializer — all previous review concerns addressed.

Sequence Diagram

sequenceDiagram
    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
Loading

Reviews (2): Last reviewed commit: "fix(mothership): defer state writes and ..." | Re-trigger Greptile

Comment thread apps/sim/app/workspace/[workspaceId]/home/components/user-input/user-input.tsx Outdated
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.
@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@greptile

@waleedlatif1
Copy link
Copy Markdown
Collaborator Author

@cursor review

Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ 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.

@waleedlatif1 waleedlatif1 merged commit 3af6c25 into staging May 4, 2026
14 checks passed
@waleedlatif1 waleedlatif1 deleted the waleedlatif1/mothership-draft-bug branch May 4, 2026 19:13
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

Morty Proxy This is a proxified and sanitized view of the page, visit original site.