-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: no hydration when new promise comes in (#8383)
* add failing repro test * update assertinos * add logg * ehm - maybe fix? * rm -only * make example * upd * ad debug logs * more debugging * push * maybe??? * rm log * revert * fix: ? * fix: check for pending status again otherwise, we risk including promises that happen because of background updates (think persistQueryClient) * fix: clear serverQueryClient between "requests" otherwise, we are re-using the cache and the query won't be in "pending" state the second time around * chore: remove logs * rethrow next build error * kick off ci again * add `shouldRedactError` option * pluralize * docs * chore: more memory * chore: revert more memory * don't compare statuses if they don't exist * ci: apply automated fixes * lint --------- Co-authored-by: Dominik Dorfmeister <[email protected]> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
- Loading branch information
1 parent
bb25d06
commit 6ca0eb7
Showing
11 changed files
with
207 additions
and
19 deletions.
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 |
---|---|---|
@@ -0,0 +1,11 @@ | ||
'use server' | ||
|
||
import { revalidatePath } from 'next/cache' | ||
import { countRef } from './make-query-client' | ||
|
||
export async function queryExampleAction() { | ||
await Promise.resolve() | ||
countRef.current++ | ||
revalidatePath('/', 'page') | ||
return undefined | ||
} |
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 |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { countRef } from '../make-query-client' | ||
|
||
export const GET = () => { | ||
return Response.json({ count: countRef.current }) | ||
} |
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 |
---|---|---|
@@ -1,30 +1,41 @@ | ||
import { headers } from 'next/headers' | ||
import React from 'react' | ||
import { HydrationBoundary, dehydrate } from '@tanstack/react-query' | ||
import { Temporal } from '@js-temporal/polyfill' | ||
import { ClientComponent } from './client-component' | ||
import { makeQueryClient, tson } from './make-query-client' | ||
import { makeQueryClient } from './make-query-client' | ||
import { queryExampleAction } from './_action' | ||
|
||
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms)) | ||
|
||
export default async function Home() { | ||
export default function Home() { | ||
const queryClient = makeQueryClient() | ||
|
||
void queryClient.prefetchQuery({ | ||
queryClient.prefetchQuery({ | ||
queryKey: ['data'], | ||
queryFn: async () => { | ||
await sleep(2000) | ||
const { count } = await ( | ||
await fetch('http://localhost:3000/count', { | ||
headers: await headers(), | ||
}) | ||
).json() | ||
|
||
return { | ||
text: 'data from server', | ||
date: Temporal.PlainDate.from('2024-01-01'), | ||
count, | ||
} | ||
}, | ||
}) | ||
|
||
const state = dehydrate(queryClient) | ||
|
||
return ( | ||
<main> | ||
<HydrationBoundary state={dehydrate(queryClient)}> | ||
<HydrationBoundary state={state}> | ||
<ClientComponent /> | ||
</HydrationBoundary> | ||
<form action={queryExampleAction}> | ||
<button type="submit">Increment</button> | ||
</form> | ||
</main> | ||
) | ||
} |
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
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