Skip to content

Fix: @catch on fragment root breaks usePaginationFragment and usePrefetchableForwardPaginationFragment#5281

Open
christiansany wants to merge 3 commits into
facebook:mainfrom
christiansany:bug/pagination-fragment-root-catch-hasnext
Open

Fix: @catch on fragment root breaks usePaginationFragment and usePrefetchableForwardPaginationFragment#5281
christiansany wants to merge 3 commits into
facebook:mainfrom
christiansany:bug/pagination-fragment-root-catch-hasnext

Conversation

@christiansany

@christiansany christiansany commented May 13, 2026

Copy link
Copy Markdown
Contributor

Problem

When @catch is applied to the root of a fragment used with usePaginationFragment, hasNext always returned false even when the response included pageInfo.hasNextPage: true. @catch on a child field worked correctly — only the root-level case was broken.

Root cause

When @catch is on the fragment root, the compiler sets metadata.catchTo: "RESULT" on the ReaderFragment. At read time, RelayReader._catchErrors wraps the entire fragment data in a Result envelope:

{ok: true, value: {friends: ..., id: ...}}
// or
{ok: false, errors: [...]}

The pagination/refetch hook internals were reading fields directly off fragmentData and never unwrapping this envelope:

  • getConnectionState did getValueAtPath(fragmentData, ["friends"])undefined → returned {cursor: null, hasMore: false}hasNext === false.
  • useLoadMoreFunction and useRefetchableFragmentInternal did fragmentData[identifierField]undefined → broken refetch identifier.

Fix

Added a tiny helper getFragmentInternalData(fragmentNode, fragmentData) that unwraps the Result envelope when catchTo === 'RESULT' (no-op otherwise). Applied it at every internal call site that reads from fragmentData. The user-facing data returned from usePaginationFragment remains wrapped, matching the generated Result<T, unknown> type.

…t hasNext

When @catch is applied at the root of a fragment used by usePaginationFragment,
hasNext is reported as false even when pageInfo.hasNextPage is true in the
resolved data. The existing test (with @catch on the connection field) still
passes, isolating the bug to root-level @catch.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@christiansany christiansany changed the title Add failing test: @catch on fragment root breaks usePaginationFragmen… Fix: @catch on fragment root breaks usePaginationFragment and usePrefetchableForwardPaginationFragment May 14, 2026
@christiansany christiansany marked this pull request as ready for review May 15, 2026 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant