Skip to content

fix(LdRepository): restore filtered items when optimistic filters broaden#71

Merged
flxapps merged 4 commits into
devfrom
fix/ld-monkey-filtering
Feb 13, 2026
Merged

fix(LdRepository): restore filtered items when optimistic filters broaden#71
flxapps merged 4 commits into
devfrom
fix/ld-monkey-filtering

Conversation

@flxapps
Copy link
Copy Markdown
Collaborator

@flxapps flxapps commented Feb 12, 2026

This fixes an issue in optimistic filtering where filtering only worked in one direction.

Problem

When a filter became stricter, non-matching items were correctly hidden.
But when the filter was broadened again, those items often didn’t come back right away. In practice, users had to fully clear the filter or refresh to see them again.

Screen Recording 2026-02-12 at 15 59 03

Root cause

The optimistic filter/sort pass in repository.dart wasn’t consistently rebuilding item visibility from the current in-memory paginator state.
Items that had already moved to filteredOut could stay stuck there.

What changed

  • Updated applyOptimisticFilterAndSorting() to recompute filter state for all loaded items on each change.
  • Restores items from LdPaginatorItemState.filteredOut to LdPaginatorItemState.loaded as soon as they match again.
  • Applies sorting after state recalculation so order remains stable and predictable.
  • Added safer mutex handling (try/finally) around the update path.

Result

Optimistic filtering now behaves correctly in both directions:

  • tighten filter → items are hidden
  • broaden filter → matching items immediately reappear

No public API changes.

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes optimistic filtering in LdRepository so that items previously marked as filteredOut are restored to loaded when filters broaden, and ensures mutex release is handled safely during the optimistic update pass.

Changes:

  • Reworks applyOptimisticFilterAndSorting() to recompute filter applicability for all in-memory loaded items each time filters/sorts change.
  • Restores items from LdPaginatorItemState.filteredOut to LdPaginatorItemState.loaded when they match again.
  • Wraps the update path in try/finally to guarantee mutex release.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/liquid_flutter/lib/src/monkey/data/repository.dart Outdated
Comment thread packages/liquid_flutter/lib/src/monkey/data/repository.dart Outdated
Comment thread packages/liquid_flutter/lib/src/monkey/data/repository.dart
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comments suppressed due to low confidence (1)

packages/liquid_flutter/lib/src/list/list_paginator.dart:282

  • With the repository change that can leave _items populated with filteredOut entries while totalItems == 0, refreshList() will enter the totalItems == 0 fetch branch without clearing those existing entries. Because LdListWidget only fetches when getItemAt(position) is null (or pendingRefresh), stale filteredOut items occupying positions can block placeholder fetches and lead to incorrect data being shown/hidden after refresh. Consider resetting/clearing (or at least removing filteredOut entries) before the initial fetch when totalItems == 0 so indices represent the refreshed dataset.
  Future<void> refreshList() async {
    for (final item in _items.entries) {
      if (item.value.value != null && item.value.state != LdPaginatorItemState.filteredOut) {
        _items[item.key] = item.value.copyWith(state: LdPaginatorItemState.pendingRefresh);
      }
    }
    _updated(null);

    // The list has not been fetched yet or we filtered out all the items
    // optimistically.
    if (totalItems == 0 || _items.isEmpty) {
      _setBusy(true);
      _offsetQueue.clear();
      await fetchItemsAtOffset(initialOffset);
      _setBusy(false);

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread packages/liquid_flutter/lib/src/monkey/data/repository.dart Outdated
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@flxapps flxapps merged commit f04c97a into dev Feb 13, 2026
8 checks passed
@flxapps flxapps deleted the fix/ld-monkey-filtering branch February 13, 2026 13:08
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.

2 participants