Skip to content

fix(gqty): resolve crash and redundant fetches during prepareReactRender#2325

Open
schettn wants to merge 1 commit intogqty-dev:mainfrom
schettn:fix-null-selections
Open

fix(gqty): resolve crash and redundant fetches during prepareReactRender#2325
schettn wants to merge 1 commit intogqty-dev:mainfrom
schettn:fix-null-selections

Conversation

@schettn
Copy link
Copy Markdown

@schettn schettn commented Apr 27, 2026

Improve SSR stability and performance by ensuring valid GraphQL generation for null objects and deduplicating fetches for already-cached data.

  • Update resolve.ts to fallback to leaf nodes or __typename for null objects and empty arrays, preventing invalid GraphQL queries (e.g., human { nullFather }).
  • Update select.ts to return null instead of undefined for sub-paths of explicitly null nodes, correctly identifying resolved states.
  • Implement a robust cache-aware filter in prepareRender.ts to skip redundant fetches for data already hydrated in the cache.
  • Optimize cache notification and preparation checks with recursive hasValue and hasMissing helpers, replacing inefficient flat(Infinity) calls.
  • Add comprehensive test cases in useQuery.test.tsx covering null object access and partial cache hits in arrays during SSR.

Note: @vicary All newly added test cases were verified to fail prior to these changes, confirming the identified bugs. While all existing tests continue to pass, please review the implementation for any unintended side effects or if an alternative architectural approach is preferred.

Improve SSR stability and performance by ensuring valid GraphQL generation for null
objects and deduplicating fetches for already-cached data.

- Update `resolve.ts` to fallback to leaf nodes or `__typename` for null objects
  and empty arrays, preventing invalid GraphQL queries (e.g., `human { nullFather }`).
- Update `select.ts` to return `null` instead of `undefined` for sub-paths of
  explicitly null nodes, correctly identifying resolved states.
- Implement a robust cache-aware filter in `prepareRender.ts` to skip redundant
  fetches for data already hydrated in the cache.
- Optimize cache notification and preparation checks with recursive `hasValue` and
  `hasMissing` helpers, replacing inefficient `flat(Infinity)` calls.
- Add comprehensive test cases in `useQuery.test.tsx` covering null object access
  and partial cache hits in arrays during SSR.
@@ -489,49 +490,71 @@ describe('mutate accessors', () => {
} as unknown as Human);

expect(owner).toMatchInlineSnapshot(`
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

those are only whitespace changes.. sorry

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.

1 participant