generated from chiffre-io/template-library
-
-
Notifications
You must be signed in to change notification settings - Fork 135
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
30 changed files
with
779 additions
and
42 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
import { testRenderCount } from 'e2e-shared/specs/render-count.cy' | ||
|
||
const hooks = ['useQueryState', 'useQueryStates'] as const | ||
const shallows = [true, false] as const | ||
const histories = ['replace', 'push'] as const | ||
|
||
for (const hook of hooks) { | ||
for (const shallow of shallows) { | ||
for (const history of histories) { | ||
for (const startTransition of [false, true]) { | ||
for (const delay of shallow === false ? [0, 50] : [0]) { | ||
testRenderCount({ | ||
path: `/app/render-count/${hook}/${shallow}/${history}/${startTransition}?delay=${delay}`, | ||
hook, | ||
props: { | ||
shallow, | ||
history, | ||
startTransition, | ||
delay | ||
}, | ||
expected: { | ||
mount: 1, | ||
update: shallow === false ? 3 : 2 | ||
}, | ||
nextJsRouter: 'app' | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
for (const hook of hooks) { | ||
for (const shallow of shallows) { | ||
for (const history of histories) { | ||
for (const startTransition of [false, true]) { | ||
for (const delay of shallow === false ? [0, 50] : [0]) { | ||
testRenderCount({ | ||
path: `/pages/render-count/${hook}/${shallow}/${history}/${startTransition}?delay=${delay}`, | ||
hook, | ||
props: { | ||
shallow, | ||
history, | ||
startTransition, | ||
delay | ||
}, | ||
expected: { | ||
mount: 1, | ||
update: 2 | ||
}, | ||
nextJsRouter: 'pages' | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
} |
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
47 changes: 47 additions & 0 deletions
47
...t/src/app/app/(shared)/render-count/[hook]/[shallow]/[history]/[startTransition]/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,47 @@ | ||
import { RenderCount } from 'e2e-shared/specs/render-count' | ||
import { | ||
loadParams, | ||
loadSearchParams | ||
} from 'e2e-shared/specs/render-count.params' | ||
import { setTimeout } from 'node:timers/promises' | ||
import { type SearchParams } from 'nuqs/server' | ||
import { Suspense } from 'react' | ||
|
||
export const dynamic = 'force-dynamic' | ||
|
||
type PageProps = { | ||
params: Promise<Record<keyof ReturnType<typeof loadParams>, string>> | ||
searchParams: Promise<SearchParams> | ||
} | ||
|
||
export default async function Page({ | ||
params, | ||
searchParams | ||
}: PageProps & { searchParams: Promise<SearchParams> }) { | ||
const { hook, shallow, history, startTransition } = await loadParams(params) | ||
const { delay } = await loadSearchParams(searchParams) | ||
if (delay) { | ||
await setTimeout(delay) | ||
} | ||
return ( | ||
<Suspense> | ||
<RenderCount | ||
hook={hook} | ||
shallow={shallow} | ||
history={history} | ||
startTransition={startTransition} | ||
/> | ||
</Suspense> | ||
) | ||
} | ||
|
||
export async function generateStaticParams() { | ||
const hooks = ['useQueryState', 'useQueryStates'] | ||
const shallow = [true, false] | ||
const history = ['push', 'replace'] | ||
return hooks.flatMap(hook => | ||
shallow.flatMap(shallow => | ||
history.map(history => ({ hook, shallow: shallow.toString(), history })) | ||
) | ||
) | ||
} |
25 changes: 25 additions & 0 deletions
25
.../next/src/pages/pages/render-count/[hook]/[shallow]/[history]/[startTransition]/index.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,25 @@ | ||
import { RenderCount } from 'e2e-shared/specs/render-count' | ||
import { | ||
loadParams, | ||
loadSearchParams, | ||
type Params | ||
} from 'e2e-shared/specs/render-count.params' | ||
import { GetServerSideProps } from 'next' | ||
import { setTimeout } from 'node:timers/promises' | ||
|
||
export default RenderCount | ||
|
||
// We need SSR to get the correct initial render counts | ||
// otherwise with SSG we get at least one extra render for hydration. | ||
export const getServerSideProps: GetServerSideProps<Params> = async ({ | ||
params, | ||
query | ||
}) => { | ||
const { delay } = loadSearchParams(query) | ||
if (delay) { | ||
await setTimeout(delay) | ||
} | ||
return { | ||
props: loadParams(params!) | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
packages/e2e/react-router/v6/cypress/e2e/shared/render-count.cy.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,80 @@ | ||
import { testRenderCount } from 'e2e-shared/specs/render-count.cy' | ||
|
||
const hooks = ['useQueryState', 'useQueryStates'] as const | ||
const shallows = [true, false] as const | ||
const histories = ['replace', 'push'] as const | ||
|
||
for (const hook of hooks) { | ||
for (const shallow of shallows) { | ||
for (const history of histories) { | ||
for (const startTransition of [false, true]) { | ||
testRenderCount({ | ||
path: `/render-count/${hook}/${shallow}/${history}/${startTransition}/no-loader`, | ||
description: 'no loader', | ||
hook, | ||
props: { | ||
shallow, | ||
history, | ||
startTransition | ||
}, | ||
expected: { | ||
mount: 1, | ||
update: 2 + (shallow === false ? (startTransition ? 0 : 1) : 0) | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
|
||
for (const hook of hooks) { | ||
for (const shallow of shallows) { | ||
for (const history of histories) { | ||
for (const startTransition of [false, true]) { | ||
testRenderCount({ | ||
path: `/render-count/${hook}/${shallow}/${history}/${startTransition}/sync-loader`, | ||
description: 'sync loader', | ||
hook, | ||
props: { | ||
shallow, | ||
history, | ||
startTransition | ||
}, | ||
expected: { | ||
mount: 1, | ||
update: 2 + (shallow === false ? 1 : 0) | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
|
||
for (const hook of hooks) { | ||
for (const shallow of shallows) { | ||
for (const history of histories) { | ||
for (const startTransition of [false, true]) { | ||
for (const delay of shallow === false ? [0, 50] : [0]) { | ||
testRenderCount({ | ||
path: `/render-count/${hook}/${shallow}/${history}/${startTransition}/async-loader?delay=${delay}`, | ||
description: 'async loader', | ||
hook, | ||
props: { | ||
shallow, | ||
history, | ||
startTransition, | ||
delay | ||
}, | ||
expected: { | ||
mount: 1, | ||
update: | ||
2 + | ||
(shallow === false ? 1 : 0) + | ||
(!startTransition && delay ? 1 : 0) | ||
} | ||
}) | ||
} | ||
} | ||
} | ||
} | ||
} |
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
22 changes: 22 additions & 0 deletions
22
...uter/v6/src/routes/render-count.$hook.$shallow.$history.$startTransition.async-loader.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 @@ | ||
import { RenderCount } from 'e2e-shared/specs/render-count' | ||
import { | ||
loadParams, | ||
loadSearchParams | ||
} from 'e2e-shared/specs/render-count.params' | ||
|
||
import { useParams, type LoaderFunctionArgs } from 'react-router-dom' | ||
|
||
const wait = (ms: number) => new Promise(resolve => setTimeout(resolve, ms)) | ||
|
||
export async function loader({ request }: LoaderFunctionArgs) { | ||
const { delay } = loadSearchParams(request) | ||
if (delay) { | ||
await wait(delay) | ||
} | ||
return null | ||
} | ||
|
||
export default function Page() { | ||
const params = loadParams(useParams()) | ||
return <RenderCount {...params} /> | ||
} |
8 changes: 8 additions & 0 deletions
8
...-router/v6/src/routes/render-count.$hook.$shallow.$history.$startTransition.no-loader.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,8 @@ | ||
import { RenderCount } from 'e2e-shared/specs/render-count' | ||
import { loadParams } from 'e2e-shared/specs/render-count.params' | ||
import { useParams } from 'react-router-dom' | ||
|
||
export default function Page() { | ||
const params = loadParams(useParams()) | ||
return <RenderCount {...params} /> | ||
} |
12 changes: 12 additions & 0 deletions
12
...outer/v6/src/routes/render-count.$hook.$shallow.$history.$startTransition.sync-loader.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 { RenderCount } from 'e2e-shared/specs/render-count' | ||
import { loadParams } from 'e2e-shared/specs/render-count.params' | ||
import { useParams } from 'react-router-dom' | ||
|
||
export function loader() { | ||
return null | ||
} | ||
|
||
export default function Page() { | ||
const params = loadParams(useParams()) | ||
return <RenderCount {...params} /> | ||
} |
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
20 changes: 20 additions & 0 deletions
20
...uter/v7/app/routes/render-count.$hook.$shallow.$history.$startTransition.async-loader.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 { RenderCount } from 'e2e-shared/specs/render-count' | ||
import { | ||
loadParams, | ||
loadSearchParams | ||
} from 'e2e-shared/specs/render-count.params' | ||
import { setTimeout } from 'node:timers/promises' | ||
import { useParams, type LoaderFunctionArgs } from 'react-router' | ||
|
||
export async function loader({ request }: LoaderFunctionArgs) { | ||
const { delay } = loadSearchParams(request) | ||
if (delay) { | ||
await setTimeout(delay) | ||
} | ||
return null | ||
} | ||
|
||
export default function Page() { | ||
const params = loadParams(useParams()) | ||
return <RenderCount {...params} /> | ||
} |
8 changes: 8 additions & 0 deletions
8
...-router/v7/app/routes/render-count.$hook.$shallow.$history.$startTransition.no-loader.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,8 @@ | ||
import { RenderCount } from 'e2e-shared/specs/render-count' | ||
import { loadParams } from 'e2e-shared/specs/render-count.params' | ||
import { useParams } from 'react-router' | ||
|
||
export default function Page() { | ||
const params = loadParams(useParams()) | ||
return <RenderCount {...params} /> | ||
} |
12 changes: 12 additions & 0 deletions
12
...outer/v7/app/routes/render-count.$hook.$shallow.$history.$startTransition.sync-loader.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 { RenderCount } from 'e2e-shared/specs/render-count' | ||
import { loadParams } from 'e2e-shared/specs/render-count.params' | ||
import { useParams } from 'react-router' | ||
|
||
export function loader() { | ||
return null | ||
} | ||
|
||
export default function Page() { | ||
const params = loadParams(useParams()) | ||
return <RenderCount {...params} /> | ||
} |
Oops, something went wrong.