Skip to content

Commit 7472798

Browse files
fix(live-preview): client-side live preview cannot populate more than 10 relationships at once (#12929)
### What? Set the `limit` query param on API requests called within the `useLivePreview` hook. ### Why? We are heavily relying on the block system in our pages and we reuse the media collection in a lot of the block types. When the page has more than 10 images, the API request doesn't fetch all of them for live preview due to the default 10 item `limit`. This PR allows the preview page to override this `limit` so that all the items get correctly fetched. ### Our current workaround Set the `depth` param of `useLivePreview` hook like this: ``` useLivePreview({ // ... depth: '1000&limit=1000', }) ``` --- - To see the specific tasks where the Asana app for GitHub is being used, see below: - https://app.asana.com/0/0/1210643905956939 --------- Co-authored-by: Jacob Fletcher <[email protected]>
1 parent 605c993 commit 7472798

File tree

2 files changed

+2
-2
lines changed

2 files changed

+2
-2
lines changed

packages/live-preview/src/mergeData.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ export const mergeData = async <T extends Record<string, any>>(args: {
8484
res = await requestHandler({
8585
apiPath: apiRoute || '/api',
8686
endpoint: encodeURI(
87-
`${collection}?depth=${depth}&where[id][in]=${Array.from(ids).join(',')}${locale ? `&locale=${locale}` : ''}`,
87+
`${collection}?depth=${depth}&limit=${ids.size}&where[id][in]=${Array.from(ids).join(',')}${locale ? `&locale=${locale}` : ''}`,
8888
),
8989
serverURL,
9090
}).then((res) => res.json())

test/live-preview/int.spec.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1463,7 +1463,7 @@ describe('Collections - Live Preview', () => {
14631463
// Verify that the request was made to the properly encoded URL
14641464
// Without encodeURI wrapper the request URL - would receive string: "undefined/api/posts?depth=1&where[id][in]=66ba7ab6a60a945d10c8b976,66ba7ab6a60a945d10c8b979
14651465
expect(capturedEndpoint).toContain(
1466-
encodeURI(`posts?depth=1&where[id][in]=${testPost.id},${testPostTwo.id}`),
1466+
encodeURI(`posts?depth=1&limit=2&where[id][in]=${testPost.id},${testPostTwo.id}`),
14671467
)
14681468
})
14691469
})

0 commit comments

Comments
 (0)