Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rough outline for RSC prefetching #4676

Draft
wants to merge 1 commit into
base: pr/rsc
Choose a base branch
from
Draft

Conversation

phryneas
Copy link
Member

@phryneas phryneas commented Oct 27, 2024

This would enable manual endpoint prefetching from Server Components:

function Page() {
  return (
    <PrefetchEndpoints
      baseQuery={baseQuery}
      run={async (prefetch) => {
        // immediate prefetching
        const promise1 = prefetch(api.endpoints.foo, 'bar')
        const promise2 = prefetch(api.endpoints.foo, 'baz')
        // and a "dependent endpoint" that can only be prefetched with the result of the first two
        const result1 = await promise1
        const result2 = await promise2
        prefetch(api.endpoints.foo, result1 + result2)
      }}
    >
      foo
    </PrefetchEndpoints>
  )
}

Drawbacks:

  • as RTK currently doesn't have suspense, this will still render a loading state in SSR. We could add a "blocking" boolean option that could be set on the RSC side e.g. when a crawler request is detected to finish all requests before handing off to client components, so the SSR run would render the final data

Copy link

codesandbox bot commented Oct 27, 2024

Review or Edit in CodeSandbox

Open the branch in Web EditorVS CodeInsiders

Open Preview

Copy link

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

Latest deployment of this branch, based on commit c9756bd:

Sandbox Source
@examples-query-react/basic Configuration
@examples-query-react/advanced Configuration
@examples-action-listener/counter Configuration
rtk-esm-cra Configuration

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