Repository navigation
Keep your New Linear and Jira creation drafts after an accidental dismissal - #12167
brennanb2025 merged 3 commits into
Conversation
📝 WalkthroughWalkthroughThe 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)
✅ Passed checks (4 passed)
✨ Finishing Touches 💡 1📝 Generate docstrings 💡
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. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
src/renderer/src/components/task-page-task-creation-drafts.test.ts (1)
14-47: 📐 Maintainability & Code Quality | 🔵 Trivial | 🏗️ Heavy liftTest 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
📒 Files selected for processing (8)
src/renderer/src/components/TaskPage.tsxsrc/renderer/src/components/task-page-task-creation-drafts.test.tssrc/renderer/src/store/index.tssrc/renderer/src/store/slices/diffComments.test.tssrc/renderer/src/store/slices/store-test-helpers.tssrc/renderer/src/store/slices/task-creation-drafts.test.tssrc/renderer/src/store/slices/task-creation-drafts.tssrc/renderer/src/store/types.ts
Greptile SummaryThis 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
Confidence Score: 5/5Safe 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.
|
| 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
Reviews (3): Last reviewed commit: "Update draft retention refs after commit" | Re-trigger Greptile
Electron QA — final commit
|
There was a problem hiding this comment.
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
📒 Files selected for processing (5)
src/renderer/src/components/TaskPage.tsxsrc/renderer/src/components/task-page-task-creation-drafts.test.tssrc/renderer/src/components/use-task-creation-draft-retention.test.tssrc/renderer/src/components/use-task-creation-draft-retention.tssrc/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
| // 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]) |
There was a problem hiding this comment.
🚀 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 -200Repository: 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:
- 1: https://react.dev/reference/react/StrictMode
- 2: https://pockit.tools/blog/react-19-useeffect-strict-mode-guide/
- 3: Bug: useEffect does not run twice due to remounting in strict mode and dev run react/react#35017
- 4: Bug:
StrictModereruns effects when a child is moved in an array react/react#32561 - 5: [React 19] React 19 runs extra effects when elements are reordered react/react#29585
🏁 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 3Repository: 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
…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



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:
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
taskCreationDraftsslice is notpersist-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 lintpnpm typecheckpnpm test— ran the draft-related and affected suites locally (54 tests across 7 files, all green); full suite left to CIpnpm 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 invalidationsb4faaa2046— Escape, Cancel, and outside-click dismissal restored every text field; each flow recorded 0 draft writes while typing and 1 on closestore/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:
useTaskCreationDraftRetentionkeeps 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.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
GitLabItemDialog,JiraIssueWorkspace,LinearItemDrawer, GitHub Project slug sheet) — better served by a "don't dismiss while a draft has text" guard likeDiffCommentPopover's; and the crash-report dialog, where an outside click both loses typed notes and permanently dismisses the report.