Skip to content

fix(studio): reset anchor offsets on cell move and preserve stationary entry order on no-op move downgrade - #49550

Open
AyushDubey23 wants to merge 1 commit into
supabase:masterfrom
AyushDubey23:fix/derive-notebook-diff-moved-anchor-and-noop-order
Open

AyushDubey23 wants to merge 1 commit into
supabase:masterfrom
AyushDubey23:fix/derive-notebook-diff-moved-anchor-and-noop-order

Conversation

@AyushDubey23

@AyushDubey23 AyushDubey23 commented Aug 25, 2026 •

Copy link
Copy Markdown

I have read the CONTRIBUTING.md file.

YES

What kind of change does this PR introduce?

Bug fix

What is the current behavior?

Closes #49545
Closes #49546

  1. In deriveNotebookDiff, inserting a cell after an anchor that was previously moved shifts the new cell past its intended target position because insertedAfter retains accumulated offset counts from the anchor's pre-move location (Insert anchored to a previously-moved cell lands after the wrong cell in deriveNotebookDiff #49545).
  2. In deriveNotebookDiff, a move that is downgraded to unchanged (downgradeNoOpMoves) leaves { _tag: 'removed' } entries displaced below cells whose moves were cancelled out (A downgraded no-op move displaces a removed entry from its original position #49546).

What is the new behavior?

  1. insertedAfter.delete(operation.cell_id) is invoked when handling move_cell operations so anchor insertion offsets reset when a cell relocates.
  2. downgradeNoOpMoves sorts stationary entries (unchanged, removed, replaced) by their original notebook index when downgrading a no-op move, ensuring deleted entries remain in their original relative position.

Additional context

Added focused regression unit tests covering both operation composition scenarios in notebook-operations.test.ts.

Summary by CodeRabbit

  • Bug Fixes
    • Improved notebook cell reordering to preserve the relative order of unchanged entries.
    • Fixed cases where moving a cell without changing its position could incorrectly reorder removed entries.
    • Corrected insertion behavior when placing cells after an anchor that has moved.
    • Ensured previous insertion positioning is cleared before a cell is reinserted.

@AyushDubey23
AyushDubey23 requested a review from a team as a code owner August 25, 2026 17:05
@github-actions

Copy link
Copy Markdown
Contributor

Thanks for contributing to Supabase! ❤️ Our team will review your PR.

A few tips for a smoother review process:

  • If you have a local version of the repo, run pnpm run format to make sure formatting checks pass.
  • Once we've reviewed your PR, please don't trivially merge master (don't click Update branch if there are no merge conflicts to be fixed). This invalidates any pre-merge checks we've run.

@vercel

vercel Bot commented Aug 25, 2026

Copy link
Copy Markdown

@AyushDubey23 is attempting to deploy a commit to the Supabase Team on Vercel.

A member of the Team first needs to authorize it.

@vercel

vercel Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

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

Project Deployment Actions Updated
design-system Ready Ready Preview Sep 24, 2026 5:12pm UTC
docs Ready Ready Preview, v0 Sep 24, 2026 5:12pm UTC
studio-self-hosted Ready Ready Preview Sep 24, 2026 5:12pm UTC
studio-staging Ready Ready Preview Sep 24, 2026 5:12pm UTC
ui-library Ready Ready Preview Sep 24, 2026 5:12pm UTC
zone-www-dot-com Ready Ready Preview, v0 Sep 24, 2026 5:12pm UTC
1 Skipped Deployment
Project Deployment Actions Updated
studio Ignored Ignored Sep 24, 2026 5:12pm UTC

Request Review

@coderabbitai

coderabbitai Bot commented Aug 25, 2026 •

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: a226063e-1dde-4bae-8f89-9346a3247766

📥 Commits

Reviewing files that changed from the base of the PR and between 8f124cd and d5792ae.

📒 Files selected for processing (2)
  • apps/studio/data/content/notebooks/notebook-operations.test.ts
  • apps/studio/data/content/notebooks/notebook-operations.ts

Included review availability: Your plan provides up to 10 included reviews per hour; 8 remain after this review.


📝 Walkthrough

Walkthrough

deriveNotebookDiff now resolves inserts after moved anchors using current positions and preserves original entry order when moves become no-ops. Tests cover both ordering cases.

Changes

Notebook diff ordering

Layer / File(s) Summary
Move-aware insertion ordering
apps/studio/data/content/notebooks/notebook-operations.ts, apps/studio/data/content/notebooks/notebook-operations.test.ts
Move processing clears stale insertion offsets. Tests verify that a later insert follows an anchor after the anchor moves.
No-op move order preservation
apps/studio/data/content/notebooks/notebook-operations.ts, apps/studio/data/content/notebooks/notebook-operations.test.ts
Diff entries track original indices and restore stationary entries to their original order after no-op moves. Tests verify that removed entries remain in place.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Merge Risk: ⚪ Minimal · up to d5792

This localized bug fix adds regression coverage for notebook cell movement and ordering behavior; no actionable merge-blocking risk remains beyond normal checks and review.

Suggested reviewers: charislam

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 4 functions across 2 files. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes both notebook diff fixes: resetting anchor offsets after cell moves and preserving stationary entry order after no-op move downgrades.
Description check ✅ Passed The description includes all required template sections and provides clear current behavior, new behavior, linked issues, and regression-test context.
Linked Issues check ✅ Passed The implementation and regression tests address both linked issues: same-anchor inserts after moved cells and preservation of removed-entry order during no-op move downgrades.
Out of Scope Changes check ✅ Passed The changes are limited to the related notebook diff implementation and focused regression tests. No unrelated changes are present.
✨ Finishing Touches 💡 1
🛠️ Fix failing CI checks 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

1 participant