Skip to content

Commit d1e3847

Browse files
authored
Update LaunchDarkly examples for native Vercel Marketplace integration (#1532)
## Summary Updates the LaunchDarkly examples to use the new native LaunchDarkly Vercel Marketplace integration, alongside the upcoming `@flags-sdk/launchdarkly` v1.0.0 release. The key change is that the Edge Config connection string is now exposed as `EXPERIMENTATION_CONFIG` (renamed from `EDGE_CONFIG`), matching the native Marketplace integration and other experimentation adapters (e.g. Statsig). ### `flags-sdk/launchdarkly` - Bump `@flags-sdk/launchdarkly` `^0.3.2` → `^1.0.0` (v1.0.0 reads `EXPERIMENTATION_CONFIG` by default) - `.env.example`: `EDGE_CONFIG` → `EXPERIMENTATION_CONFIG` - README: Marketplace `products` deploy param + docs on enabling the Edge Config sync from the integration resource - Regenerated `pnpm-lock.yaml` ### `edge-middleware/feature-flag-launchdarkly` - `page.tsx`: read connection string from `EXPERIMENTATION_CONFIG` - Deploy URL: replaced legacy `integration-ids`/`edge-config-stores` params with the Marketplace `products` param - README/link updates for the native Marketplace integration ### Notes - `toolbar/toolbar-launchdarkly` is unaffected (uses `LAUNCHDARKLY_SDK_KEY` directly, no Edge Config). - Edge Config provisioning with the integration is handled by a separate change.
1 parent 18d2f5b commit d1e3847

10 files changed

Lines changed: 172 additions & 117 deletions

File tree

edge-middleware/feature-flag-launchdarkly/README.md

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ description: Learn how to set up the LaunchDarkly integration to read flags from
55
framework: Next.js
66
useCase: Edge Middleware
77
css: Tailwind
8-
deployUrl: https://vercel.com/new/clone?repository-url=https://github.com/vercel/examples/tree/main/edge-middleware/feature-flag-launchdarkly&project-name=feature-flag-launchdarkly&repository-name=feature-flag-launchdarkly&integration-ids=oac_8DFUMlauSkqeQhdGHpL5xbWp&env=NEXT_PUBLIC_LD_CLIENT_SIDE_ID&env=EDGE_CONFIG&edge-config-stores=%7B%22EDGE_CONFIG%22%3A%7B%7D%7D
8+
deployUrl: https://vercel.com/new/clone?repository-url=https://github.com/vercel/examples/tree/main/edge-middleware/feature-flag-launchdarkly&project-name=feature-flag-launchdarkly&repository-name=feature-flag-launchdarkly&products=%5B%7B%22integrationSlug%22%3A%22launchdarkly%22%2C%22productSlug%22%3A%22launchdarkly%22%2C%22type%22%3A%22integration%22%2C%22protocol%22%3A%22experimentation%22%7D%5D
99
demoUrl: https://feature-flag-launchdarkly.vercel.app
1010
relatedTemplates:
1111
- maintenance-page
@@ -14,13 +14,21 @@ relatedTemplates:
1414

1515
# feature-flag-launchdarkly example
1616

17-
This example shows how to use the [LaunchDarkly integration](https://vercel.com/integrations/launchdarkly) with Next.js.
17+
This example shows how to use the native [LaunchDarkly integration](https://vercel.com/marketplace/launchdarkly) from the Vercel Marketplace with Next.js.
1818

19-
> ℹ️ The LaunchDarkly integration requires a LaunchDarkly enterprise account.
19+
The integration provides the `NEXT_PUBLIC_LAUNCHDARKLY_CLIENT_SIDE_ID` environment variable, which contains your client-side ID from LaunchDarkly.
2020

21-
You will need to provide the `NEXT_PUBLIC_LD_CLIENT_SIDE_ID` environment variable. Fill it with your client-side ID from LaunchDarkly.
21+
LaunchDarkly syncs your feature flags into an Edge Config. When installing the LaunchDarkly integration from the Vercel Marketplace, turn on the **Enable Edge Config Syncing** toggle in the "Configuration and Plan" step of the install process. This provisions an Edge Config and exposes its connection string as the `EXPERIMENTATION_CONFIG` environment variable, which this example reads to create the Edge Config client.
2222

23-
LaunchDarkly wills sync your feature flags into an Edge Config, which you can set in the integration. Note that the same Edge Config also needs to be linked to this project via the `EDGE_CONFIG` environment variable. If you clone this template, this will be set up for you automatically when you select the Edge Config.
23+
## Set up the feature flag
24+
25+
Head over to the [LaunchDarkly Console](https://app.launchdarkly.com) and create the feature flag used by this example, in the same project and environment your client-side ID belongs to:
26+
27+
- `My Flag` (type boolean) with the key `my-flag` and the variations `true` and `false`
28+
29+
Turn the flag ON. Toggling targeting on and off changes what the page shows, confirming flags are being read from Edge Config.
30+
31+
The example evaluates the flag against a context of kind `org` with the key `my-org-key` (see `app/page.tsx`). Contexts do not need to be created in LaunchDarkly ahead of time — they are simply sent by the app at evaluation time. The default targeting rule works without any extra setup. If you want to add targeting rules, target the `org` context kind rather than `user`.
2432

2533
## Demo
2634

@@ -34,7 +42,7 @@ You can choose from one of the following two methods to use this repository:
3442

3543
Deploy the example using [Vercel](https://vercel.com?utm_source=github&utm_medium=readme&utm_campaign=vercel-examples):
3644

37-
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/vercel/examples/tree/main/edge-middleware/feature-flag-launchdarkly&project-name=feature-flag-launchdarkly&repository-name=feature-flag-launchdarkly&integration-ids=oac_8DFUMlauSkqeQhdGHpL5xbWp&env=NEXT_PUBLIC_LD_CLIENT_SIDE_ID&env=EDGE_CONFIG&edge-config-stores=%7B%22EDGE_CONFIG%22%3A%7B%7D%7D)
45+
[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https://github.com/vercel/examples/tree/main/edge-middleware/feature-flag-launchdarkly&project-name=feature-flag-launchdarkly&repository-name=feature-flag-launchdarkly&products=%5B%7B%22integrationSlug%22%3A%22launchdarkly%22%2C%22productSlug%22%3A%22launchdarkly%22%2C%22type%22%3A%22integration%22%2C%22protocol%22%3A%22experimentation%22%7D%5D)
3846

3947
### Clone and Deploy
4048

edge-middleware/feature-flag-launchdarkly/app/layout.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function RootLayout({ children }: { children: ReactNode }) {
1616
path="edge-middleware/feature-flag-launchdarkly"
1717
deployButton={{
1818
customDeployUrl:
19-
'https://vercel.com/new/clone?repository-url=https://github.com/vercel/examples/tree/main/edge-middleware/feature-flag-launchdarkly&project-name=feature-flag-launchdarkly&repository-name=feature-flag-launchdarkly&integration-ids=oac_8DFUMlauSkqeQhdGHpL5xbWp&env=NEXT_PUBLIC_LD_CLIENT_SIDE_ID&env=EDGE_CONFIG&edge-config-stores=%7B%22EDGE_CONFIG%22%3A%7B%7D%7D',
19+
'https://vercel.com/new/clone?repository-url=https://github.com/vercel/examples/tree/main/edge-middleware/feature-flag-launchdarkly&project-name=feature-flag-launchdarkly&repository-name=feature-flag-launchdarkly&products=%5B%7B%22integrationSlug%22%3A%22launchdarkly%22%2C%22productSlug%22%3A%22launchdarkly%22%2C%22type%22%3A%22integration%22%2C%22protocol%22%3A%22experimentation%22%7D%5D',
2020
}}
2121
>
2222
{children}

edge-middleware/feature-flag-launchdarkly/app/page.tsx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ export const metadata = {
1010
}
1111
export const runtime = 'edge'
1212

13-
const edgeConfigClient = createClient(process.env.EDGE_CONFIG)
13+
export const dynamic = 'force-dynamic'
1414

1515
// In Edge Runtime it's not possible to share promises across requests.
1616
//
@@ -34,8 +34,9 @@ const edgeConfigClient = createClient(process.env.EDGE_CONFIG)
3434
// - "cache" does not work in Edge Middleware, so you'd need to create a fresh
3535
// instance of the LaunchDarkly client for every request.
3636
const getLdClient = cache(async (): Promise<LDClient> => {
37+
const edgeConfigClient = createClient(process.env.EXPERIMENTATION_CONFIG)
3738
const ldClient = init(
38-
process.env.NEXT_PUBLIC_LD_CLIENT_SIDE_ID!,
39+
process.env.NEXT_PUBLIC_LAUNCHDARKLY_CLIENT_SIDE_ID!,
3940
edgeConfigClient
4041
)
4142
await ldClient.waitForInitialization()
@@ -62,7 +63,7 @@ export default async function Home() {
6263
<Text>
6364
This example shows how to use the{' '}
6465
<Link
65-
href="https://vercel.com/integrations/launchdarkly"
66+
href="https://vercel.com/marketplace/launchdarkly"
6667
target="_blank"
6768
>
6869
LaunchDarkly integration

edge-middleware/feature-flag-launchdarkly/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
"dependencies": {
1313
"@launchdarkly/vercel-server-sdk": "^1.3.3",
1414
"@vercel/edge-config": "^1.1.0",
15-
"@vercel/examples-ui": "^2.0.3",
16-
"next": "^16.0.10",
15+
"@vercel/examples-ui": "^2.0.4",
16+
"next": "^16.2.0",
1717
"react": "^19.2.1",
1818
"react-dom": "^19.2.1"
1919
},
@@ -25,7 +25,7 @@
2525
"eslint-config-next": "^13.4.19",
2626
"postcss": "^8.4.28",
2727
"tailwindcss": "^3.3.3",
28-
"turbo": "^1.10.12",
28+
"turbo": "1.13.4",
2929
"typescript": "^5"
3030
}
3131
}

0 commit comments

Comments
 (0)