Skip to content

Fix: Patch application race conditions and large list handling#1

Merged
xentixar merged 2 commits into
diffyne:mainfrom
xentixar:fix/patch-application-race-conditions
Dec 6, 2025
Merged

Fix: Patch application race conditions and large list handling#1
xentixar merged 2 commits into
diffyne:mainfrom
xentixar:fix/patch-application-race-conditions

Conversation

@xentixar
Copy link
Copy Markdown
Contributor

@xentixar xentixar commented Dec 6, 2025

Problem

When using Diffyne with large lists (100+ items) and search functionality, patches were not applying correctly sometimes. Old data would remain visible after search, especially when:

  • Search results changed from many items to few/zero items
  • Rapid search updates occurred
  • Multiple requests were in flight simultaneously

Solution

This PR fixes patch application issues by:

  1. Request Cancellation & Sequencing

    • Cancel pending requests when new ones are made
    • Track request sequence numbers to ignore stale responses
    • Prevent out-of-order patches from being applied
  2. Improved Patch Application Order

    • Apply remove patches first (in reverse index order)
    • Then apply creates/updates/replaces
    • Prevents index shifting issues when removing multiple items
  3. Better Error Handling

    • Enhanced warnings and error messages in PatchApplier
    • More robust path resolution with bounds checking
    • Fallback handling for failed patch applications
  4. Diff Engine Improvements

    • Better handling of empty lists
    • Improved keyed children diffing
    • Removes generated in reverse order on server side

Testing

Tested with:

  • Large lists (100+ items) with search
  • Rapid search changes
  • Search to empty results
  • Search from many to few results

Files Changed

  • resources/js/Diffyne.js - Request cancellation and sequencing
  • resources/js/core/PatchApplier.js - Improved patch application order
  • src/VirtualDOM/DiffEngine.php - Better diff handling for empty lists
  • public/js/diffyne.js - Built JavaScript

Breaking Changes

None - this is a bug fix that maintains backward compatibility.

…ndling

- Add request cancellation and sequencing to prevent stale patches
- Fix patch application order (removes first, then creates/updates)
- Improve error handling in PatchApplier with better warnings
- Enhance diff engine to handle empty lists and keyed children better
- Sort remove patches in reverse order to prevent index shifting
- Add fallback handling for failed patch applications

Fixes issue where old data remains visible after search in large lists (100+ items).
Ensures patches are applied in correct order even with rapid updates.
@xentixar xentixar merged commit 0b1d523 into diffyne:main Dec 6, 2025
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant