Skip to content

Export PreloadQueryRef#549

Open
teodorszeltins wants to merge 1 commit into
apollographql:mainfrom
teodorszeltins:export-preload-query-ref
Open

Export PreloadQueryRef#549
teodorszeltins wants to merge 1 commit into
apollographql:mainfrom
teodorszeltins:export-preload-query-ref

Conversation

@teodorszeltins

@teodorszeltins teodorszeltins commented Apr 9, 2026

Copy link
Copy Markdown

This exports PreloadQueryRef as a public API and adds it to the object returned by registerApolloClient.

Until now, it only existed as an internal helper used by PreloadQuery under the name SimulatePreloadedQuery.

Why

PreloadQuery starts the query from where it appears in the render tree, so the request does not begin until React gets there.

This makes it harder to parallelise GraphQL queries with other async work (REST calls, auth checks, etc.) at the top of a Server Component.

PreloadQueryRef makes that flow a bit more flexible. You can create the queryRef early with createTransportedQueryPreloader, start the query right away, and render <PreloadQueryRef> later to hydrate it into the client tree.

Usage

export default async function Page() {
  const preloader = createTransportedQueryPreloader(await getClient());

  const queryRef = preloader(MY_QUERY, {
    variables: { id: "1" },
  });

  const otherData = await fetchSomeRestEndpoint();

  return (
    <ApolloWrapper>
      <PreloadQueryRef queryRef={queryRef}>
        <Suspense fallback={<>loading...</>}>
          <ClientChild queryRef={queryRef} otherData={otherData} />
        </Suspense>
      </PreloadQueryRef>
    </ApolloWrapper>
  );
}

Summary by CodeRabbit

Release Notes

  • New Features
    • Exported PreloadQueryRef as a public API, now available through registerApolloClient, enabling query-ref-first preloading workflows for improved data fetching patterns.

@teodorszeltins teodorszeltins requested a review from a team as a code owner April 9, 2026 23:05
@apollo-cla

Copy link
Copy Markdown

@teodorszeltins: Thank you for submitting a pull request! Before we can merge it, you'll need to sign the Apollo Contributor License Agreement here: https://contribute.apollographql.com/

@changeset-bot

changeset-bot Bot commented Apr 9, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 04017bd

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 5 packages
Name Type
@apollo/client-react-streaming Minor
@apollo/client-integration-nextjs Minor
@apollo/client-integration-react-router Minor
@apollo/client-integration-tanstack-start Minor
@apollo/experimental-nextjs-app-support Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@netlify

netlify Bot commented Apr 9, 2026

Copy link
Copy Markdown

👷 Deploy request for apollo-client-nextjs-docmodel pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 04017bd

@vercel

vercel Bot commented Apr 9, 2026

Copy link
Copy Markdown

@teodorszeltins is attempting to deploy a commit to the Apollo Client - Next package - integration tests Team on Vercel.

A member of the Team first needs to authorize it.

@coderabbitai

coderabbitai Bot commented Apr 9, 2026

Copy link
Copy Markdown

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 5ddedd8e-52e4-481c-9c8a-dd06ec1ef7e7

📥 Commits

Reviewing files that changed from the base of the PR and between 15eda44 and 04017bd.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (13)
  • .changeset/tidy-taxis-jam.md
  • integration-test/nextjs/package.json
  • integration-test/nextjs/src/app/rsc/client.ts
  • integration-test/nextjs/src/app/rsc/dynamic/PreloadQueryRef/queryRef-useReadQuery/page.tsx
  • integration-test/playwright/src/preloadQuery.test.ts
  • packages/client-react-streaming/package-shape.json
  • packages/client-react-streaming/src/PreloadQuery.tsx
  • packages/client-react-streaming/src/PreloadQueryRef.cc.ts
  • packages/client-react-streaming/src/index.cc.tsx
  • packages/client-react-streaming/src/index.rsc.ts
  • packages/client-react-streaming/src/index.ts
  • packages/client-react-streaming/src/registerApolloClient.tsx
  • packages/client-react-streaming/tsup.config.ts
📜 Recent review details
🧰 Additional context used
🧠 Learnings (5)
📚 Learning: 2026-04-08T16:23:43.800Z
Learnt from: CR
Repo: apollographql/apollo-client-integrations PR: 0
File: .github/instructions/apollo-client.instructions.md:0-0
Timestamp: 2026-04-08T16:23:43.800Z
Learning: Use the apollo-client skill for questions about integrating Apollo Client with frameworks like Next.js, TanStack Start, or React Router

Applied to files:

  • integration-test/nextjs/package.json
  • .changeset/tidy-taxis-jam.md
  • integration-test/nextjs/src/app/rsc/client.ts
  • packages/client-react-streaming/src/registerApolloClient.tsx
  • integration-test/nextjs/src/app/rsc/dynamic/PreloadQueryRef/queryRef-useReadQuery/page.tsx
📚 Learning: 2026-04-08T16:23:43.800Z
Learnt from: CR
Repo: apollographql/apollo-client-integrations PR: 0
File: .github/instructions/apollo-client.instructions.md:0-0
Timestamp: 2026-04-08T16:23:43.800Z
Learning: Use the apollo-client skill for answering questions about Apollo Client setup, configuration, usage, or troubleshooting

Applied to files:

  • integration-test/nextjs/package.json
  • .changeset/tidy-taxis-jam.md
  • integration-test/nextjs/src/app/rsc/client.ts
  • packages/client-react-streaming/src/registerApolloClient.tsx
📚 Learning: 2026-04-08T16:23:43.800Z
Learnt from: CR
Repo: apollographql/apollo-client-integrations PR: 0
File: .github/instructions/apollo-client.instructions.md:0-0
Timestamp: 2026-04-08T16:23:43.800Z
Learning: Apply apollo-client skill when reviewing documentation PRs or content related to Apollo Client

Applied to files:

  • integration-test/nextjs/package.json
  • integration-test/nextjs/src/app/rsc/client.ts
  • packages/client-react-streaming/src/registerApolloClient.tsx
📚 Learning: 2026-04-08T16:23:43.800Z
Learnt from: CR
Repo: apollographql/apollo-client-integrations PR: 0
File: .github/instructions/apollo-client.instructions.md:0-0
Timestamp: 2026-04-08T16:23:43.800Z
Learning: Refer to apollo-client skill guidance over general knowledge for Apollo Client questions, as the skill is trained on Apollo Client 4.x and represents current best practices

Applied to files:

  • integration-test/nextjs/package.json
  • integration-test/nextjs/src/app/rsc/client.ts
  • packages/client-react-streaming/src/registerApolloClient.tsx
📚 Learning: 2026-04-08T16:23:43.800Z
Learnt from: CR
Repo: apollographql/apollo-client-integrations PR: 0
File: .github/instructions/apollo-client.instructions.md:0-0
Timestamp: 2026-04-08T16:23:43.800Z
Learning: Use the apollo-client skill when reviewing documentation-like content including Markdown files, JSDoc/TSDoc docblocks, code comments intended for end users, README files, and API documentation

Applied to files:

  • packages/client-react-streaming/src/registerApolloClient.tsx
🔇 Additional comments (13)
integration-test/nextjs/package.json (1)

15-15: Dependency addition is correct for integration coverage.

Adding @apollo/client-react-streaming as a workspace dependency is the right change to exercise the new PreloadQueryRef API in the Next.js integration test app.

packages/client-react-streaming/src/PreloadQueryRef.cc.ts (1)

12-13: Public export rename is consistent and safe.

PreloadQueryRef keeps the same runtime behavior while correctly promoting the component to public API visibility.

packages/client-react-streaming/tsup.config.ts (1)

90-91: Build entry rename is correctly wired.

The tsup browser entry now points to the renamed PreloadQueryRef client-component module, which keeps bundling aligned with the new public export path.

packages/client-react-streaming/src/index.cc.tsx (1)

5-22: Lazy wrapper migration to PreloadQueryRef looks good.

The renamed lazy-loaded wrapper, type binding, and public-facing docs are all consistent with the new API surface.

packages/client-react-streaming/src/index.ts (1)

12-12: Public re-export is correctly added.

PreloadQueryRef is now exposed from the main entrypoint, matching the intended API expansion.

packages/client-react-streaming/src/index.rsc.ts (1)

