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
24 changed files
with
630 additions
and
14 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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 @@ | ||
import { testLoader } from 'e2e-shared/specs/loader.cy' | ||
|
||
// In page components: | ||
|
||
testLoader({ path: '/app/loader', nextJsRouter: 'app' }) | ||
|
||
testLoader({ path: '/pages/loader', nextJsRouter: 'pages' }) | ||
|
||
// In API routes: | ||
|
||
testLoader({ path: '/api/app/loader', nextJsRouter: 'app' }) | ||
|
||
testLoader({ path: '/api/pages/loader', 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
import { loadSearchParams } from 'e2e-shared/specs/loader' | ||
import { NextResponse } from 'next/server' | ||
|
||
// Needed for Next.js 14.2.0 to 14.2.3 | ||
// (due to https://github.com/vercel/next.js/pull/66446) | ||
export const dynamic = 'force-dynamic' | ||
|
||
export async function GET(request: Request) { | ||
const { test, int } = loadSearchParams(request) | ||
return new NextResponse( | ||
`<!doctype html> | ||
<html> | ||
<body> | ||
<div id="hydration-marker" style="display:none;" aria-hidden>hydrated</div> | ||
<pre id="test">${test}</pre> | ||
<pre id="int">${int}</pre> | ||
</body> | ||
</html>`, | ||
{ | ||
headers: { | ||
'content-type': 'text/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,11 @@ | ||
import { LoaderRenderer, loadSearchParams } from 'e2e-shared/specs/loader' | ||
import type { SearchParams } from 'nuqs/server' | ||
|
||
type PageProps = { | ||
searchParams: Promise<SearchParams> | ||
} | ||
|
||
export default async function Page({ searchParams }: PageProps) { | ||
const serverValues = await loadSearchParams(searchParams) | ||
return <LoaderRenderer serverValues={serverValues} /> | ||
} |
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,22 @@ | ||
import { loadSearchParams } from 'e2e-shared/specs/loader' | ||
import type { NextApiRequest, NextApiResponse } from 'next' | ||
|
||
export default function handler( | ||
request: NextApiRequest, | ||
response: NextApiResponse | ||
) { | ||
const { test, int } = loadSearchParams(request.query) | ||
response | ||
.status(200) | ||
.setHeader('content-type', 'text/html') | ||
.send( | ||
`<!doctype html> | ||
<html> | ||
<body> | ||
<div id="hydration-marker" style="display:none;" aria-hidden>hydrated</div> | ||
<pre id="test">${test}</pre> | ||
<pre id="int">${int}</pre> | ||
</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,22 @@ | ||
import { | ||
type SearchParams, | ||
LoaderRenderer, | ||
loadSearchParams | ||
} from 'e2e-shared/specs/loader' | ||
import type { GetServerSidePropsContext } from 'next' | ||
|
||
type PageProps = { | ||
serverValues: SearchParams | ||
} | ||
|
||
export default function Page({ serverValues }: PageProps) { | ||
return <LoaderRenderer serverValues={serverValues} /> | ||
} | ||
|
||
export async function getServerSideProps({ query }: GetServerSidePropsContext) { | ||
return { | ||
props: { | ||
serverValues: loadSearchParams(query) | ||
} | ||
} | ||
} |
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 @@ | ||
import { testLoader } from 'e2e-shared/specs/loader.cy' | ||
|
||
testLoader({ path: '/loader' }) |
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 @@ | ||
import { LoaderRenderer, loadSearchParams } from 'e2e-shared/specs/loader' | ||
import { useLoaderData, type LoaderFunctionArgs } from 'react-router-dom' | ||
|
||
export function loader({ request }: LoaderFunctionArgs) { | ||
return loadSearchParams(request) | ||
} | ||
|
||
export default function Page() { | ||
const serverValues = useLoaderData() as Awaited<ReturnType<typeof loader>> | ||
return <LoaderRenderer serverValues={serverValues} /> | ||
} |
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,13 @@ | ||
import { LoaderRenderer, loadSearchParams } from 'e2e-shared/specs/loader' | ||
import type { LoaderFunctionArgs } from 'react-router' | ||
import type { Route } from './+types/loader' | ||
|
||
export function loader({ request }: LoaderFunctionArgs) { | ||
return loadSearchParams(request) | ||
} | ||
|
||
export default function Page({ | ||
loaderData: serverValues | ||
}: Route.ComponentProps) { | ||
return <LoaderRenderer serverValues={serverValues} /> | ||
} |
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 @@ | ||
import { testLoader } from 'e2e-shared/specs/loader.cy' | ||
|
||
testLoader({ path: '/loader' }) |
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 type { LoaderFunctionArgs } from '@remix-run/node' | ||
import { useLoaderData } from '@remix-run/react' | ||
import { LoaderRenderer, loadSearchParams } from 'e2e-shared/specs/loader' | ||
|
||
export function loader({ request }: LoaderFunctionArgs) { | ||
return loadSearchParams(request) | ||
} | ||
|
||
export default function Page() { | ||
const serverValues = useLoaderData<typeof loader>() | ||
return <LoaderRenderer serverValues={serverValues} /> | ||
} |
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 @@ | ||
import { testLoader } from 'e2e-shared/specs/loader.cy' | ||
|
||
testLoader({ path: '/loader' }) |
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 { createTest } from '../create-test' | ||
|
||
export const testLoader = createTest('Loader', ({ path }) => { | ||
it('loads state from the URL', () => { | ||
cy.visit(path + '?test=pass&int=42') | ||
cy.contains('#hydration-marker', 'hydrated').should('be.hidden') | ||
cy.get('#test').should('have.text', 'pass') | ||
cy.get('#int').should('have.text', '42') | ||
}) | ||
}) |
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,27 @@ | ||
import { | ||
createLoader, | ||
type inferParserType, | ||
parseAsInteger, | ||
parseAsString | ||
} from 'nuqs/server' | ||
|
||
const searchParams = { | ||
test: parseAsString, | ||
int: parseAsInteger | ||
} | ||
|
||
export type SearchParams = inferParserType<typeof searchParams> | ||
export const loadSearchParams = createLoader(searchParams) | ||
|
||
type LoaderRendererProps = { | ||
serverValues: inferParserType<typeof searchParams> | ||
} | ||
|
||
export function LoaderRenderer({ serverValues }: LoaderRendererProps) { | ||
return ( | ||
<> | ||
<pre id="test">{serverValues.test}</pre> | ||
<pre id="int">{serverValues.int}</pre> | ||
</> | ||
) | ||
} |
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.