Hydra data provider ignores hydra:view pagination links, hardcodes page/itemsPerPage
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 64/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 静か
- 技術スタック
- react, typescript
調査の方向性
src/hydra/dataProvider.ts の convertReactAdminRequestToHydraRequest と、602-631 行付近のレスポンス処理から始めます。GET_LIST のページネーションリクエストと hydra:view リンクがどのように処理されるかを追跡します。初回リクエストで適切な場合に強制的なページネーションを回避し、その後のナビゲーションで hydra:next と hydra:previous に従い、カーソルレスポンスで total ではなく pageInfo を返すようになれば完了です。
索引モデルが issue の本文から書いたものです。
説明
Description
The Hydra data provider hardcodes page and itemsPerPage query parameters on every GET_LIST request, ignoring the cursor-based pagination links (hydra:next, hydra:previous) returned in hydra:view.
This makes it impossible to use cursor-based (keyset) pagination — a common pattern for APIs that avoid offset-based pagination for performance and consistency reasons.
Current behavior
In convertReactAdminRequestToHydraRequest (dataProvider.ts#L413-L414):
if (page) url.searchParams.set('page', page.toString());
if (perPage) url.searchParams.set('itemsPerPage', perPage.toString());
These params are always appended to the request URL, regardless of what the server's hydra:view links specify.
On the response side (dataProvider.ts#L602-L631), when hydra:totalItems is present, the provider returns { data, total } and never reads hydra:view. The hydra:view / pageInfo path is only reached when totalItems is absent — but even then, subsequent requests still send page=N instead of following the cursor URLs from hydra:next / hydra:previous.
Expected behavior
When a collection response includes hydra:view with hydra:next / hydra:previous links, the data provider should use those URLs for navigation instead of constructing page=N&itemsPerPage=X params. This is how Hydra's PartialCollectionView is designed to work — the server tells the client how to navigate.
Specifically:
- For the first page, the provider should request the collection URL (optionally with
itemsPerPage/pageSizeif the server supports it) - For subsequent pages, the provider should follow
hydra:next/hydra:previousURLs from the response'shydra:view - When
hydra:viewis present withouthydra:last, the provider should returnpageInfo(nottotal) so react-admin uses next/prev navigation
Workaround
We currently bypass base.getList entirely in our data provider wrapper — we fetch the collection URL ourselves, track hydra:next/hydra:previous URLs from responses in a cache, and return pageInfo instead of total:
getList: async (resource, params) => {
const page = params.pagination?.page ?? 1;
const perPage = params.pagination?.perPage ?? 25;
const cached = cursorCache.get(cursorKey(resource, params));
let url;
if (page > 1 && cached?.page < page && cached?.nextUrl) {
url = new URL(cached.nextUrl, window.location.origin);
} else if (page > 1 && cached?.page > page && cached?.previousUrl) {
url = new URL(cached.previousUrl, window.location.origin);
} else {
url = new URL(`/api/${resource}`, window.location.origin);
url.searchParams.set("pageSize", String(perPage));
}
const response = await fetch(url.toString(), {
headers: { Accept: "application/ld+json" },
credentials: "include",
});
const json = await response.json();
const view = json["hydra:view"] ?? null;
cursorCache.set(key, {
nextUrl: view?.["hydra:next"] ?? null,
previousUrl: view?.["hydra:previous"] ?? null,
page,
});
return {
data: json["hydra:member"].map(normalize),
pageInfo: {
hasNextPage: !!view?.["hydra:next"],
hasPreviousPage: !!view?.["hydra:previous"],
},
};
}
This works but defeats the purpose of using the Hydra data provider in the first place.
Versions
@api-platform/admin: 4.2.4react-admin: 5.6.1
- 主要言語
- TypeScript
- スター
- 516
- フォーク
- 134
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
api-platform/admin のほかの issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
api-platform/admin#616 · コメント 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 50/100
api-platform/admin#659 · リアクション 1 件 ·
-
難易度 3/5 1〜2日 初心者へのやさしさ 35/100
api-platform/admin#631 · コメント 6 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
api-platform/admin#626 · コメント 1 件 · リアクション 1 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 35/100
api-platform/admin#615 · コメント 4 件 · リアクション 2 件 ·
api-platform/admin の issue をすべて見る
似ている issue
-
blocklist removal
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
MetaMask/eth-phishing-detect#296544 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
pastelsky/bundlephobia#1122 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
category/development priority/P2 scope/file-operations scope/testing type/enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
Enatega Customer and Rider app: Add-ons price is not visible to customer after order is placed. オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100