6-6: RSC export alignment is correct.

Re-exporting PreloadQueryRef from the RSC entrypoint keeps the server-components API surface consistent with the rest of the package.

packages/client-react-streaming/src/PreloadQuery.tsx (1)

1-1: Wrapper rename in PreloadQuery is correctly applied.

Using PreloadQueryRef here preserves the existing preload flow while aligning with the new public naming.

Also applies to: 61-63

packages/client-react-streaming/src/registerApolloClient.tsx (1)

6-6: registerApolloClient API extension is coherent and complete.

The new PreloadQueryRef return-field is consistently wired across import, type signature, docs example, and runtime return object.

Also applies to: 26-27, 82-85, 116-116

packages/client-react-streaming/package-shape.json (1)

17-17: Consistent package-shape export updates across all targets

PreloadQueryRef is added uniformly to every relevant runtime surface, which avoids target-specific export drift.

Also applies to: 38-38, 59-59, 80-80, 101-101

.changeset/tidy-taxis-jam.md (1)

1-6: Changeset classification and note look correct

Minor bumps for both packages are appropriate for adding a new public export and extending registerApolloClient’s returned API.

integration-test/nextjs/src/app/rsc/client.ts (1)

20-29: PreloadQueryRef export wiring is correct

This correctly surfaces PreloadQueryRef from the registered test client without altering existing client configuration behavior.

integration-test/playwright/src/preloadQuery.test.ts (1)

10-10: Good coverage for PreloadQueryRef behavior

The added cases validate both initial server-side resolution and the client-side refetch path via useQueryRefHandlers.

Also applies to: 181-225

integration-test/nextjs/src/app/rsc/dynamic/PreloadQueryRef/queryRef-useReadQuery/page.tsx (1)

1-30: Query-ref-first PreloadQueryRef page flow is implemented correctly

This page correctly preloads the query before render and hydrates it through PreloadQueryRef for client consumption.


📝 Walkthrough

Walkthrough

This update renames the internal SimulatePreloadedQuery component to PreloadQueryRef and exposes it as a public API export across @apollo/client-react-streaming and @apollo/client-integration-nextjs. The changes include index export updates, package metadata modifications, integration test additions, and build configuration adjustments to reflect the new naming.

Changes

Cohort / File(s) Summary
Changeset & Package Metadata
.changeset/tidy-taxis-jam.md, packages/client-react-streaming/package-shape.json
Documents minor version bump and adds PreloadQueryRef to the public API surface for multiple runtime targets (react-server, browser, node, etc.).
Component Renaming & Core Exports
packages/client-react-streaming/src/PreloadQueryRef.cc.ts, packages/client-react-streaming/src/index.cc.tsx, packages/client-react-streaming/src/index.rsc.ts, packages/client-react-streaming/src/index.ts
Renames SimulatePreloadedQuery to PreloadQueryRef, adds JSDoc @public marker, and updates all index files to export the new component name with appropriate lazy-loading wrappers.
API Integration & Hook Integration
packages/client-react-streaming/src/registerApolloClient.tsx, packages/client-react-streaming/src/PreloadQuery.tsx
Updates registerApolloClient return type to include PreloadQueryRef property; updates PreloadQuery component to use PreloadQueryRef wrapper instead of SimulatePreloadedQuery.
Build Configuration
packages/client-react-streaming/tsup.config.ts
Updates browser entry point to compile src/PreloadQueryRef.cc.ts instead of src/SimulatePreloadedQuery.cc.ts.
Integration Test Setup
integration-test/nextjs/package.json, integration-test/nextjs/src/app/rsc/client.ts
Adds @apollo/client-react-streaming dependency and updates client registration to destructure and export PreloadQueryRef from registerApolloClient.
Integration Test Coverage
integration-test/nextjs/src/app/rsc/dynamic/PreloadQueryRef/queryRef-useReadQuery/page.tsx, integration-test/playwright/src/preloadQuery.test.ts
Adds new test page demonstrating server-side PreloadQueryRef preloading with configurable error handling; introduces Playwright tests validating preload resolution and refetch workflows with useQueryRefHandlers.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'Export PreloadQueryRef' directly and accurately summarizes the main change: exporting a previously internal component as a public API.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

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