feat: save recent generations in local history - #224
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
🚧 Files skipped from review as they are similar to previous changes (1)
📝 WalkthroughSummary by CodeRabbit
WalkthroughThe PR adds bounded browser storage for generated markdown, a history panel, cross-tab synchronization, restoration of repository and language values, and clearing controls. Tests cover normalization, limits, invalid data, persistence, quota recovery, removal, and clearing. ChangesGeneration history
Estimated code review effort: 3 (Moderate) | ~25 minutes Sequence Diagram(s)sequenceDiagram
participant GeneratePageClient
participant generationHistory
participant localStorage
participant GenerationHistory
GeneratePageClient->>generationHistory: append generated markdown
generationHistory->>localStorage: save bounded history
localStorage-->>GeneratePageClient: storage event
GeneratePageClient->>GenerationHistory: render synchronized entries
GenerationHistory->>GeneratePageClient: restore selected entry
GeneratePageClient->>GeneratePageClient: restore form and preview
Possibly related PRs
Suggested labels: Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
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.
Actionable comments posted: 4
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/app/generate/GeneratePageClient.tsx`:
- Around line 114-123: Update the history handling around appendGeneration so
next is computed from the current history outside the setHistory functional
updater, then pass next to saveHistory and setHistory separately. Remove the
persistence side effect from the setHistory callback while preserving the
existing appendGeneration inputs and update order.
In `@src/components/Generator/GenerationHistory.tsx`:
- Line 49: Update GenerationHistory to receive the active history entry id from
GeneratePageClient and determine the active row by comparing entry.id with that
id, removing the URL-only activeUrl comparison. Ensure GeneratePageClient passes
the restored or currently selected entry id through the component props.
In `@src/lib/generationHistory.ts`:
- Around line 17-20: Update getStorage so the globalThis.localStorage property
access is wrapped in try/catch; return the retrieved storage on success and null
when accessing it throws, while preserving the existing undefined-global and
missing-storage behavior.
- Around line 113-126: Update saveHistory to return the pool that was
successfully persisted, while distinguishing the no-storage or completely
failed-write case. Update GeneratePageClient’s history state flow to consume
that result and replace its in-memory entries with the persisted subset after
quota eviction, preserving consistent behavior across refreshes and tabs.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: ed69b1ac-4a60-4c2f-858a-eb7cec0b41c4
📒 Files selected for processing (5)
src/__tmp__/generationHistory.test.tssrc/app/generate/GeneratePageClient.tsxsrc/components/Generator/GenerationHistory.tsxsrc/components/Generator/SearchInput.tsxsrc/lib/generationHistory.ts
| export function saveHistory( | ||
| entries: GenerationHistoryEntry[], | ||
| storage: StorageLike | null = getStorage(), | ||
| ): void { | ||
| if (!storage) return; | ||
| let pool = entries; | ||
| for (;;) { | ||
| try { | ||
| storage.setItem(GENERATION_HISTORY_KEY, JSON.stringify(pool)); | ||
| return; | ||
| } catch { | ||
| if (pool.length <= 1) return; | ||
| pool = pool.slice(0, Math.ceil(pool.length / 2)); | ||
| } |
There was a problem hiding this comment.
🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift
Keep in-memory history equal to the persisted history after quota eviction.
When setItem rejects a large payload, this function writes a smaller pool but does not return it. GeneratePageClient retains the original list, so entries can remain visible until refresh and then disappear. Other tabs also load a different list.
Return the successfully saved pool, or a result that distinguishes a failed write. Update GeneratePageClient to use the returned entries as its state.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/lib/generationHistory.ts` around lines 113 - 126, Update saveHistory to
return the pool that was successfully persisted, while distinguishing the
no-storage or completely failed-write case. Update GeneratePageClient’s history
state flow to consume that result and replace its in-memory entries with the
persisted subset after quota eviction, preserving consistent behavior across
refreshes and tabs.
|
Addressed all 4 CodeRabbit comments:
Re-verified: vitest 18/18, lint, tsc, build. |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@src/components/Generator/GenerationHistory.tsx`:
- Around line 99-100: Update the generation flow around handleGenerate to
synchronize activeHistoryEntryId with the newly persisted generation entry,
replacing the restored ID or clearing it before generation starts. Ensure
GenerationHistory receives the current displayed generation ID so isActive
highlights entry B rather than a previously restored entry A.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro Plus
Run ID: 4a247af2-caa7-4590-b2cf-96ec9d4c6b4d
📒 Files selected for processing (4)
src/__tmp__/generationHistory.test.tssrc/app/generate/GeneratePageClient.tsxsrc/components/Generator/GenerationHistory.tsxsrc/lib/generationHistory.ts
🚧 Files skipped from review as they are similar to previous changes (3)
- src/lib/generationHistory.ts
- src/tmp/generationHistory.test.ts
- src/app/generate/GeneratePageClient.tsx
| const isActive = entry.id === activeEntryId; | ||
| return ( |
There was a problem hiding this comment.
🎯 Functional Correctness | 🟡 Minor | ⚡ Quick win
Synchronize activeEntryId with the displayed generation.
GeneratePageClient.handleRestoreGeneration sets activeHistoryEntryId, but handleGenerate does not clear or replace it. If a user restores entry A and then generates entry B, this component still highlights A while displaying B. Update the parent state from the newly persisted entry ID, or clear it before starting a new generation.
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
In `@src/components/Generator/GenerationHistory.tsx` around lines 99 - 100, Update
the generation flow around handleGenerate to synchronize activeHistoryEntryId
with the newly persisted generation entry, replacing the restored ID or clearing
it before generation starts. Ensure GenerationHistory receives the current
displayed generation ID so isActive highlights entry B rather than a previously
restored entry A.
|
Fixed the remaining CodeRabbit comment: after a successful generation, \GeneratePageClient\ now sets \�ctiveHistoryEntryId\ to the newly persisted entry (index 0), so the history panel highlights the current displayed generation instead of a previously restored one. Verified: lint, tsc, vitest 18/18, build. |
Closes #162
Persists recent generated repositories in the browser (localStorage) and adds a history panel to the generate page.
Changes
Acceptances
Validation
px vitest run\ — 17/17 passing
pm run lint,
px tsc --noEmit,
pm run build\ — clean