Skip to content

Conversation

@Ramudur19
Copy link

@Ramudur19 Ramudur19 commented Dec 25, 2025

Avoid invalidating the full rows query on inline edits and updated the row locally to preserve pagination and scroll position.

What does this PR do?

This PR fixes an issue where editing a cell in the spreadsheet caused the view to scroll back to the top.

The root cause was that inline row edits were invalidating the entire rows query, which triggered a re-fetch starting from offset 0. This reset pagination state and caused the spreadsheet to lose its scroll position.

For inline edits, a full data reload isn’t necessary because the row is already updated locally and persisted to the backend. This change avoids invalidating the full rows query for inline edits and instead updates the edited row in the local store.

As a result, pagination and scroll position remain stable after editing a row.

Test Plan

  • Open a database table with a large number of rows.
  • Scroll down to any position in the table.
  • Edit a cell inline and save the change.
  • Verify that:
  • The edited value updates correctly.
  • The scroll position does not reset.
  • Pagination state remains unchanged.
  • Refresh the page and confirm the updated value persists.
scroll.jump.mp4

Related PRs and Issues

Closes #2689

Have you read the Contributing Guidelines on issues?

Yes, I have read and followed the contributing guidelines.

Summary by CodeRabbit

  • Refactor
    • Improved row update handling in database table spreadsheet views for more efficient data management.

✏️ Tip: You can customize this high-level summary in your review settings.

Avoid invalidating the full rows query on inline edits and updated the row locally to preserve pagination and scroll position.
@appwrite
Copy link

appwrite bot commented Dec 25, 2025

Console (appwrite/console)

Project ID: 688b7bf400350cbd60e9

Sites (1)
Site Status Logs Preview QR
 console-stage
688b7cf6003b1842c9dc
Failed Failed Authorize Preview URL QR Code

Tip

Roll back Sites deployments instantly by switching between versions

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 25, 2025

Walkthrough

The change modifies row update handling in a spreadsheet component by replacing a full invalidation call with selective in-place updating. After a row is updated, the code now uses a Map-based index lookup to locate the row in the paginatedRows array. If found, it updates that specific row directly; if not found, no in-memory update occurs. Event tracking and notification logic remain unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Pre-merge checks and finishing touches

✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main fix: preventing scroll jump when editing cells inline in the spreadsheet, which matches the changeset's purpose.
Linked Issues check ✅ Passed The PR directly addresses issue #2689 by replacing full query invalidation with selective in-place updates, preventing the scroll jump that occurred during inline row edits.
Out of Scope Changes check ✅ Passed The change is narrowly scoped to fixing the scroll jump issue via selective row updates; no unrelated modifications to event tracking, notifications, or public APIs are introduced.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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 and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/spreadsheet.svelte (1)

633-639: Consider adding debug logging for skipped updates.

When a row is edited but not present in the current paginated view (rowIndex === undefined), the local update is silently skipped. While this appears intentional and aligns with the PR's goal, adding optional debug logging could aid troubleshooting.

🔎 Proposed enhancement with debug logging
 const rowIndex = rowIndexMap.get(row.$id);
 if (rowIndex !== undefined) {
     paginatedRows.update(
         rowIndex,
         row as Models.DefaultRow
     );
+} else {
+    // Row not in current page view; backend updated but skipping local UI sync
+    console.debug(`Row ${row.$id} updated in backend but not in current paginated view`);
 }
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between e446f7f and 8edc7cc.

📒 Files selected for processing (1)
  • src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/spreadsheet.svelte
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{ts,tsx,js,jsx,svelte}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx,js,jsx,svelte}: Import reusable modules from the src/lib directory using the $lib alias
Use minimal comments in code; reserve comments for TODOs or complex logic explanations
Use $lib, $routes, and $themes aliases instead of relative paths for module imports

Files:

  • src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/spreadsheet.svelte
src/routes/**/*.svelte

📄 CodeRabbit inference engine (AGENTS.md)

Use SvelteKit file conventions: +page.svelte for components, +page.ts for data loaders, +layout.svelte for wrappers, +error.svelte for error handling, and dynamic route params in square brackets like [param]

Files:

  • src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/spreadsheet.svelte
**/*.{ts,tsx,js,jsx,svelte,json}

📄 CodeRabbit inference engine (AGENTS.md)

Use 4 spaces for indentation, single quotes, 100 character line width, and no trailing commas per Prettier configuration

Files:

  • src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/spreadsheet.svelte
**/*.svelte

📄 CodeRabbit inference engine (AGENTS.md)

Use Svelte 5 + SvelteKit 2 syntax with TypeScript for component development

Files:

  • src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/spreadsheet.svelte
src/routes/**

📄 CodeRabbit inference engine (AGENTS.md)

Configure dynamic routes using SvelteKit convention with [param] syntax in route directory names

Files:

  • src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/spreadsheet.svelte
🧠 Learnings (2)
📚 Learning: 2025-09-25T04:21:57.071Z
Learnt from: ItzNotABug
Repo: appwrite/console PR: 2373
File: src/routes/(console)/project-[region]-[project]/databases/database-[database]/(suggestions)/empty.svelte:536-552
Timestamp: 2025-09-25T04:21:57.071Z
Learning: In the Appwrite console database suggestions flow, after successfully creating columns via `createColumns()`, the `await invalidate(Dependencies.TABLE)` call causes the view to be destroyed and another view (populated table view) to be rendered, automatically cleaning up component state without needing manual reset.

Applied to files:

  • src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/spreadsheet.svelte
📚 Learning: 2025-09-30T07:41:06.679Z
Learnt from: ItzNotABug
Repo: appwrite/console PR: 2425
File: src/routes/(console)/project-[region]-[project]/databases/database-[database]/(suggestions)/empty.svelte:454-468
Timestamp: 2025-09-30T07:41:06.679Z
Learning: In `src/routes/(console)/project-[region]-[project]/databases/database-[database]/(suggestions)/empty.svelte`, the column suggestions API (console.suggestColumns) has a maximum limit of 7 columns returned, which aligns with the initial placeholder count of 7 in customColumns.

Applied to files:

  • src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/spreadsheet.svelte
🔇 Additional comments (2)
src/routes/(console)/project-[region]-[project]/databases/database-[database]/table-[table]/spreadsheet.svelte (2)

115-116: LGTM: Efficient O(1) row lookup implementation.

The reactive Map provides constant-time lookups for row indices, which is appropriate given that row updates need to quickly locate their position in the paginated view. The Map recalculation on every $paginatedRows.items change is acceptable given the pagination limit keeps the dataset size bounded.


633-639: Effective fix for scroll jump issue.

The selective in-place update successfully addresses the scroll jump problem by updating only the affected row in the local store instead of invalidating and refetching all rows. The check rowIndex !== undefined correctly handles index 0 and gracefully handles cases where the edited row isn't in the current paginated view.

However, verify that the Models.Row to Models.DefaultRow cast at line 637 is type-safe. The cast is needed because paginatedRows expects Models.DefaultRow, but the function parameter is typed as Models.Row. While the same cast pattern appears elsewhere in the codebase (cell/edit.svelte), type compatibility between these types cannot be confirmed without access to the external @appwrite.io/console package definitions.

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.

View shifts when editing spreadsheet

1 participant