Skip to content

Keep your New Linear and Jira creation drafts after an accidental dismissal - #12167

Merged
brennanb2025 merged 3 commits into
mainfrom
brennanb2025/feature-preserve-drafts-when-issue-creation-moda
Aug 3, 2026
Merged

brennanb2025 merged 3 commits into
mainfrom
brennanb2025/feature-preserve-drafts-when-issue-creation-moda

Conversation

@brennanb2025

@brennanb2025 brennanb2025 commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Summary

Dismissing the New Linear issue, New Linear project, or New Jira issue dialog by clicking outside it (or pressing Escape, or clicking Cancel) no longer discards the typed text. Each dialog now retains its latest text in a session-only draft when dismissed or unmounted and restores it when the dialog reopens, exactly like the New GitHub issue dialog does since #7778:

  • New Linear issue: title + description
  • New Linear project: name, summary, and the project brief
  • New Jira issue: title + description

The draft is cleared only after a successful create. Scope is deliberately text-only: picker selections (team, project, lead/members, labels, priority, dates, issue type, custom fields) keep their existing open-time defaults, so no repo/team/project staleness guards are needed. Drafts are in-memory only (the new taskCreationDrafts slice is not persist-wrapped) and do not survive an app restart, matching the #7778 boundary.

Closes #7696 — the GitHub dialog (the originally reported case) was already fixed by #7778; this covers the remaining creation dialogs the issue's second paragraph asks about.

Screenshots

No visual layout change. Electron evidence for all three reopened dialogs is attached in this PR comment.

Testing

  • pnpm lint
  • pnpm typecheck
  • pnpm test — ran the draft-related and affected suites locally (54 tests across 7 files, all green); full suite left to CI
  • pnpm build — not run locally; no build-surface changes (renderer-only state wiring)
  • pnpm run check:zustand-selector-fanout — 2,500 subscribers × 2,000 writes, 0.0144 ms/write against the 5 ms budget, 0 render invalidations
  • Electron QA on final commit b4faaa2046 — Escape, Cancel, and outside-click dismissal restored every text field; each flow recorded 0 draft writes while typing and 1 on close
  • Added or updated focused regression tests
    • store/slices/task-creation-drafts.test.ts: slice isolation, wholesale replacement, clearing, and the whitespace-only content gate.
    • components/use-task-creation-draft-retention.test.ts: no writes across typing renders, one latest-value write on dismissal/unmount, and successful-create discard without cleanup resurrection.
    • components/task-page-task-creation-drafts.test.ts: pins all three retention hooks, restore-on-open wiring, and success-only discard calls.

AI Review Report

A same-model, same-reasoning subagent reviewed the final diff, fixed one meaningful in-scope performance regression, reran validation, and re-reviewed to CLEAN:

  • Dismissal/unmount retention: useTaskCreationDraftRetention keeps the latest committed form values locally and writes to the global store once when an open composer closes or unmounts. Provider-context force-closes therefore retain the last open values even when local fields reset in the same update.
  • Successful create: each success handler discards the draft before closing/resetting fields. The hook marks that close as discarded, so cleanup cannot resurrect the submitted text. Failed creates and stale-provider returns never discard the draft.
  • Emptied-then-dismissed form: the shared content gate clears a prior draft when all text is empty or whitespace-only, so the next open is fresh.
  • Performance: the original implementation wrote the app-wide Zustand store on every keystroke and added six live action subscriptions. The final implementation performs zero draft-store writes while typing, removes those subscriptions, and writes once on dismissal.
  • Scope: only text for New Linear issue/project and New Jira issue is retained. Picker selections, provider ownership, persistence, mobile sync, IPC, SSH, and folder-workspace behavior are unchanged.
  • Cross-platform: renderer-only state with no shortcut, path, shell, or Electron-main changes; behavior is platform-neutral across macOS, Linux, and Windows.

Security Audit

No IPC, command execution, path handling, or auth changes. Draft text stays in the in-memory renderer store — never written to disk, logs, or telemetry — so no new retention surface for sensitive text. The credential dialogs (Jira connect, Linear API key) are deliberately untouched: they clear secrets on open by design and were explicitly excluded from draft preservation.

Notes

  • Follow-ups (out of scope, from the same audit): detail-sheet composers discard in-progress comments/edits on outside click (GitLabItemDialog, JiraIssueWorkspace, LinearItemDrawer, GitHub Project slug sheet) — better served by a "don't dismiss while a draft has text" guard like DiffCommentPopover's; and the crash-report dialog, where an outside click both loses typed notes and permanently dismisses the report.
  • Jira custom-field values are not preserved: the create-fields effect wipes them on every open/project/type change, and preserving them would require restructuring that effect for marginal benefit.

