Migrating from v1

SDK 2.0 replaces v1 completely. Here’s what changed and how to move your app over.

SDK 2.0 decides flags inside your app from a cached config, adds percentage rollouts, and never throws. It also has breaking changes, so plan a short migration.

What changed

  • New entry points. React exports live in @flaggish/sdk/react and Next.js helpers in @flaggish/sdk/next. The root @flaggish/sdk is the framework-free core.
  • New functions. useGetFlags, useFlaggish and the v1 getFlags are replaced by FlaggishProvider, useFlag and useFlags in React, and getFlag and getFlags on the Next.js server.
  • Exact flag names. Flag keys are the exact flag names, with no changes. v1 removed spaces from names, so a flag called new checkout was newcheckout. In v2 it’s new checkout.
  • No secret key. Use the public client key only.
  • A proxy for Next.js. Add flaggishMiddleware to proxy.ts (Next.js 16) or middleware.ts (Next.js 14 and 15), so rollouts match between the server and the browser.

Upgrade

  1. Install SDK 2.0

    Terminal
    npm i @flaggish/sdk@beta
  2. Update your environment variables

    Keep NEXT_PUBLIC_FLAGGISH_CLIENT_KEY or FLAGGISH_CLIENT_KEY. Delete FLAGGISH_SECRET_KEY: v2 doesn’t use it, and it doesn’t belong anywhere a browser can see. If you used NEXT_PUBLIC_FLAGGISH_CLIENT_API_KEY, rename it to NEXT_PUBLIC_FLAGGISH_CLIENT_KEY.

    .env.local
    NEXT_PUBLIC_FLAGGISH_CLIENT_KEY=your-client-key

    FLAGGISH_ENV now takes production or development. See Environment variables.

  3. Add the proxy and the provider

    In Next.js, add flaggishMiddleware and wrap your root layout in FlaggishServerProvider. In React, wrap your app in FlaggishProvider. Remove any useFlaggish() call. The Next.js and React guides have the code.

  4. Replace your flag checks

    v1
    import { getFlags, useGetFlags } from '@flaggish/sdk';
    
    // client
    const { flags, isLoading } = useGetFlags();
    const enabled = flags?.newcheckout;
    
    // server
    const serverFlags = await getFlags();

    Search your code for each flag name. Any name with a space in it needs updating.

  5. Remove error handling around checks

    v1 could throw when the API failed or a key was missing. v2 never throws: it falls back to the last flags it had, then your defaults, then false. Pass defaults for flags that should be on when Flaggish can’t be reached. See If Flaggish is down.

  6. Check it

    Flip a flag in the dashboard. Your app picks up the change within about 30 seconds.

Node

Replace v1’s getFlags() with a client:

index.ts
import { createFlaggish } from '@flaggish/sdk';

const flaggish = createFlaggish();
const enabled = await flaggish.isEnabled('new checkout', { userId: 'user_123' });

See the Node guide.

Was this page helpful?

Request early access

Become a beta user, or stay up to date with the project.