Code Monkey home page Code Monkey logo

next-13's Introduction

Just started hacking a bit with tRPC and Next 13.

This is not anywhere closed to the finished design and just a playground for our own exploration.

Overview

  • /@trpc/* represent an imaginary trpc lib for Next 13
  • Feel free to add whatever you want to get a feel of Next 13 + tRPC combo
  • Deployed at rsc.trpc.io

See the Issues for things we want to hack on

next-13's People

Contributors

eug-vs avatar juliusmarminge avatar katt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

next-13's Issues

Use `post.create`

  • Gotta be a client-side component
  • Unsure if we should use react-query for mutation, we could or use @trpc/client directly

How to align the client/server DX?

Currently, we use rsc.* to fetch data on the server and trpc.* on the client.

I wish this was the same object used so you didn't have to care if you're on the server or the client.

npm install issue

npm install throws below error messages to console log

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: [email protected]
npm ERR! Found: [email protected]
npm ERR! node_modules/next
npm ERR!   next@"^13.0.1-canary.3" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer next@"^12.2.5" from [email protected]
npm ERR! node_modules/next-auth
npm ERR!   next-auth@"4.14.0" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.

probably, change version to next@"^13.0.3" from next@"^13.0.1-canary.3" and "next-auth": to "4.16.4", will work.

tRPC 10 with Next 13 App dir

Thank you to anyone who takes the time to respond or share their thoughts on this matter.
With the condition that the app folder was used exsclusevly with client components (to gain access to the nested layouts feature),
is there a way to setup tRPC 10 to work in the app dir?

Thanks again

Maybe we wanna use `use()`

Maybe we want to do

function MyComponent() {
  const post = use(trpc.post.byId({ id: "1"}))
  // [...]

In order to enable parallelization and using Promise.all, etc

Open questions

Just dumping some thoughts / half-baked ideas here

  • With RSC - is there a point of tRPC? Is there a "lighter" approach that might be nice(r)? Maybe, but not for all
  • With RSC - is there a point of react-query? yes, there's still client components
  • Will there be a way to sync state and make sync the underlying state of the queries from RSC -> client & make isomorphic components?
    • Biggest question - unsure how state sync can work from a root "use client" Provider that renders on the server to the client that uses it.
  • Will importing the full router on every RSC-request add any significant overhead?
  • Will React Context providers be available on the server? If so, it be possible to do any "isomorphic" context providers? Will components be able to be isomorphic? This was a misconception. We'll do a root "use client" component & likely not sync state from actual RSC-components to client
    • If query state could be synced from server to client and context providers + components could be isomorphic, we could do stuff like using optimistic updates of a component that was initially rendered on the server.
  • How to deal with caching?
  • [..]

Idea: hydrate `react-query` cache more automagically

The way we hydrate the react-query cache on the client is a bit convoluted and unnecessarily complex DX.

I think I could make mine a bit easier to deal with so it's more generic instead:

  • In RSC, create a real queryClient from react-query & populate it's cache when calling stuff
  • Pass queryClientData={hydrate(queryClient}} to the Client component
  • Have a generic HOC on client components that expects a queryClientData & uses setQueryData

API on the server (here) could look something like:

Not that nice with HOC
// page.tsx
function PostListRSC() {
  const postList = rscClient.post.list.fetch({});

  return (
    <PostList
      queryClientData={rscClient.hydrate()}
    />
  );
}

Or, if the HOC was a render-prop thing, maybe this could work:

// page.tsx
function PostListRSC() {
  const postList = rscClient.post.list.fetch({});

  return (
    <Hydrated
      queryClient={rscClient.hydrate()}
      Component={PostList}
    />
  );
}

Then, the client could "just work" in a pre-hydrated way where we wouldn't need to pass initialData.

Overview of how to do it

  • Create a new recursive proxy like the one we have in /@trpc
  • Create new QueryClient() and populate it as we're calling (similar to our utils.*.fetch()

  • Don't take the API design above as absolute truth, it's probable that it will have to be slightly different
  • One important caveat is that we need to make sure this queryClient isn't used across multiple clients' requests.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.