@coderabbitai

coderabbitai Bot commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

The PR adds session-only draft state for Linear project, Linear issue, and Jira issue composers. Non-whitespace content is stored while a composer is open. Empty content clears the draft. Reopening a composer restores saved text and resets picker-specific fields. Successful creation clears the related draft. Zustand application and test stores include the new slice, with tests covering state behavior and TaskPage integration.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Linked Issues check ✅ Passed The PR preserves text drafts across dismissal and reopening for the remaining Linear and Jira creation dialogs, meeting issue #7696.
Out of Scope Changes check ✅ Passed The store, hook, component, and regression-test changes directly support draft retention and remain within the linked issue scope.
Title check ✅ Passed The title clearly summarizes retaining New Linear and Jira creation drafts after dismissal.
Description check ✅ Passed The description covers the user-visible change, testing status, AI review, security audit, platform review, screenshots, and follow-up notes.
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
src/renderer/src/components/task-page-task-creation-drafts.test.ts (1)

14-47: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy lift

Test the dialog lifecycle at runtime.

These assertions only check source text. They can pass if an effect does not run or a dismissal path stops saving the draft.

Render each dialog and verify restoration after Cancel, Escape, and outside click. Mock successful and failed creation responses. Assert that only successful creation clears the draft.


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 7437cb33-7b0a-402e-a0bb-6e8a6e0d7033

📥 Commits

Reviewing files that changed from the base of the PR and between 95c431f and 7569243.

📒 Files selected for processing (8)
  • src/renderer/src/components/TaskPage.tsx
  • src/renderer/src/components/task-page-task-creation-drafts.test.ts
  • src/renderer/src/store/index.ts
  • src/renderer/src/store/slices/diffComments.test.ts
  • src/renderer/src/store/slices/store-test-helpers.ts
  • src/renderer/src/store/slices/task-creation-drafts.test.ts
  • src/renderer/src/store/slices/task-creation-drafts.ts
  • src/renderer/src/store/types.ts

@greptile-apps

greptile-apps Bot commented Aug 3, 2026 •

Copy link
Copy Markdown

Greptile Summary

