-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* upgrade next * ensure pages router support in turbopack * add pages router examples * fix cards * re-add node prefix * remove node prefix * fix tests * fix pages router pages
- Loading branch information
Showing
16 changed files
with
598 additions
and
307 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import localFont from 'next/font/local'; | ||
import '../app/globals.css'; | ||
import { VercelToolbar } from '@vercel/toolbar/next'; | ||
|
||
const geistSans = localFont({ | ||
src: '../app/fonts/GeistVF.woff', | ||
variable: '--font-geist-sans', | ||
weight: '100 900', | ||
}); | ||
|
||
const geistMono = localFont({ | ||
src: '../app/fonts/GeistMonoVF.woff', | ||
variable: '--font-geist-mono', | ||
weight: '100 900', | ||
}); | ||
|
||
export default function PagesLayout({ | ||
children, | ||
}: { | ||
children: React.ReactNode; | ||
}) { | ||
const shouldInjectToolbar = process.env.NODE_ENV === 'development'; | ||
return ( | ||
<div | ||
className={`${geistSans.variable} ${geistMono.variable} antialiased prose px-4 m-0`} | ||
> | ||
{children} | ||
{shouldInjectToolbar && <VercelToolbar />} | ||
</div> | ||
); | ||
} |
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 @@ | ||
This folder contains supporting files for the Pages Router example, as those files can not live within the `pages/` folder as they would otherwise count as actualy Next.js 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,11 @@ | ||
import { flag } from '@vercel/flags/next'; | ||
|
||
export const exampleFlag = flag({ | ||
key: 'pages-router-precomputed-example-flag', | ||
decide() { | ||
return true; | ||
}, | ||
options: [false, true], | ||
}); | ||
|
||
export const exampleFlags = [exampleFlag]; |
12 changes: 12 additions & 0 deletions
12
examples/snippets/lib/pages-router-precomputed/middleware.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,12 @@ | ||
import { precompute } from '@vercel/flags/next'; | ||
import { type NextRequest, NextResponse } from 'next/server'; | ||
import { exampleFlags } from './flags'; | ||
|
||
export async function pagesRouterMiddleware(request: NextRequest) { | ||
// precompute the flags | ||
const code = await precompute(exampleFlags); | ||
|
||
return NextResponse.rewrite( | ||
new URL(`/examples/pages-router-precomputed/${code}`, request.url), | ||
); | ||
} |
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
19 changes: 19 additions & 0 deletions
19
examples/snippets/pages/examples/pages-router-dynamic/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,19 @@ | ||
import PagesLayout from '@/components/pages-layout'; | ||
import type { GetServerSideProps, InferGetServerSidePropsType } from 'next'; | ||
import { exampleFlag } from '@/flags'; | ||
import { DemoFlag } from '@/components/demo-flag'; | ||
|
||
export const getServerSideProps = (async ({ req }) => { | ||
const example = await exampleFlag(req); | ||
return { props: { example } }; | ||
}) satisfies GetServerSideProps<{ example: boolean }>; | ||
|
||
export default function PageRouter({ | ||
example, | ||
}: InferGetServerSidePropsType<typeof getServerSideProps>) { | ||
return ( | ||
<PagesLayout> | ||
<DemoFlag name="example-flag" value={example} /> | ||
</PagesLayout> | ||
); | ||
} |
38 changes: 38 additions & 0 deletions
38
examples/snippets/pages/examples/pages-router-precomputed/[code]/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,38 @@ | ||
import PagesLayout from '@/components/pages-layout'; | ||
import type { | ||
GetStaticPaths, | ||
GetStaticProps, | ||
InferGetStaticPropsType, | ||
} from 'next'; | ||
import { | ||
exampleFlag, | ||
exampleFlags, | ||
} from '@/lib/pages-router-precomputed/flags'; | ||
import { DemoFlag } from '@/components/demo-flag'; | ||
import { generatePermutations } from '@vercel/flags/next'; | ||
|
||
export const getStaticPaths = (async () => { | ||
const codes = await generatePermutations(exampleFlags); | ||
|
||
return { | ||
paths: codes.map((code) => ({ params: { code } })), | ||
fallback: 'blocking', | ||
}; | ||
}) satisfies GetStaticPaths; | ||
|
||
export const getStaticProps = (async (context) => { | ||
if (typeof context.params?.code !== 'string') return { notFound: true }; | ||
|
||
const example = await exampleFlag(context.params.code, exampleFlags); | ||
return { props: { example } }; | ||
}) satisfies GetStaticProps<{ example: boolean }>; | ||
|
||
export default function PageRouter({ | ||
example, | ||
}: InferGetStaticPropsType<typeof getStaticProps>) { | ||
return ( | ||
<PagesLayout> | ||
<DemoFlag name="example-flag" value={example} /> | ||
</PagesLayout> | ||
); | ||
} |
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.