-
Notifications
You must be signed in to change notification settings - Fork 27k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
re-use auto prefetch cache entries for different searchParams
- Loading branch information
Showing
13 changed files
with
316 additions
and
25 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
10 changes: 10 additions & 0 deletions
10
test/e2e/app-dir/searchparams-reuse-loading/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,10 @@ | ||
import { ReactNode, Suspense } from 'react' | ||
export default function Root({ children }: { children: ReactNode }) { | ||
return ( | ||
<html> | ||
<body> | ||
<Suspense>{children}</Suspense> | ||
</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,24 @@ | ||
import Link from 'next/link' | ||
|
||
export default function Page() { | ||
return ( | ||
<> | ||
<Link href="/search">Go to search</Link> | ||
<hr /> | ||
|
||
<ul> | ||
<li> | ||
<Link href="/search-params?id=1">/search-params?id=1</Link> | ||
</li> | ||
<li> | ||
<Link href="/search-params?id=2">/search-params?id=2</Link> | ||
</li> | ||
<li> | ||
<Link href="/search-params?id=3" prefetch> | ||
/search-params?id=3 (prefetch: true) | ||
</Link> | ||
</li> | ||
</ul> | ||
</> | ||
) | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/searchparams-reuse-loading/app/search-params/loading.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,3 @@ | ||
export default function Loading() { | ||
return <h1 id="loading">Loading...</h1> | ||
} |
16 changes: 16 additions & 0 deletions
16
test/e2e/app-dir/searchparams-reuse-loading/app/search-params/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,16 @@ | ||
import Link from 'next/link' | ||
|
||
export default async function Page({ | ||
searchParams, | ||
}: { | ||
searchParams: Record<string, string> | ||
}) { | ||
// sleep for 500ms | ||
await new Promise((resolve) => setTimeout(resolve, 500)) | ||
return ( | ||
<> | ||
<h1 id="params">{JSON.stringify(searchParams)}</h1> | ||
<Link href="/">Back</Link> | ||
</> | ||
) | ||
} |
13 changes: 13 additions & 0 deletions
13
test/e2e/app-dir/searchparams-reuse-loading/app/search/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,13 @@ | ||
'use client' | ||
|
||
import { Fragment } from 'react' | ||
import { useSearchParams } from 'next/navigation' | ||
|
||
export default function SearchLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode | ||
}) { | ||
let searchParams = useSearchParams() | ||
return <Fragment key={searchParams.get('q')}>{children}</Fragment> | ||
} |
3 changes: 3 additions & 0 deletions
3
test/e2e/app-dir/searchparams-reuse-loading/app/search/loading.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,3 @@ | ||
export default function Loading() { | ||
return <p id="loading">Loading...</p> | ||
} |
12 changes: 12 additions & 0 deletions
12
test/e2e/app-dir/searchparams-reuse-loading/app/search/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,12 @@ | ||
import { Search } from './search' | ||
|
||
export default async function Page({ searchParams }: { searchParams: any }) { | ||
await new Promise((resolve) => setTimeout(resolve, 3000)) | ||
|
||
return ( | ||
<main id="page-content"> | ||
<Search /> | ||
<p id="search-value">Search Value: {searchParams.q ?? 'None'}</p> | ||
</main> | ||
) | ||
} |
22 changes: 22 additions & 0 deletions
22
test/e2e/app-dir/searchparams-reuse-loading/app/search/search.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,22 @@ | ||
'use client' | ||
|
||
import { useRouter } from 'next/navigation' | ||
|
||
export function Search() { | ||
let router = useRouter() | ||
|
||
function search(event: React.FormEvent<HTMLFormElement>) { | ||
event.preventDefault() | ||
|
||
let input = event.currentTarget.q.value | ||
let params = new URLSearchParams([['q', input]]) | ||
router.push(`/search?${params}`) | ||
} | ||
|
||
return ( | ||
<form onSubmit={search}> | ||
<input placeholder="Search..." name="q" className="border" /> | ||
<button>Submit</button> | ||
</form> | ||
) | ||
} |
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,6 @@ | ||
/** | ||
* @type {import('next').NextConfig} | ||
*/ | ||
const nextConfig = {} | ||
|
||
module.exports = nextConfig |
Oops, something went wrong.