fix(studio): repaint pending dry edits after every table reload + beforeunload guard - #219
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Warning Review limit reached
Next review available in: 56 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (5)
✨ Finishing Touches🧪 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 |
…oreunload guard Every reload path (table switch, page/sort/filter change, live-monitor refresh, cache paint) replaced grid rows with database values while the pending-changes bar still counted N unsaved edits, and Apply would write values the user could no longer see. Freshly loaded rows are now overlaid with the buffered edits by primary key via overlayPendingEditsOnRows(), and closing the window with unsaved edits now prompts via beforeunload. Together with the undo-by-PK and reload-guard work in #213 this closes the remaining scope of the issue. Closes #195
|
🧙 Sourcery has finished reviewing your pull request! Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The
guardUnloadWithPendingEditseffect only re-runs when thehasEditsfunction reference changes, so thebeforeunloadlistener may not be installed/removed when the actual pending edits state changes; consider depending on the edit count/boolean itself instead of the function to keep the unload guard in sync with edits. - In
overlayPendingEditsOnRows, repeatedly filteringeditsfor each row is O(n*m); for large datasets you could pre-indexeditsby primary key (and possibly column) once and then apply them in a single pass to reduce overhead.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The `guardUnloadWithPendingEdits` effect only re-runs when the `hasEdits` function reference changes, so the `beforeunload` listener may not be installed/removed when the actual pending edits state changes; consider depending on the edit count/boolean itself instead of the function to keep the unload guard in sync with edits.
- In `overlayPendingEditsOnRows`, repeatedly filtering `edits` for each row is O(n*m); for large datasets you could pre-index `edits` by primary key (and possibly column) once and then apply them in a single pass to reduce overhead.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
What
Finishes the remaining scope of #195 (the live-monitor reload guard and undo-by-PK already landed in #213).
Dry-mode edits are buffered per table and painted optimistically into the grid — but switching tables, changing page/sort/filter, or any cache paint replaced the rows with database values. The grid then showed originals while the pending-changes bar still counted N unsaved edits, and Apply wrote values the user could no longer see. There was also no unsaved-changes guard on window close.
How
overlayPendingEditsOnRows(rows, edits)inpackages/studio/src/core/pending-edits/overlay.ts: repaints buffered edits onto rows by primary key (edits for rows not on the current page stay buffered, untouched).use-database-studio-sync.tsapplies the overlay at all three paint sites: the instant cache paint and the fresh fetch inloadTableData, and the cache paint inhandleTableChange. The edits getter is read through a ref soloadTableData's identity doesn't churn (and re-trigger loads) on every buffered keystroke. The table-data cache itself still stores raw database truth.database-studio.tsxregisters abeforeunloadprompt whenever any pending edits exist.Verification
overlay.test.ts)bun run test:desktop: 783 passed; studio + desktoptypecheckandbun run lintcleanCloses #195
Summary by Sourcery
Ensure dry-mode pending edits are re-applied to table rows after any data reload and guard against losing unsaved edits on window close.
New Features:
Enhancements:
Tests: