Skip to content

Fix database row order refresh#345

Merged
appflowy merged 1 commit into
mainfrom
fix/database-row-order-refresh
May 15, 2026
Merged

Fix database row order refresh#345
appflowy merged 1 commit into
mainfrom
fix/database-row-order-refresh

Conversation

@appflowy
Copy link
Copy Markdown
Contributor

@appflowy appflowy commented May 15, 2026

Summary

  • update unfiltered row order subscribers immediately when Yjs row_orders changes
  • keep sorted/filtered row recomputation on the existing debounced path
  • add selector regression coverage for add/delete, row_orders replacement, and active-filter guards

Tests

  • pnpm exec jest src/application/database-yjs/tests/useRowOrdersSelector.test.tsx --no-coverage --runInBand
  • pnpm run type-check
  • pnpm exec eslint --quiet --ext .ts,.tsx src/application/database-yjs/selector.ts src/application/database-yjs/tests/useRowOrdersSelector.test.tsx --ignore-path .eslintignore.web

Summary by Sourcery

Ensure row order selectors immediately reflect unfiltered Yjs row order changes while keeping conditioned views on the debounced recomputation path.

Bug Fixes:

  • Fix row order selector to update immediately when rows are added, removed, or when the row order array is replaced in unfiltered views.
  • Prevent immediate publication of raw row order changes when filters are active so conditioned views remain consistent.

Tests:

  • Extend useRowOrdersSelector tests to cover add/delete behavior, row_orders array replacement resubscription, and active-filter guard behavior.

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented May 15, 2026

Reviewer's Guide

Refines the useRowOrdersSelector hook so unfiltered row order updates are applied immediately on Yjs row_orders changes while keeping filtered/sorted recomputation debounced, and adds regression tests around row order add/delete, array replacement, and filtered behavior.

Sequence diagram for updated row_orders change handling in useRowOrdersSelector

sequenceDiagram
  participant YjsRowOrders as rowOrders
  participant Hook as useRowOrdersSelector
  participant Sync as syncUnconditionedRowOrders
  participant Debounce as debouncedChange
  participant Conditions as onConditionsChange

  YjsRowOrders->>Hook: observeDeep(handleRowOrdersChange)
  YjsRowOrders-->>Hook: handleRowOrdersChange()
  Hook->>Sync: syncUnconditionedRowOrders()
  alt [syncUnconditionedRowOrders returns true]
    Sync->>Hook: setRowOrdersState({ rows, conditionSignature })
  else [syncUnconditionedRowOrders returns false]
    Hook->>Debounce: debouncedChange()
    Debounce-->>Conditions: onConditionsChange()
    Conditions->>Hook: setRowOrdersState({ rows, conditionSignature })
  end
Loading

File-Level Changes

Change Details Files
Make useRowOrdersSelector respond immediately to unconditioned row order changes while keeping conditioned recomputation debounced.
  • Cache the Yjs row_orders array from the current view in a local variable for reuse within the hook.
  • Introduce syncUnconditionedRowOrders to derive a condition signature, reset condition-related refs when it changes, and synchronously update rowOrdersState when no filters/sorts are active.
  • Update onConditionsChange to use the cached rowOrders reference rather than reading from the view each time.
src/application/database-yjs/selector.ts
Wire rowOrders observer to use conditional immediate sync or debounced recomputation and clean up correctly on unmount.
  • Replace the direct observeDeep/debouncedChange wiring on view row_orders with a handleRowOrdersChange function that first tries syncUnconditionedRowOrders and falls back to debouncedChange.
  • Adjust the effect dependencies to include rowOrders and syncUnconditionedRowOrders so subscriptions track the current Yjs array.
  • Update cleanup logic to unobserve the new handleRowOrdersChange from rowOrders instead of unobserving debouncedChange from the view.
src/application/database-yjs/selector.ts
Add regression tests for row order behavior, including immediate updates, array replacement, and active-filter guards.
  • Extend the DatabaseFixture to expose rowOrders and view so tests can mutate the Yjs structures directly.
  • Add a test asserting that unfiltered row orders update immediately when rows are inserted and deleted.
  • Add a test validating resubscription when the row_orders array on the view is replaced and subsequent changes propagate.
  • Add a test ensuring that when filters are active, raw row order changes do not immediately change the published row order (remain on the debounced conditioned path).
src/application/database-yjs/__tests__/useRowOrdersSelector.test.tsx

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

Copy link
Copy Markdown

@sourcery-ai sourcery-ai Bot left a comment

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:

  • In syncUnconditionedRowOrders, consider guarding the setRowOrdersState call with a shallow equality check against the current state to avoid unnecessary re-renders on every raw row_orders change when the order content hasn't actually changed.
  • syncUnconditionedRowOrders and onConditionsChange both compute and manage conditionSignature / conditionSignatureRef in similar ways; factoring the shared logic into a small helper would reduce duplication and make future changes to condition handling less error-prone.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `syncUnconditionedRowOrders`, consider guarding the `setRowOrdersState` call with a shallow equality check against the current state to avoid unnecessary re-renders on every raw row_orders change when the order content hasn't actually changed.
- `syncUnconditionedRowOrders` and `onConditionsChange` both compute and manage `conditionSignature` / `conditionSignatureRef` in similar ways; factoring the shared logic into a small helper would reduce duplication and make future changes to condition handling less error-prone.

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.

@appflowy appflowy merged commit 59c31c5 into main May 15, 2026
13 checks passed
@appflowy appflowy deleted the fix/database-row-order-refresh branch May 15, 2026 13:49
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.

1 participant