Skip to content

fix(studio): repaint pending dry edits after every table reload + beforeunload guard - #219

Merged
remcostoeten merged 1 commit into
masterfrom
fix/pending-edits-reload-repaint
Jul 26, 2026
Merged

fix(studio): repaint pending dry edits after every table reload + beforeunload guard#219
remcostoeten merged 1 commit into
masterfrom
fix/pending-edits-reload-repaint

Conversation

@remcostoeten

@remcostoeten remcostoeten commented Jul 26, 2026

Copy link
Copy Markdown
Owner

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

  • New pure overlayPendingEditsOnRows(rows, edits) in packages/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.ts applies the overlay at all three paint sites: the instant cache paint and the fresh fetch in loadTableData, and the cache paint in handleTableChange. The edits getter is read through a ref so loadTableData'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.tsx registers a beforeunload prompt whenever any pending edits exist.

Verification

  • 6 new unit tests for the overlay (overlay.test.ts)
  • bun run test:desktop: 783 passed; studio + desktop typecheck and bun run lint clean

Closes #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:

  • Overlay pending dry-mode edits onto freshly loaded table rows so the grid consistently reflects buffered changes.
  • Prompt the user with a beforeunload dialog when there are unsaved edits in the database studio.

Enhancements:

  • Integrate the pending-edits overlay into all table data paint paths without affecting table-data cache semantics.

Tests:

  • Add unit test coverage for the pending-edits overlay logic, including primary-key matching, multi-column edits, off-page edits, and immutability.

@vercel

vercel Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

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

Project Deployment Actions Updated (UTC)
dora Ready Ready Preview, Comment Jul 26, 2026 1:59pm

@coderabbitai

coderabbitai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

Warning

Review limit reached

@remcostoeten, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 56 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: bf1a7f78-375c-475a-b772-593f5ef422e8

📥 Commits

Reviewing files that changed from the base of the PR and between 34b2b14 and af73b71.

📒 Files selected for processing (5)
  • packages/studio/src/core/pending-edits/index.ts
  • packages/studio/src/core/pending-edits/overlay.test.ts
  • packages/studio/src/core/pending-edits/overlay.ts
  • packages/studio/src/features/database-studio/database-studio.tsx
  • packages/studio/src/features/database-studio/hooks/use-database-studio-sync.ts
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/pending-edits-reload-repaint

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.

…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-ai

sourcery-ai Bot commented Jul 26, 2026

Copy link
Copy Markdown
Contributor

🧙 Sourcery has finished reviewing your pull request!


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@sourcery-ai sourcery-ai 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.

Hey - I've left some high level feedback:

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

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@remcostoeten
remcostoeten merged commit 05e9077 into master Jul 26, 2026
10 checks passed
@remcostoeten
remcostoeten deleted the fix/pending-edits-reload-repaint branch July 26, 2026 14:37
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.

fix(studio): dry-mode pending cell edits are stranded when the table reloads or changes

1 participant