惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

罗磊的独立博客
G
Google Developers Blog
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
腾讯CDC
有赞技术团队
有赞技术团队
Vercel News
Vercel News
MongoDB | Blog
MongoDB | Blog
M
MIT News - Artificial intelligence
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
B
Blog RSS Feed
I
InfoQ
Blog — PlanetScale
Blog — PlanetScale
博客园_首页
The Cloudflare Blog
B
Blog
C
Check Point Blog
Stack Overflow Blog
Stack Overflow Blog
IT之家
IT之家
U
Unit 42
D
Docker
月光博客
月光博客
aimingoo的专栏
aimingoo的专栏
博客园 - Franky
A
About on SuperTechFans

Flags SDK Documentation

Global Config Bulk Evaluation Evaluation Context Precompute GrowthBook Hypertune PostHog Split Evaluation Context Quickstart Precompute Evaluation Context Quickstart Precompute GrowthBook Hypertune PostHog Split Proxy Dashboard Pages Marketing Pages Dashboard Pages Marketing Pages Data Locality Providers LaunchDarkly Optimizely Reflag Statsig Server-side vs Client-side
Dedupe
Vercel · 2026-04-03 · via Flags SDK Documentation

Prevent duplicate work by deduplicating function calls.

Any function wrapped in dedupe will only ever run once for the same request within the same runtime and given the same arguments.

The dedupe function is an integral piece when working with the Flags SDK.

import { dedupe } from 'flags/next';

const dedupeExample = dedupe(() => {
  return Math.random();
});

export default async function Page() {
  const random1 = await dedupeExample();
  const random2 = await dedupeExample();
  const random3 = await dedupeExample();

  // these will all be the same random number
  return (
    <div>
      {random1} {random2} {random3}
    </div>
  );
}

Example of output:

Avoiding duplicate work

This helper is useful in combination with the identify function, as it allows the identification to only happen once per request. This prevents overhead when passing the same identify function to multiple feature flags, or when using the same flag multiple times.

Generating consistent random IDs

When experimenting on anonymous visitors it is common to set a cookie containing a random id from Proxy. This random id is later used to consistently assign users to specific groups of A/B tests.

For this use case, the function generating the random id can be wrapped in dedupe. The deduplicated function is then called in Routing Functions to produce the random id, and from a flag's identify function to identify the user even on the first page visit when no cookie is present yet.

As the function is guaranteed to generate the same id the Routing Functions can set a cookie containing the generated id in a response, and the feature flag can already use the generated id even if the original request did not contain the id.

Note that dedupe is not available in Pages Router.

See the Marketing Pages example