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

major(next): support Next 13 and React Server Components #3214

Merged
merged 27 commits into from
Jul 21, 2023

Conversation

JoviDeCroock
Copy link
Collaborator

@JoviDeCroock JoviDeCroock commented May 12, 2023

Resolves #3208
Resolves #3219

Summary

This creates a new package @urql/next (and replaces next-urql), the goal is to achieve good Next 13 support.

In essence this creates two new entry points

  • @urql/next the entry points for components rendered on the server and hydrated on the client, this uses a few next-internals to hydrate data as DOM streams to the client
  • @urql/next/rsc this solely intends to create a client that can be used and shared across
    server components. The sharing method is react.cache

You can play with an example here the main idea is that in Next we need a way to retrieve context values on the client so they can be shared. During the stream the values will be flushed, we use this to ensure we have all the data we need. In the example you can see that we have two suspense boundaries, neither will initiate a fetch on the client but instead you'll see a script tag get populated twice, one for each boundary. We read these <script tags and add them to the ssr-exchange.

TODO:

  • resolve the build warning
  • add an example
  • check if we can find a good way of testing this (spoiler: nope)
  • update documentation
  • find a way around the key warning for <script />
  • find a way to add "use client" to the @urql/next entry-point
  • think about handling text/event-stream and multipart/mixed, do we just remove @defer and @stream during ssr? Or can we add a mechanism that ensures these are handled correctly i.e. by means of a useFragment-like mechanism throwing promises as well

Having an awkward problem where it's not letting me create a changeset on my fork 😅

People can still use next-urql for the old next supported ways

packages/next-urql/src/index.ts Show resolved Hide resolved
packages/next-urql/src/useQuery.ts Outdated Show resolved Hide resolved
packages/next-urql/src/useUrqlValue.ts Outdated Show resolved Hide resolved
packages/next-urql/src/useUrqlValue.ts Show resolved Hide resolved
packages/next-urql/package.json Show resolved Hide resolved
@vercel
Copy link

vercel bot commented May 18, 2023

The latest updates on your projects. Learn more about Vercel for Git ↗︎

1 Ignored Deployment
Name Status Preview Comments Updated (UTC)
urql-docs ⬜️ Ignored (Inspect) Visit Preview May 29, 2023 6:09pm

@JoviDeCroock JoviDeCroock marked this pull request as ready for review May 18, 2023 16:51
Copy link
Member

@kitten kitten left a comment

Choose a reason for hiding this comment

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

Just some minor questions. Sourcemaps question is the only relevant for publishing and correctness.

We're missing TSDocs for the public APIs, but I think I can add those later on before publishing as well

scripts/rollup/banner-plugin.mjs Outdated Show resolved Hide resolved
packages/next-urql/src/Provider.ts Show resolved Hide resolved
packages/next-urql/src/rsc.ts Outdated Show resolved Hide resolved
@JoviDeCroock
Copy link
Collaborator Author

JoviDeCroock commented May 28, 2023

Should I copy the useQuery TSDocs from the react implementation or is there a way to inherit?

EDIT: @inheritDoc doesn't do much in VSCode atleast

Copy link
Member

@kitten kitten left a comment

Choose a reason for hiding this comment

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

LGTM 👍 I haven't tested this in code, but I think we can release this as a prerelease and see what happens 😄 Wdyt?

@kitten kitten merged commit 889ca4d into urql-graphql:main Jul 21, 2023
6 checks passed
@github-actions github-actions bot mentioned this pull request Jul 21, 2023
@JoviDeCroock JoviDeCroock deleted the next-13-package branch September 11, 2023 08:26
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.

TS Error when trying to use the next-urql default exchanges RFC (next-urql): Support for Next.js app router