-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Update Hypertune example to use the new Feature Flags pattern (#924)
Update Hypertune example to use the new Feature Flags pattern --------- Co-authored-by: Michal Bock <[email protected]>
- Loading branch information
1 parent
fdb4f5f
commit c1f0e04
Showing
26 changed files
with
2,883 additions
and
1,995 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,4 @@ | ||
HYPERTUNE_FRAMEWORK=nextApp | ||
HYPERTUNE_PLATFORM=vercel | ||
HYPERTUNE_OUTPUT_DIRECTORY_PATH=generated | ||
HYPERTUNE_GET_HYPERTUNE_IMPORT_PATH=../lib/getHypertune |
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 |
---|---|---|
@@ -1,32 +1,37 @@ | ||
import type { ReactNode } from 'react' | ||
import { Layout, getMetadata } from '@vercel/examples-ui' | ||
import { VercelToolbar } from '@vercel/toolbar/next' | ||
import { HypertuneSourceProvider } from '../generated/hypertune.react' | ||
import '@vercel/examples-ui/globals.css' | ||
|
||
export const metadata = getMetadata({ | ||
title: 'feature-flag-hypertune', | ||
description: 'An example showing how to use Vercel with Hypertune', | ||
description: 'An example showing how to use Hypertune with Vercel.', | ||
}) | ||
|
||
export const runtime = 'edge' | ||
|
||
export default function RootLayout({ | ||
export default async function RootLayout({ | ||
children, | ||
}: Readonly<{ children: ReactNode }>) { | ||
return ( | ||
<html lang="en"> | ||
<body> | ||
<Layout | ||
path="edge-middleware/feature-flag-hypertune" | ||
deployButton={{ | ||
customDeployUrl: | ||
'https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fhypertunehq%2Fvercel-examples-fork%2Ftree%2Fmain%2Fedge-middleware%2Ffeature-flag-hypertune&env=NEXT_PUBLIC_HYPERTUNE_TOKEN,HYPERTUNE_ADMIN_TOKEN,EDGE_CONFIG,EDGE_CONFIG_HYPERTUNE_ITEM_KEY,FLAGS_SECRET&envDescription=Environment%20variables%20needed%20to%20use%20Hypertune%20with%20Vercel%20Edge%20Config%20and%20the%20Vercel%20Toolbar&envLink=https%3A%2F%2Fdocs.hypertune.com%2Fgetting-started%2Fvercel-quickstart&project-name=feature-flag-hypertune&repository-name=feature-flag-hypertune&demo-title=Hypertune%20with%20Vercel&demo-description=Use%20Hypertune%20with%20Vercel%20Edge%20Config%20and%20the%20Vercel%20Toolbar&demo-url=https%3A%2F%2Ffeature-flag-hypertune.vercel.app%2F&demo-image=https%3A%2F%2Ffeature-flag-hypertune.vercel.app%2Fdemo.png&integration-ids=oac_naLXREDG2o9KihTGYBVz9fVl', | ||
}} | ||
> | ||
{children} | ||
<VercelToolbar /> | ||
</Layout> | ||
</body> | ||
</html> | ||
<HypertuneSourceProvider | ||
createSourceOptions={{ token: process.env.NEXT_PUBLIC_HYPERTUNE_TOKEN! }} | ||
> | ||
<html lang="en"> | ||
<body> | ||
<Layout | ||
path="edge-middleware/feature-flag-hypertune" | ||
deployButton={{ | ||
customDeployUrl: | ||
'https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Fhypertunehq%2Fvercel-examples-fork%2Ftree%2Fmain%2Fedge-middleware%2Ffeature-flag-hypertune&env=NEXT_PUBLIC_HYPERTUNE_TOKEN,HYPERTUNE_ADMIN_TOKEN,EDGE_CONFIG,EDGE_CONFIG_HYPERTUNE_ITEM_KEY,FLAGS_SECRET&envDescription=Environment%20variables%20needed%20to%20use%20Hypertune%20with%20Vercel%20Edge%20Config%20and%20the%20Vercel%20Toolbar&envLink=https%3A%2F%2Fdocs.hypertune.com%2Fgetting-started%2Fvercel-quickstart&project-name=feature-flag-hypertune&repository-name=feature-flag-hypertune&demo-title=Hypertune%20with%20Vercel&demo-description=Use%20Hypertune%20with%20Vercel%20Edge%20Config%20and%20the%20Vercel%20Toolbar&demo-url=https%3A%2F%2Ffeature-flag-hypertune.vercel.app%2F&demo-image=https%3A%2F%2Ffeature-flag-hypertune.vercel.app%2Fdemo.png&integration-ids=oac_naLXREDG2o9KihTGYBVz9fVl', | ||
}} | ||
> | ||
{children} | ||
<VercelToolbar /> | ||
</Layout> | ||
</body> | ||
</html> | ||
</HypertuneSourceProvider> | ||
) | ||
} |
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
15 changes: 15 additions & 0 deletions
15
edge-middleware/feature-flag-hypertune/app/static/[code]/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,15 @@ | ||
import { unstable_generatePermutations as generatePermutations } from '@vercel/flags/next' | ||
import { exampleFlagFlag } from '../../../generated/hypertune.vercel' | ||
import precomputeFlags from '../../../lib/precomputeFlags' | ||
|
||
export async function generateStaticParams() { | ||
const codes = await generatePermutations(precomputeFlags) | ||
return codes.map((code) => ({ code })) | ||
} | ||
|
||
export default async function Page({ params }: { params: { code: string } }) { | ||
// access the precomputed result by passing params.code and precomputeFlags | ||
const exampleFlag = await exampleFlagFlag(params.code, precomputeFlags) | ||
|
||
return <div>Example Flag: {String(exampleFlag)}</div> | ||
} |
16 changes: 16 additions & 0 deletions
16
edge-middleware/feature-flag-hypertune/components/ClientComponent.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 @@ | ||
'use client' | ||
|
||
import { Text } from '@vercel/examples-ui' | ||
import { useHypertune } from '../generated/hypertune.react' | ||
|
||
export default function ClientComponent(): React.ReactElement { | ||
const hypertune = useHypertune() | ||
|
||
const exampleFlag = hypertune.exampleFlag({ fallback: false }) | ||
|
||
return ( | ||
<Text> | ||
(Client Component) Example Flag: <strong>{String(exampleFlag)}</strong> | ||
</Text> | ||
) | ||
} |
28 changes: 28 additions & 0 deletions
28
edge-middleware/feature-flag-hypertune/components/ClientComponentWrapper.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,28 @@ | ||
import { merge } from 'hypertune' | ||
import { | ||
HypertuneHydrator, | ||
HypertuneRootProvider, | ||
} from '../generated/hypertune.react' | ||
import getHypertune from '../lib/getHypertune' | ||
import ClientComponent from './ClientComponent' | ||
|
||
export default async function ClientComponentWrapper() { | ||
const hypertune = await getHypertune() | ||
|
||
const serverRootArgs = hypertune.getRootArgs() | ||
const serverDehydratedState = hypertune.dehydrate() | ||
|
||
return ( | ||
<HypertuneRootProvider | ||
rootArgs={merge( | ||
serverRootArgs | ||
// Set real values for browser-only args, e.g. | ||
// { context: { browserOnlyId: "1" } }, | ||
)} | ||
> | ||
<HypertuneHydrator dehydratedState={serverDehydratedState}> | ||
<ClientComponent /> | ||
</HypertuneHydrator> | ||
</HypertuneRootProvider> | ||
) | ||
} |
22 changes: 22 additions & 0 deletions
22
edge-middleware/feature-flag-hypertune/components/ServerComponent.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 { Suspense } from 'react' | ||
import { Text } from '@vercel/examples-ui' | ||
import { VercelFlagValues } from '../generated/hypertune.vercel' | ||
import getHypertune from '../lib/getHypertune' | ||
|
||
export default async function ServerComponent() { | ||
const hypertune = await getHypertune() | ||
|
||
const exampleFlag = hypertune.exampleFlag({ fallback: false }) | ||
|
||
return ( | ||
<> | ||
<Text> | ||
(Server Component) Example Flag: <strong>{String(exampleFlag)}</strong> | ||
</Text> | ||
|
||
<Suspense fallback={null}> | ||
<VercelFlagValues flagValues={hypertune.get()} /> | ||
</Suspense> | ||
</> | ||
) | ||
} |
Oops, something went wrong.