-
-
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.
Merge branch 'alpha' into alpha/fix-5562
- Loading branch information
Showing
79 changed files
with
2,012 additions
and
665 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
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,17 @@ | ||
/** @type {import('next').NextConfig} */ | ||
const nextConfig = { | ||
eslint: { | ||
ignoreDuringBuilds: true, | ||
}, | ||
experimental: { | ||
appDir: true, | ||
serverActions: true, | ||
}, | ||
webpack: (config) => { | ||
if (config.name === 'server') config.optimization.concatenateModules = false | ||
|
||
return config | ||
}, | ||
} | ||
|
||
module.exports = nextConfig |
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,24 @@ | ||
{ | ||
"name": "@tanstack/query-example-nextjs-suspense-streaming", | ||
"private": true, | ||
"license": "MIT", | ||
"scripts": { | ||
"dev": "next dev", | ||
"build": "next build", | ||
"start": "next start" | ||
}, | ||
"dependencies": { | ||
"@tanstack/react-query": "^5.0.0-alpha.68", | ||
"@tanstack/react-query-devtools": "^5.0.0-alpha.68", | ||
"@tanstack/react-query-next-experimental": "^5.0.0-alpha.80", | ||
"next": "^13.4.4", | ||
"react": "^18.2.0", | ||
"react-dom": "^18.2.0", | ||
"superjson": "^1.12.3" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "20.2.5", | ||
"@types/react": "18.2.8", | ||
"typescript": "5.1.3" | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
examples/react/nextjs-suspense-streaming/src/app/api/wait/route.ts
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,10 @@ | ||
import { NextResponse } from 'next/server' | ||
|
||
export async function GET(request: Request) { | ||
const { searchParams } = new URL(request.url) | ||
const wait = Number(searchParams.get('wait')) | ||
|
||
await new Promise((resolve) => setTimeout(resolve, wait)) | ||
|
||
return NextResponse.json(`waited ${wait}ms`) | ||
} |
20 changes: 20 additions & 0 deletions
20
examples/react/nextjs-suspense-streaming/src/app/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,20 @@ | ||
import { Providers } from './providers' | ||
|
||
export const metadata = { | ||
title: 'Next.js', | ||
description: 'Generated by Next.js', | ||
} | ||
|
||
export default function RootLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
return ( | ||
<html lang="en"> | ||
<body> | ||
<Providers>{children}</Providers> | ||
</body> | ||
</html> | ||
) | ||
} |
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,89 @@ | ||
'use client' | ||
import { useQuery } from '@tanstack/react-query' | ||
import { Suspense } from 'react' | ||
|
||
// export const runtime = "edge"; // 'nodejs' (default) | 'edge' | ||
|
||
function getBaseURL() { | ||
if (typeof window !== 'undefined') { | ||
return '' | ||
} | ||
if (process.env.VERCEL_URL) { | ||
return `https://${process.env.VERCEL_URL}` | ||
} | ||
return 'http://localhost:3000' | ||
} | ||
const baseUrl = getBaseURL() | ||
function useWaitQuery(props: { wait: number }) { | ||
const query = useQuery({ | ||
queryKey: ['wait', props.wait], | ||
queryFn: async () => { | ||
const path = `/api/wait?wait=${props.wait}` | ||
const url = baseUrl + path | ||
|
||
console.log('fetching', url) | ||
const res: string = await ( | ||
await fetch(url, { | ||
cache: 'no-store', | ||
}) | ||
).json() | ||
return res | ||
}, | ||
suspense: true, | ||
}) | ||
|
||
return [query.data as string, query] as const | ||
} | ||
|
||
function MyComponent(props: { wait: number }) { | ||
const [data] = useWaitQuery(props) | ||
|
||
return <div>result: {data}</div> | ||
} | ||
|
||
export default function MyPage() { | ||
return ( | ||
<> | ||
<Suspense fallback={<div>waiting 100....</div>}> | ||
<MyComponent wait={100} /> | ||
</Suspense> | ||
<Suspense fallback={<div>waiting 200....</div>}> | ||
<MyComponent wait={200} /> | ||
</Suspense> | ||
<Suspense fallback={<div>waiting 300....</div>}> | ||
<MyComponent wait={300} /> | ||
</Suspense> | ||
<Suspense fallback={<div>waiting 400....</div>}> | ||
<MyComponent wait={400} /> | ||
</Suspense> | ||
<Suspense fallback={<div>waiting 500....</div>}> | ||
<MyComponent wait={500} /> | ||
</Suspense> | ||
<Suspense fallback={<div>waiting 600....</div>}> | ||
<MyComponent wait={600} /> | ||
</Suspense> | ||
<Suspense fallback={<div>waiting 700....</div>}> | ||
<MyComponent wait={700} /> | ||
</Suspense> | ||
|
||
<fieldset> | ||
<legend> | ||
combined <code>Suspense</code>-container | ||
</legend> | ||
<Suspense | ||
fallback={ | ||
<> | ||
<div>waiting 800....</div> | ||
<div>waiting 900....</div> | ||
<div>waiting 1000....</div> | ||
</> | ||
} | ||
> | ||
<MyComponent wait={800} /> | ||
<MyComponent wait={900} /> | ||
<MyComponent wait={1000} /> | ||
</Suspense> | ||
</fieldset> | ||
</> | ||
) | ||
} |
29 changes: 29 additions & 0 deletions
29
examples/react/nextjs-suspense-streaming/src/app/providers.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,29 @@ | ||
// app/providers.jsx | ||
'use client' | ||
|
||
import { QueryClient, QueryClientProvider } from '@tanstack/react-query' | ||
import { ReactQueryDevtools } from '@tanstack/react-query-devtools' | ||
import React from 'react' | ||
import { ReactQueryStreamedHydration } from '@tanstack/react-query-next-experimental' | ||
|
||
export function Providers(props: { children: React.ReactNode }) { | ||
const [queryClient] = React.useState( | ||
() => | ||
new QueryClient({ | ||
defaultOptions: { | ||
queries: { | ||
staleTime: 5 * 1000, | ||
}, | ||
}, | ||
}), | ||
) | ||
|
||
return ( | ||
<QueryClientProvider client={queryClient}> | ||
<ReactQueryStreamedHydration> | ||
{props.children} | ||
</ReactQueryStreamedHydration> | ||
<ReactQueryDevtools initialIsOpen={false} /> | ||
</QueryClientProvider> | ||
) | ||
} |
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,25 @@ | ||
{ | ||
"compilerOptions": { | ||
"target": "es5", | ||
"lib": ["dom", "dom.iterable", "esnext"], | ||
"allowJs": true, | ||
"skipLibCheck": true, | ||
"strict": true, | ||
"forceConsistentCasingInFileNames": true, | ||
"noEmit": true, | ||
"esModuleInterop": true, | ||
"module": "esnext", | ||
"moduleResolution": "node", | ||
"resolveJsonModule": true, | ||
"isolatedModules": true, | ||
"jsx": "preserve", | ||
"incremental": true, | ||
"plugins": [ | ||
{ | ||
"name": "next" | ||
} | ||
] | ||
}, | ||
"include": ["next-env.d.ts", "**/*.ts", "**/*.tsx", ".next/types/**/*.ts"], | ||
"exclude": ["node_modules"] | ||
} |
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
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
Oops, something went wrong.