This PR extends the accidental-dismissal draft recovery introduced for GitHub issues (PR #7778) to the New Linear issue, New Linear project, and New Jira issue dialogs. A new useTaskCreationDraftRetention hook tracks the latest typed values in refs and writes them to a non-persisted Zustand slice exactly once when a dialog closes or unmounts, with zero store writes while typing.

  • useTaskCreationDraftRetention: uses useLayoutEffect (no-deps, gated on open) to keep draftRef current, and a [open]-dep useEffect cleanup to write the draft on close. A discardRef flag — set by the returned discard() callback — prevents the cleanup from resurrecting a successfully submitted draft.
  • createTaskCreationDraftsSlice: three independent set/clear pairs backed by in-memory Zustand state (not persist-wrapped); an isTaskCreationDraftContentful gate skips saving empty or whitespace-only forms so reopening after a full-clear is fresh.
  • TaskPage wiring: module-level write helpers read the store via getState() (no reactive subscription), each open-button handler restores draft text before calling setOpen(true), and each success handler calls discard() before setOpen(false) to clear the draft and prevent cleanup resurrection.

Confidence Score: 5/5

Safe to merge. The change is renderer-only, fully in-memory, and touches no IPC, persistence, or auth surfaces.

All three success paths call discard() before setOpen(false), so cleanup cannot resurrect submitted text. Error and staleness-guard early-returns all skip discard, correctly preserving the draft for the next attempt. The hook's ref-based design avoids per-keystroke store writes and handles unmount, close, and discard in verified order.

Files Needing Attention: No files require special attention.

Important Files Changed

Filename Overview
src/renderer/src/components/use-task-creation-draft-retention.ts New hook that saves the latest draft on close/unmount using refs to avoid per-keystroke store writes; correctly prevents resurrection via a discardRef flag checked in cleanup.
src/renderer/src/store/slices/task-creation-drafts.ts New unpersisted Zustand slice for three session-only creation drafts; simple set/clear actions and an isTaskCreationDraftContentful guard to skip writing empty forms.
src/renderer/src/components/TaskPage.tsx Wires the three retention hooks, module-level write helpers, and draft-restore logic on each dialog's open-button handler; discard called on success only, before setOpen(false).
src/renderer/src/components/use-task-creation-draft-retention.test.ts Four targeted tests covering no-write-while-typing, unmount retention, successful-create anti-resurrection, and unopened-composer no-op; good coverage of the hook's contracts.
src/renderer/src/components/task-page-task-creation-drafts.test.ts Source-text assertions confirm hook wiring count, absence of reactive subscriptions, field restoration strings, and presence of discard calls — adequately pins the integration but sectionBetween cannot distinguish success-path placement from catch/finally.
src/renderer/src/store/slices/task-creation-drafts.test.ts Slice unit tests verify independent set/clear, wholesale replacement, and the isTaskCreationDraftContentful gate for whitespace and non-empty values.
src/renderer/src/store/index.ts Registers the new slice without persist middleware, matching the in-memory-only requirement.
src/renderer/src/store/types.ts Adds TaskCreationDraftsSlice to the AppState union; straightforward type-level change.
src/renderer/src/store/slices/diffComments.test.ts Adds the new slice to the test store factory so diffComments tests continue to compile against the full AppState shape.
src/renderer/src/store/slices/store-test-helpers.ts Adds createTaskCreationDraftsSlice to the shared test store helper; mechanical, low-risk change.

Sequence Diagram

sequenceDiagram
    participant User
    participant Dialog
    participant Hook as useTaskCreationDraftRetention
    participant Store as Zustand Store

    User->>Dialog: "Opens dialog (open=true)"
    activate Hook
    Hook->>Hook: "useEffect body: discardRef=false, register cleanup"
    User->>Dialog: Types text (multiple renders)
    Hook->>Hook: "useLayoutEffect: draftRef=latest, writeDraftRef=stable fn"

    alt Accidental dismissal (Escape / outside click)
        User->>Dialog: "Dismisses (open=false)"
        Hook->>Hook: "useEffect cleanup: discardRef==false, write draft"
        Hook->>Store: writeDraft(latestDraft)
        Store-->>Store: setNewLinear/JiraIssueDraft(draft)
        User->>Dialog: Reopens dialog
        Dialog->>Store: getState().newLinear/JiraIssueDraft
        Store-->>Dialog: Restore title + body
    end

    alt Successful create
        User->>Dialog: Submits form
        Dialog->>Hook: "discard(), discardRef=true, writeDraft(null)"
        Hook->>Store: "clearNew*Draft()"
        Dialog->>Dialog: setOpen(false)
        Hook->>Hook: "useEffect cleanup: discardRef==true, SKIP write"
        deactivate Hook
    end
Loading

Reviews (3): Last reviewed commit: "Update draft retention refs after commit" | Re-trigger Greptile

@brennanb2025

brennanb2025 commented Aug 3, 2026 •

Copy link
Copy Markdown
Contributor Author

Electron QA — final commit b4faaa2046

Validated the rendered desktop dialogs in the intended worktree instance with an isolated, synthetic-data profile:

  • New Linear issue: entered title + description, dismissed with Escape, reopened, and confirmed exact restoration.
  • New Linear project: entered name + summary + brief, dismissed with Cancel, reopened, and confirmed exact restoration.
  • New Jira issue: entered title + description, dismissed by clicking the dialog backdrop, reopened, and confirmed exact restoration.
  • Performance backing check: each flow produced 0 draft-store writes while typing and 1 write on dismissal.

No external Linear/Jira item was created. Provider data was synthetic; the screenshots contain no account credentials or private project data. The isolated Jira fixture has no projects, so its disabled button was exercised through the button's real React handler; no create action was invoked.

Linear issue — restored after Escape

pr12167-linear-issue-draft-restored-final.png

Linear project — restored after Cancel

pr12167-linear-project-draft-restored-final.png

Jira issue — restored after outside click

pr12167-jira-issue-draft-restored-final.png

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1


ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 3b5a0c07-3c14-4b46-a193-3c2284fbc79f

📥 Commits

Reviewing files that changed from the base of the PR and between 7569243 and b4faaa2.

📒 Files selected for processing (5)
  • src/renderer/src/components/TaskPage.tsx
  • src/renderer/src/components/task-page-task-creation-drafts.test.ts
  • src/renderer/src/components/use-task-creation-draft-retention.test.ts
  • src/renderer/src/components/use-task-creation-draft-retention.ts
  • src/renderer/src/store/slices/task-creation-drafts.ts
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/renderer/src/components/task-page-task-creation-drafts.test.ts
  • src/renderer/src/components/TaskPage.tsx

Comment on lines +27 to +38
// Why: closing cleanup captures the latest render once without a global store write per keystroke.
useEffect(() => {
if (!open) {
return
}
discardRef.current = false
return () => {
if (!discardRef.current) {
writeDraftRef.current(draftRef.current)
}
}
}, [open])

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🚀 Performance & Scalability | 🟡 Minor | ⚡ Quick win

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Repo files matching hook/test names:"
git ls-files | rg 'use-task-creation-draft-retention\.(ts|tsx|test\.ts)$|package\.json$|vite|react|strictmode|StrictMode' || true

echo
if [ -f src/renderer/src/components/use-task-creation-draft-retention.ts ]; then
  echo "Hook outline:"
  ast-grep outline src/renderer/src/components/use-task-creation-draft-retention.ts || true
  echo
  echo "Hook contents:"
  cat -n src/renderer/src/components/use-task-creation-draft-retention.ts
fi

echo
if [ -f src/renderer/src/components/use-task-creation-draft-retention.test.ts ]; then
  echo "Test outline:"
  ast-grep outline src/renderer/src/components/use-task-creation-draft-retention.test.ts || true
  echo
  echo "Test contents:"
  cat -n src/renderer/src/components/use-task-creation-draft-retention.test.ts
fi

echo
echo "Package React version info:"
if [ -f package.json ]; then
  jq -r '.dependencies.react?, .devDependencies.react?, .dependencies["react-dom"]?, .devDependencies["react-dom"]?' package.json
fi

echo
echo "Search for StrictMode/renderHook and usage of hook:"
rg -n "StrictMode|<StrictMode>|renderHook|useTaskCreationDraftRetention|draftRetention|effect.*cleanup|clean.*up" src/renderer src -g '*.{ts,tsx,js,jsx,json}' | head -200

Repository: stablyai/orca

Length of output: 30539


🌐 Web query:

React 19 StrictMode effects additional effects including cleanup effect after unmount docs

💡 Result:

In React 19, StrictMode continues to use intentional double-invocations in development to help surface bugs, specifically those related to missing or incorrect effect cleanup [1][2]. The core behavior in StrictMode for development is designed to simulate the component lifecycle of mounting, unmounting, and remounting [1][2]. When a component mounts in development with StrictMode enabled, React performs the following sequence: 1. Mount (Setup) 2. Unmount (Cleanup) 3. Mount (Setup) This sequence ensures that your effect's cleanup function is properly implemented and resilient to being called multiple times [1][2]. If your effect creates a side effect (such as a subscription or a network connection), the cleanup function should release those resources so that the subsequent remount does not create orphaned or conflicting side effects [2]. It is important to note the following: * Purpose: This behavior is exclusive to development mode [1][2]. It does not occur in production builds, where effects run exactly once per mount [2]. * Cleanup Execution: The cleanup function is executed after the component is unmounted during this cycle [1][2]. This allows you to verify that your cleanup logic effectively reverses the setup logic performed during the initial mount [2]. * Resilience: By enforcing this cycle, React encourages developers to write effects that are "resilient"—meaning they can be safely re-run without causing issues [2]. If you observe unexpected behavior or inconsistencies (such as effects not running twice or running unexpectedly during reordering), be aware that React 19 has seen reports of regressions or changes in specific scenarios, such as reordering elements in a list or specific mount behaviors [3][4][5]. However, the standard expectation for StrictMode remains that components should be able to handle this mount-unmount-mount lifecycle without side effects [1][2][4].

Citations:


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "React renderer root file:"
cat -n src/renderer/src/lib/react-renderer-root.ts

echo
echo "Renderers containing StrictMode mount:"
rg -n "StrictMode|createRoot|hydrateRoot|render" src/renderer/src/main.tsx src/renderer/src/lib/react-renderer-root.ts src/renderer/src/main.tsx -C 3

Repository: stablyai/orca

Length of output: 6962


Prevent draft writes during Strict Mode mount replay.

In development with <StrictMode>, React can run the mount effect cleanup before remounting, so this cleanup writes while the composer is still open. Delay the cleanup write and cancel it when an open setup re-runs, and add a <StrictMode> test case for the hook.

📍 Affects 2 files
  • src/renderer/src/components/use-task-creation-draft-retention.ts#L27-L38 (this comment)
  • src/renderer/src/components/use-task-creation-draft-retention.test.ts#L12-L28

@brennanb2025
brennanb2025 merged commit 4481b9b into main Aug 3, 2026
123 of 127 checks passed
enrick-dev pushed a commit to enrick-dev/orca that referenced this pull request Oct 15, 2026
…missal (stablyai#12167)

* Keep your New Linear and Jira creation drafts after an accidental dismissal

* Avoid draft store writes while typing

* Update draft retention refs after commit
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.

[Feature] Preserve drafts when issue creation modals or panels are dismissed

1 participant