Repository navigation
Recipe data-paginated-list: cover search, and rewrite the deferrals that hide traps - #6
Open
adrianstevens wants to merge 1 commit into
Open
adrianstevens wants to merge 1 commit into
adrianstevens wants to merge 1 commit into
Conversation
…hat hide traps The recipe taught pagination well and listed "filtering and search" under "Does NOT cover" as an independent concern with its own design space. That deferral is the problem. An agent reading it does not become careful; it fills the gap from its priors, and the prior is a client-side .filter() over the fetched pages, because that is what generic React material teaches. Three first-party apps shipped exactly that — Suggestions, RaidPlanner and BlogCraft — and in each one the search could only ever find matches inside the page the client happened to hold, with no error and no empty state to show for it. The recipe also pointed at the shape that failed: it closed by suggesting an IntersectionObserver-driven infinite scroll, without noting that filtering the accumulated pages shrinks the list, which can lift the sentinel out of the viewport, so searching prevents its own results from loading. That is RaidPlanner's bug, recommended. So search is now part of the recipe rather than deferred out of it: - ListRecordsRequest gains `search`, applied server-side in the same SQL as the seek, so paging walks the matching rows instead of walking every row and discarding non-matches. - The cursor payload carries the term it was issued under, and the server restarts from the first page when the term differs. This is the payoff of the existing opaque-cursor design: the payload gained a field and no client had to change. - The client debounces (300ms), resets pagination on a term change, and does no filtering. The first page of any query now REPLACES rather than appends, which makes it idempotent and removes the useRef StrictMode latch entirely — designing the operation to be repeatable beats latching around a repeat. - The test driver passes `search` through so the harness can assert the filtered case, which is the one that cannot be checked by eye. Second change, structural: "Does NOT cover" is split in two. One table for concerns that genuinely live elsewhere and carry no hazard, and one for extensions where the obvious approach is silently wrong — multi-axis filtering, ties in the sort column, user-chosen sorting — each with the trap named and the working shape beside it. The two used to be the same shape on the page, which is how a warning came to read as permission. Verified against the compiled service with a real sqlite database seeded as db.ts seeds it, 9/9. The discriminating case is built in: page one is ids 100..81, "Record 5" matches ids 5 and 50..59, so every match is outside page one and a client-side filter over it would return nothing. Also asserted that filtered paging walks matches (59..55, then 54..50) and that a cursor from another query restarts instead of seeking.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
The recipe taught pagination well and listed filtering under
Does NOT cover:That deferral is the problem. A reader — human or agent — does not become cautious at it; the gap gets filled from priors, and the prior is a client-side
.filter()over the fetched pages, because that is what generic React material teaches. Three first-party apps shipped exactly that. In each one the search could only find matches inside the page the client happened to hold, with no error and no empty state to show for it.The recipe also recommended the shape that failed. It closed by suggesting an
IntersectionObserver-driven infinite scroll without noting that filtering the accumulated pages shrinks the rendered list, which can lift the sentinel out of the viewport, so the observer never fires and searching prevents its own results from loading.What changed
Search is part of the recipe now, not deferred out of it.
ListRecordsRequestgainssearch, applied server-side in the same SQL as the seek, so paging walks the matching rows rather than walking every row and discarding non-matches.useRefStrictMode latch be deleted outright — designing the operation to be repeatable beats latching around a repeat.searchthrough so the harness can assert the filtered case.Second change, structural.
Does NOT coveris split in two: one table for concerns that genuinely live elsewhere and carry no hazard, and one for extensions where the obvious approach is silently wrong — multi-axis filtering, ties in the sort column, user-chosen sorting — each with the trap named and the working shape beside it. Previously both kinds looked identical on the page, which is how a warning came to read as permission. Other recipes likely have the same issue; not swept here.Verification
9/9 against the compiled service with a real sqlite database seeded as
db.tsseeds it. The discriminating case is built into the fixture: page one is ids 100..81, and"Record 5"matches ids 5 and 50..59, so every match sits outside page one and a client-side filter over it returns nothing.What is NOT yet proven
The justification for this change is that it alters what an agent writes when asked to add a search box. That has not been tested. The intended check is an A/B — the same task against this branch and against
main, graded on whether the term reaches the server — with a control arm, because the model may well get it right unaided and this would be taking credit for its priors. Adrian is running that against other systems separately.If it turns out agents get this right without the recipe, the code change still stands on its own (the recipe demonstrably lacked a common case) but the
Does NOT coverrestructure is the part that would need rethinking.Note on comment density
This recipe is teaching material and its established style is dense explanatory comments — that is the product here, and the additions match it. Not the standard applied to app code.