Propose plan: apply BFF/server-pagination pattern app-wide - #2268
Propose plan: apply BFF/server-pagination pattern app-wide#2268harry-rhesis wants to merge 2 commits into
Conversation
Scope rolling the metrics/behaviors server-driven pagination pattern (prefetchList + usePaginatedList from PR #2267) out to the rest of the app's directory pages, with a survey of every candidate page, the backend foundations the pattern depends on, and the CRUD guardrails learned from the behaviors sort-order bug.
There was a problem hiding this comment.
Solid plan and the guardrails (CRUD visibility + sorted insert) are particularly useful.
Two doc issues to fix before merging:
- The referenced
prefetchList/usePaginatedListfiles aren’t present onmainyet (broken links unless #2267 is merged first / you use permalinks). - The “Survey” link is not resolvable from the repo.
|
|
||
| PR #2267 replaced this with two reusable primitives: | ||
|
|
||
| - **[`prefetchList`](../apps/frontend/src/utils/server-prefetch.ts)** — a server-side |
There was a problem hiding this comment.
Improvement: The doc links to ../apps/frontend/src/utils/server-prefetch.ts / ../apps/frontend/src/hooks/usePaginatedList.ts, but those paths (and prefetchList/usePaginatedList symbols) don’t exist on main right now.
Fix: either link to a permalink in PR #2267 / the commit that introduces them, or add a note that this plan assumes #2267 has merged (and ensure merge order), so we don’t end up with broken links on
main.
|
|
||
| ## 5. Survey of candidate pages | ||
|
|
||
| Audit performed via [Survey](fac00d4a-907f-4db2-abec-2a50bb2aee8d) against |
There was a problem hiding this comment.
Improvement: “Audit performed via Survey” is a dead reference from the repo’s perspective.
Fix: replace with a real URL (Notion/Jira/GDoc), a relative path to an included artifact, or remove it and briefly describe the audit method in text.
PR #2267 review added an enabled option to usePaginatedList (and wired it into metrics/behaviors) after this plan was written, closing a gap where the hook fired list requests for users about to see AccessDenied. Document the option and add it as a guardrail/checklist item for future migrations.
There was a problem hiding this comment.
Docs plan is solid, but I’d fix the two doc-quality blockers before merging:
- The links to
../apps/frontend/src/utils/server-prefetch.tsand../apps/frontend/src/hooks/usePaginatedList.tsare broken onmainright now (unless #2267 merges first). Please switch to permalinks in #2267 / the introducing commit, or add an explicit merge-order assumption. - “Audit performed via Survey” is a dead reference. Please replace with a real URL / included artifact, or remove it and describe the audit method in text.
|
@nicolai-rhesis, would you also please check this proposed plan? We can tackle this after @EmanueleDeRossi1's optimizations on the backend. |
|
Hi @harry-rhesis, thanks for drafting this plan! It tackles much-needed things in the app with direct UX implications ( I also like the suggestion of making page.tsx a Next.js Server Component -> remove the blank page/spinner on first load). I'm on board with the direction. Maybe a couple ideas:
|
Purpose
PR #2267 replaced client-side "fetch everything and paginate/filter in memory"
on the metrics and behaviors directory pages with a server-driven pattern:
a Server Component prefetches the first page through the BFF proxy
(eliminating the first-load spinner), and a client hook owns pagination/
filtering against server-pushed OData queries instead of an in-memory dataset.
This is a docs-only PR proposing how to roll that pattern out to the rest
of the app's directory/list pages (projects, models, tools, tokens, tests,
test sets, endpoints, knowledge, test runs, tasks, experiments, annotations,
traces, team members), based on a full audit of their current fetch/pagination
implementations. No application code changes.
What Changed
docs/frontend-bff-pagination-migration-plan.md, covering:prefetchList/usePaginatedListprimitives fromPR Add server-driven pagination and initial fetch for metrics/behaviors #2267 and what they replace.
QueryBuildereager-loading, the two-phase ("id-then-join") pagination query pattern,
the
X-Total-Countheader /PaginatedResponsecontract, OData$filtersupport (including
any()navigation filters through many-to-manyrelationships), custom non-OData params like
metric_scope(JSONB@>)and
$select, and the automatic tenant-isolationbefore_compilehookthat only applies to ORM/Core queries.
already on
useGridQuery/React Query away from that hook; those justneed SSR prefetch added, not a rewrite.
apps/frontend/src/app/(protected)/, split into:cap and filter in memory: projects, models, tools, tokens, explorer.
endpoints, tests, test sets, knowledge, test runs, tasks, experiments,
annotations, team members.
switching create/edit/delete to "refetch the current page" silently hid
newly-created rows when the list was sorted alphabetically and the new
row didn't land on page 0. The fix there (and the guidance here) is to
mutate local state directly (sorted insert/update/remove) rather than
trust a blind refetch, unless sort order guarantees visibility.
pagination fixes, then heavier grids, then special cases), each as its
own small PR per repo convention.
React Query's cache directly vs. just seed a prop; whether entities
returning non-standard shapes (
{ data, totalCount }/{ data, total })should get a shape adapter or be normalized to
PaginatedResponse;backend follow-ups needed for Tokens (
$filtersupport) and Explorer(total-count-bearing response shape) before they can adopt the pattern.
Additional Context
follow-up commit extracting
usePaginatedList/prefetchListas reusableprimitives.
and sequencing before opening per-page migration PRs.
Testing
N/A — documentation only. No app code touched.