Feature flags let you roll out product changes to specific users, test features internally, and run A/B tests before a full release. The Flags SDK and Vercel Toolbar give you control over which content your users see.
This guide shows you how to set up the Flags SDK in a Fumadocs project with the Vercel Toolbar. Fumadocs is a popular framework for building documentation sites.
You'll build an application that:
- Toggles content visibility within MDX pages
- Hides entire pages behind a feature flag
- Removes flagged pages from the sidebar
- Tests flag states using the Vercel Toolbar
Before you begin, make sure you have:
To use the Flags SDK and Vercel Toolbar in your project, install the following packages:
Note: Fumadocs version 11.6.6 requires zod version 3.24.2.
Then update your next.config.js file to wrap the default MDX config with the Vercel Toolbar:
Update your root layout file to conditionally render the Vercel Toolbar in development:
Create a new file called flags.ts at your project root:
This code defines:
key: A unique identifier for the flag that you reference in codedefaultValue: The initial state of the flag. This value must be a type that thedecidefunction can return. For a boolean flag, the default is typicallyfalsedecide: A function that determines which value a user sees. It can return any value that matches the type ofdefaultValue
The Vercel Toolbar discovers available flags through an API route. Create the endpoint with the following code:
You can hide parts of your documentation from certain users with a feature flag. Create a component called InternalContent:
Register it as a globally available component in all MDX files:
Import your new component in an MDX file, then add content you want hidden when the flag is disabled:
Open your source.config.ts file and extend the Fumadocs schema to add a new property to the MDX pages frontmatter fields:
Note: Use the as any casts to avoid "Type instantiation is excessively deep" errors due to complex type inference in Zod with Fumadocs schemas. A later version of Fumadocs might resolve this.
Check the flag in your page component and return a 404 if the flag is disabled:
When you set the internal property in your MDX pages' frontmatter, it hides the page from navigation, preventing users from landing on a 404. This code filters out internal pages from the sidebar by removing those pages from the tree:
This code:
- Gets all pages marked with
internal: true - Creates a
Setof their URLs - Recursively filters the page tree:
- Removes pages in the internal URLs set
- Removes folders that become empty after filtering
- Handles folder index pages separately
Add internal: true to any MDX page's frontmatter. This will hide the page is the flag is set to true:
When running your project locally, you’ll see the toolbar as a widget floating above the UI. To test your flag locally, open the flags explorer from the toolbar and:
Navigate to the page you added the InternalContent component to, you should see the banner you added that marks the page as internal to your team.