-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
feat(react-query): next-app-router example with prefetch helpers #5451
Merged
Merged
Changes from all commits
Commits
Show all changes
123 commits
Select commit
Hold shift + click to select a range
70a0c71
next-app-router example with prefetch helpers
juliusmarminge fd05259
chore: apply lint and formatting fixes
autofix-ci[bot] e8e3c8d
<Posts/>
juliusmarminge 04bb3b9
commity env
juliusmarminge 18df440
readme
juliusmarminge 1375467
why did autofixer do thsi?
juliusmarminge 5b5f71e
fix manypkg things...
juliusmarminge 82d4d85
Merge branch 'next' into app-router-example
juliusmarminge 9d7762a
chore: apply lint and formatting fixes
autofix-ci[bot] e9fe669
Merge branch 'next' into app-router-example
juliusmarminge efa894c
wtf linter???
juliusmarminge 40ea132
no infer
juliusmarminge ad941c8
Merge branch 'next' into app-router-example
juliusmarminge 1b2ea2d
skip this autolinter thing
juliusmarminge bbeaea4
Merge branch 'next' into app-router-example
juliusmarminge 42d96f5
Merge branch 'next' into app-router-example
juliusmarminge 45a9eb5
up
juliusmarminge b729b2b
wait query with nested suspense
juliusmarminge 97c049d
docs: update batching toggle docs (#5553)
KATT 9e26b44
fix(server + client): skip referencing `NodeJS.*` (#5562)
KATT 0175098
fix: Export required types for TypeScript workspaces (#5500)
jeffberry dde5e8b
fix(example): custom websocket server not upgrading due to next 13.4.…
dougkulak 5eadbc7
chore: make dependabot understand bumps in `next`-tag (#5578)
KATT 3be4c5a
chore: bump pnpm (#5579)
KATT cf27db6
feat(server): add `experimental_caller()` (#5584)
KATT c36d09f
feat(server): add an `onError`-option to router caller (#5585)
KATT bba3f97
feat(next app dir): rethrow built-in Next errors (#5587)
KATT bf5ce50
feat(server): add next.js `experimental_caller()`-adapter (#5589)
KATT b9b3610
return redirect (#5593)
juliusmarminge db93230
patch(server): bump `@fastify/websocket` to 10.0.1 (#5592)
vafanassieff 3067e25
chore(docs): Update setup.mdx (#5594)
KATT 143bfaa
feat: release v11 release candidate (#5601)
KATT 5c009f9
patch(server): fix `dev --turbo` (#5604)
KATT 50959e1
fix(deps): update dependency eslint-plugin-unicorn to v52 (#5608)
renovate[bot] 375abc3
fix(react-query): use `optsRef` in `useSubscription` (#5610)
KATT 683e592
fix(deps): update dependency @testing-library/dom to v10 (#5617)
renovate[bot] 86dd51d
fix(server): remove extra export for router (#5621)
ax-at af1a832
docs: Add Ethereum DApp example (#5615)
tr1sm0s1n 7fd3e2e
fix(deps): update dependency @testing-library/react to v15 (#5624)
renovate[bot] 550563e
chore(deps): Remove unused dependency aws-lambda (#5628)
astuyve c61de82
chore: make sure test job runs on pushes (#5630)
KATT c48eb0a
chore: fix codecov (#5631)
KATT fbf388a
patch(client): createInnerProxy exclude apply bind and call (#5629)
KATT 4e9ca0a
chore: bump prisma (#5632)
KATT aa0d06d
feat: export procedure types (#5640)
infodusha 7bb86bb
chore: remove `name:` from jobs in ci (#5641)
KATT f418809
fix(deps): update dependency devalue to v5 (#5646)
renovate[bot] 854353d
feat: Support Content Types other than JSON (FormData, File, Blob, Ui…
Nick-Lucas 235787b
fix: dump complex formdata stuff in favor of "using the platform" (#5…
juliusmarminge 1769441
chore: better error for mismatched content-type (#5654)
juliusmarminge 2a81b34
feat(react-query): expose `setQueriesData` in `useUtils` (#5605)
nabeelvalley 1b66b3f
Update migrate-from-v10-to-v11.mdx (#5655)
KATT be7d3f0
Update migrate-from-v10-to-v11.mdx (#5656)
KATT e36bbae
fix: rollback formdata/octet type stream support (#5661)
KATT f5b8246
feat: add trpc-rabbitmq & trpc-mqtt to the awesome-trpc list (#5664)
edorgeville 74cb83d
fix(deps): update dependency cssnano to v7 (#5669)
renovate[bot] c060eb2
feat(server): export `TRPCBuilder` class from `@trpc/server` package …
opiation 8a63dd1
chore: bump react version (#5680)
KATT 935cc8b
chore: add secret to codecov (#5633)
KATT 4ff00b3
chore: fix codecov badge (#5689)
KATT 0b9f580
chore: fix codecov for forks (#5688)
KATT 634775a
feat(react-query): add support for global onSuccess for mutation (#5668)
tomer-yechiel 2b3f2c3
docs: fix link to the react query integration page (#5693)
fpetrakov 5fe9779
feat: add formdata and octet stream support (#5665)
Nick-Lucas ab18070
chore(server): rewrite `resolveHTTPResponse` with Fetch (#5684)
KATT 5bd12e0
chore: tweak some comments (#5694)
KATT c67c598
chore: trigger subtree after release (#5695)
KATT f3e31b2
fix(deps): update dependency @headlessui/react to v2 (#5706)
renovate[bot] f9af5c3
chore(server): use `Readable.fromWeb()` to pipe responses (#5701)
KATT bfd5f2e
fix(deps): update dependency eslint-plugin-unicorn to v53 (#5712)
renovate[bot] 05af9e4
chore: bump react (#5720)
KATT b35c918
feat(client): add `'none'` color option to default logger, add `withC…
jonluca d66a1d7
feat(server): websocket keep alive (#5715)
buraktt a43a348
Fixes a single typo in docs (#5716)
babakfp 0784b4b
docs: add used by google (#5722)
KATT 3a3bc2e
fix(server): handle large POST bodies in node-http (#5724)
jcarrus 9bd66a4
feat(server + client): streaming mutations and queries over HTTP (#5700)
KATT 1c0fc79
Add trpc-cli to awesome-trpc (#5733)
mmkal e01b7d5
docs: update aws-lambda.md (#5740)
KATT 81d5810
Merge branch 'next' into app-router-example
juliusmarminge f8455e7
rev
juliusmarminge 97340c3
updates
juliusmarminge 1c4916e
rm dep
juliusmarminge 3e31afb
try getting stream provider working
juliusmarminge 0198a3e
Merge branch 'next' into app-router-example
juliusmarminge b515336
chore: apply lint and formatting fixes
autofix-ci[bot] ffa4e27
this'd be neat
juliusmarminge 88aae3e
okayyy
juliusmarminge d0fd6d5
nicee
juliusmarminge 857c383
Merge branch 'next' into app-router-example
juliusmarminge c11abdf
rm prefetchquery hoc
juliusmarminge 37762c3
rethrow
juliusmarminge 86545ce
reset lock
juliusmarminge 1ee8428
revert autofixed stuff...
juliusmarminge f10c6f7
chore: apply lint and formatting fixes
autofix-ci[bot] 1fc24fe
disable autofixer
juliusmarminge 4d068ac
release tmp
juliusmarminge 895b718
Merge branch 'next' into app-router-example
juliusmarminge 59cdcc8
clarify comments
juliusmarminge bc87f07
fix bad import paths
juliusmarminge d4ee6d9
merge
juliusmarminge 840e186
hmm
juliusmarminge 4e17306
Merge branch 'next' into app-router-example
juliusmarminge a81c961
rm example in favor of current
juliusmarminge cd2b8e9
revert
juliusmarminge 0e27e9f
sync lock
juliusmarminge 6e3efa6
use shared getter
juliusmarminge 67aecc1
dynammic
juliusmarminge 1ca7af8
fix build
juliusmarminge a807f80
tsprune
juliusmarminge 3af8013
fix link
juliusmarminge 76c56f4
update link in test
juliusmarminge bc33899
test
juliusmarminge 67d2544
improve test accuracy
juliusmarminge c359a47
rm
juliusmarminge 882a6dd
data transforming
juliusmarminge 28243c3
niceee
juliusmarminge 18be748
superjson
juliusmarminge 3b987a5
Merge branch 'next' into app-router-example
juliusmarminge ada86cc
Merge branch 'next' into app-router-example
juliusmarminge 2b04d65
bump tsq
juliusmarminge 77c47e7
transformer.deserialize
juliusmarminge cd5a683
clarfiy
juliusmarminge File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,8 @@ dist/ | |
.eslintcache | ||
*.tsbuildinfo | ||
|
||
db.sqlite | ||
|
||
node_modules/ | ||
package-lock.json | ||
yarn.lock | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
5 changes: 5 additions & 0 deletions
5
examples/.experimental/next-app-dir/src/app/rsc-rq-prefetch/layout.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { TRPCReactProvider } from '~/trpc/rq-client'; | ||
|
||
export default function Layout(props: Readonly<{ children: React.ReactNode }>) { | ||
return <TRPCReactProvider>{props.children}</TRPCReactProvider>; | ||
} |
18 changes: 18 additions & 0 deletions
18
examples/.experimental/next-app-dir/src/app/rsc-rq-prefetch/page.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { HydrateClient, trpc } from '~/trpc/rq-server'; | ||
import React from 'react'; | ||
import { Post } from './post'; | ||
|
||
export const dynamic = 'force-dynamic'; | ||
|
||
export default function Home() { | ||
void trpc.getLatestPost.prefetch(); | ||
|
||
return ( | ||
<main> | ||
<h1>Latest Post</h1> | ||
<HydrateClient> | ||
<Post /> | ||
</HydrateClient> | ||
</main> | ||
); | ||
} |
46 changes: 46 additions & 0 deletions
46
examples/.experimental/next-app-dir/src/app/rsc-rq-prefetch/post.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
'use client'; | ||
|
||
import { trpc } from '~/trpc/rq-client'; | ||
import React from 'react'; | ||
|
||
export function Post() { | ||
const utils = trpc.useUtils(); | ||
const [latestPost] = trpc.getLatestPost.useSuspenseQuery(); | ||
|
||
const { mutate: createPost } = trpc.createPost.useMutation({ | ||
onSuccess: async () => { | ||
await utils.invalidate(); | ||
}, | ||
}); | ||
|
||
return ( | ||
<div> | ||
<div style={{ display: 'flex', flexDirection: 'column' }}> | ||
<span>Title: {latestPost.title}</span> | ||
<span>Content: {latestPost.content}</span> | ||
<span>Created At: {latestPost.createdAt.toLocaleString()}</span> | ||
</div> | ||
<form | ||
style={{ | ||
display: 'flex', | ||
flexDirection: 'column', | ||
gap: 8, | ||
maxWidth: 300, | ||
marginTop: 16, | ||
}} | ||
onSubmit={(e) => { | ||
e.preventDefault(); | ||
const data = new FormData(e.target as HTMLFormElement); | ||
createPost({ | ||
title: data.get('title') as string, | ||
content: data.get('content') as string, | ||
}); | ||
}} | ||
> | ||
<input name="title" placeholder="title" /> | ||
<input name="content" placeholder="content" /> | ||
<button type="submit">Create Post!</button> | ||
</form> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
examples/.experimental/next-app-dir/src/trpc/rq-client.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
'use client'; | ||
|
||
import type { QueryClient } from '@tanstack/react-query'; | ||
import { QueryClientProvider } from '@tanstack/react-query'; | ||
import { ReactQueryDevtools } from '@tanstack/react-query-devtools'; | ||
import { loggerLink, unstable_httpBatchStreamLink } from '@trpc/client'; | ||
import { createTRPCReact } from '@trpc/react-query'; | ||
import type { AppRouter } from '~/server/routers/_app'; | ||
import { useState } from 'react'; | ||
import { createQueryClient, getUrl, transformer } from './shared'; | ||
|
||
export const trpc = createTRPCReact<AppRouter>(); | ||
|
||
let clientQueryClientSingleton: QueryClient | undefined = undefined; | ||
const getQueryClient = () => { | ||
if (typeof window === 'undefined') { | ||
// Server: always make a new query client | ||
return createQueryClient(); | ||
} else { | ||
// Browser: use singleton pattern to keep the same query client | ||
return (clientQueryClientSingleton ??= createQueryClient()); | ||
} | ||
}; | ||
|
||
export function TRPCReactProvider(props: { children: React.ReactNode }) { | ||
const queryClient = getQueryClient(); | ||
|
||
const [trpcClient] = useState(() => | ||
trpc.createClient({ | ||
links: [ | ||
loggerLink({ | ||
enabled: (op) => | ||
process.env.NODE_ENV === 'development' || | ||
(op.direction === 'down' && op.result instanceof Error), | ||
}), | ||
unstable_httpBatchStreamLink({ | ||
transformer, | ||
url: getUrl(), | ||
headers: { 'x-trpc-source': 'react-query' }, | ||
}), | ||
], | ||
}), | ||
); | ||
|
||
return ( | ||
<trpc.Provider client={trpcClient} queryClient={queryClient}> | ||
<QueryClientProvider client={queryClient}> | ||
{props.children} | ||
<ReactQueryDevtools /> | ||
</QueryClientProvider> | ||
</trpc.Provider> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import 'server-only'; | ||
import { createHydrationHelpers } from '@trpc/react-query/rsc'; | ||
import { auth } from '~/auth'; | ||
import type { Context } from '~/server/context'; | ||
import { appRouter } from '~/server/routers/_app'; | ||
import { createCallerFactory } from '~/server/trpc'; | ||
import { headers } from 'next/headers'; | ||
import { cache } from 'react'; | ||
import { createQueryClient } from './shared'; | ||
|
||
const createContext = cache(async (): Promise<Context> => { | ||
const _headers = new Headers(headers()); | ||
_headers.set('x-trpc-source', 'rsc'); | ||
|
||
return { | ||
headers: Object.fromEntries(_headers), | ||
session: await auth(), | ||
}; | ||
}); | ||
|
||
/** | ||
* Create a stable getter for the query client that | ||
* will return the same client during the same request. | ||
*/ | ||
const getQueryClient = cache(createQueryClient); | ||
const caller = createCallerFactory(appRouter)(createContext); | ||
|
||
export const { trpc, HydrateClient } = createHydrationHelpers<typeof appRouter>( | ||
caller, | ||
getQueryClient, | ||
); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
what happens if a promise fails in a place like this?
is it safe / will node crash with "unhandled promise rejection"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void
will ignore errors?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Then the query will be retried when it mounts on the client depending on your retry options