Skip to content

add useEntitiesPublicInfinite hook - #552

Merged
nikgraf merged 1 commit into
mainfrom
nik/add-useEntitiesPublicInfinite-hook
Nov 14, 2025
Merged

add useEntitiesPublicInfinite hook#552
nikgraf merged 1 commit into
mainfrom
nik/add-useEntitiesPublicInfinite-hook

Conversation

@nikgraf

@nikgraf nikgraf commented Nov 14, 2025

Copy link
Copy Markdown
Collaborator

No description provided.

@nikgraf
nikgraf force-pushed the nik/add-useEntitiesPublicInfinite-hook branch from 063ba61 to 68f1d5f Compare November 14, 2025 16:43
@nikgraf
nikgraf requested a review from Copilot November 14, 2025 16:46
@nikgraf
nikgraf merged commit dded603 into main Nov 14, 2025
10 checks passed
@nikgraf
nikgraf deleted the nik/add-useEntitiesPublicInfinite-hook branch November 14, 2025 16:48

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds a new useEntitiesPublicInfinite hook to enable infinite scroll/pagination for public entities using TanStack Query's infinite query capabilities. The implementation follows the existing pattern of public entity queries but adds support for pagination through getNextPageParam.

  • Introduces useEntitiesPublicInfinite hook for infinite pagination of public entities
  • Updates QueryPublicParams type to make enabled parameter optional
  • Adds example implementation demonstrating infinite query usage with podcasts

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
packages/hypergraph-react/src/internal/types.ts Makes the enabled parameter optional in QueryPublicParams to align with typical React Query patterns
packages/hypergraph-react/src/index.ts Exports the new useEntitiesPublicInfinite hook
packages/hypergraph-react/src/hooks/use-entities-public-infinite.ts Implements the new infinite query hook using TanStack Query's useInfiniteQuery
apps/events/src/routes/podcasts.lazy.tsx Increases the fetch limit from 6 to 100 and removes explicit offset parameter
apps/events/src/routes/podcasts-infinite.lazy.tsx Demo component showcasing the new infinite query hook with automatic pagination
apps/events/src/routes/__root.tsx Adds navigation link to the new podcasts infinite query demo page
apps/events/src/routeTree.gen.ts Auto-generated route tree updates for the new demo route
.changeset/beige-lemons-beg.md Documents the patch-level change for the hypergraph-react package

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"@graphprotocol/hypergraph-react": patch
---

add useEntitiesPublicInfinite hook]

Copilot AI Nov 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changeset description has a typo - there's an extra closing bracket ] at the end of "add useEntitiesPublicInfinite hook]".

Suggested change
add useEntitiesPublicInfinite hook]
add useEntitiesPublicInfinite hook

Copilot uses AI. Check for mistakes.
Comment on lines +37 to +38
getNextPageParam: (_lastPage, pages) => {
return offset + pages.length * first;

Copilot AI Nov 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The getNextPageParam implementation has a bug. It calculates the next offset as offset + pages.length * first, but this doesn't account for the initial offset correctly when paginating.

For example:

  • If offset = 0 and first = 2, after fetching page 1 (pages.length = 1), the next offset would be 0 + 1 * 2 = 2
  • But if offset = 10 and first = 2, after fetching page 1, the next offset would be 10 + 1 * 2 = 12, which skips records 10-11

The calculation should be based on the initial page param, not the initial offset. Consider: pageParam + first or track cumulative records fetched.

Copilot uses AI. Check for mistakes.
Comment on lines +23 to +29
setTimeout(() => {
fetchNextPage();
setTimeout(() => {
fetchNextPage();
}, 1000);
}, 1000);
}, [fetchNextPage]);

Copilot AI Nov 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The useEffect hook with fetchNextPage in the dependency array will cause an infinite loop or unexpected behavior. The fetchNextPage function reference can change between renders, causing the effect to re-run repeatedly.

This implementation also lacks proper cleanup - if the component unmounts before the timeouts complete, they will still execute.

For demo purposes, consider adding a button to trigger pagination manually, or add proper guards and cleanup:

useEffect(() => {
  let cancelled = false;
  const timer1 = setTimeout(() => {
    if (!cancelled) fetchNextPage();
    const timer2 = setTimeout(() => {
      if (!cancelled) fetchNextPage();
    }, 1000);
  }, 1000);
  
  return () => {
    cancelled = true;
    clearTimeout(timer1);
  };
}, []); // Empty dependency array
Suggested change
setTimeout(() => {
fetchNextPage();
setTimeout(() => {
fetchNextPage();
}, 1000);
}, 1000);
}, [fetchNextPage]);
const timer1 = setTimeout(() => {
fetchNextPage();
const timer2 = setTimeout(() => {
fetchNextPage();
}, 1000);
}, 1000);
return () => {
clearTimeout(timer1);
};
}, []);

Copilot uses AI. Check for mistakes.
mode: 'public',
first: 6,
offset: 0,
first: 100,

Copilot AI Nov 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The offset parameter has been removed. If pagination was previously being used with this component, removing offset: 0 without adding corresponding pagination logic could be a breaking change. Consider whether this removal is intentional or if pagination should be maintained.

Copilot uses AI. Check for mistakes.
typeIds,
relationTypeIds.level1,
relationTypeIds.level2,
filter,

Copilot AI Nov 14, 2025

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The queryKey is missing the first parameter, which affects query caching. If the same query is made with different first values, they will share the same cache key and return incorrect results.

The queryKey should include first to ensure proper cache isolation:

queryKey: [
  'hypergraph-public-entities',
  space,
  typeIds,
  relationTypeIds.level1,
  relationTypeIds.level2,
  filter,
  first, // Add this
  'infinite',
],
Suggested change
filter,
filter,
first,

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants