Releases: vercel/flags
@vercel/[email protected]
Minor Changes
-
76feb16: Add
mergeProviderData
function to@vercel/flags
.This function allows merging ProviderData from multiple sources.
This is handy when you declare feature flags in code, and want to extend those definitions with data loaded from your feature flag provider.
import { verifyAccess, mergeProviderData, type ApiData } from '@vercel/flags'; import { getProviderData } from '@vercel/flags/next'; import { NextResponse, type NextRequest } from 'next/server'; import { getProviderData as getStatsigProviderData } from '@flags-sdk/statsig'; import * as flagsA from '../../../../flags-a'; // your feature flags file(s) import * as flagsB from '../../../../flags-b'; // your feature flags file(s) export async function GET(request: NextRequest) { const access = await verifyAccess(request.headers.get('Authorization')); if (!access) return NextResponse.json(null, { status: 401 }); const providerData = await mergeProviderData([ // expose flags declared in code first getProviderData({ ...flagsA, ...flagsB }), // then enhance them with metadata from your flag provider getStatsigProviderData({ consoleApiKey: '', projectId: '' }), ]); return NextResponse.json<ApiData>(providerData); }
Patch Changes
-
2713ea7: Handle
undefined
values- fix: Fall back to
defaultValue
when a feature flag returnsundefined
- fix: Throw error when a flag resolves to
undefined
and nodefaultValue
is present
The value
undefined
can not be serialized so feature flags should never resolve toundefined
. Usenull
instead.Fix exports
- fix: Export
Identify
andDecide
types
- fix: Fall back to
@vercel/[email protected]
Patch Changes
- 708d5e2: generatePermutations: infer options of boolean flags
@vercel/[email protected]
Patch Changes
- 7e21d4f: add metadata to package.json
@vercel/[email protected]
Major Changes
-
db89f0d: - BREAKING CHANGE removed all
unstable_
prefixes, e.g.unstable_flag
is nowflag
- BREAKING CHANGE removed
getPrecomputationContext
, usededupe
instead (see below) - BREAKING CHANGE moved all provider functions to dedicated packages
@vercel/flags/providers/launchdarkly
→@flags-sdk/launchdarkly
@vercel/flags/providers/statsig
→@flags-sdk/statsig
@vercel/flags/providers/split
→@flags-sdk/split
@vercel/flags/providers/hypertune
→@flags-sdk/hypertune
@vercel/flags/providers/optimizely
→@flags-sdk/optimizely
@vercel/flags/providers/happykit
→@flags-sdk/happykit
- BREAKING CHANGE changed
.run({})
behavior
See flags-sdk.com for the latest APIs.
- BREAKING CHANGE removed
-
db89f0d: remove unstable_ prefixes
Minor Changes
-
db89f0d: @vercel/flags/next: Added a
dedupe
functiondedupe
is a middleware-friendly version ofReact.cache
. It allows ensuring a function only ever runs once per request.import { dedupe } from '@vercel/flags/next'; let i = 0; const runOnce = dedupe(async () => { return i++; }); await runOnce(); // returns 0 await runOnce(); // still returns 0
This function is useful when you want to deduplicate work within each feature flag's
decide
function. For example if multiple flags need to check auth you can dedupe the auth function so it only runs once per request.dedupe
is also useful to optimistically generate a random visitor id to be set in a cookie, while also allowing each feature flag to access the id. You can call a dedupe'd function to generate the random id within your Edge Middleware and also within your feature flag'sdecide
functions. The function will return a consistent id.import { nanoid } from 'nanoid'; import { cookies, headers } from 'next/headers'; import { dedupe } from '@vercel/flags/next'; /** * Reads the visitor id from a cookie or returns a new visitor id */ export const getOrGenerateVisitorId = dedupe( async (): Promise<{ value: string; fresh: boolean }> => { const visitorIdCookie = (await cookies()).get('visitor-id')?.value; return visitorIdCookie ? { value: visitorIdCookie, fresh: false } : { value: nanoid(), fresh: true }; }, );
Note: "once per request" is an imprecise description. A
dedupe
d function actually runs once per request, per compute instance. If a dedupe'd function is used in Edge Middleware and in a React Server Component it will run twice, as there are two separate compute instances handling this request.Note: This function acts as a sort of polyfill until similar functionality lands in Next.js directly.
@flags-sdk/[email protected]
Minor Changes
- 3c66284: initialize
@flags-sdk/[email protected]
Minor Changes
- 3c66284: initialize
@flags-sdk/[email protected]
Minor Changes
- 3c66284: initialize
@flags-sdk/[email protected]
Minor Changes
- 3c66284: initialize
@flags-sdk/[email protected]
Minor Changes
- 3c66284: initialize
@flags-sdk/[email protected]
Minor Changes
- 3c66284: initialize