nutritious-match-31698
09/10/2025, 12:37 PMSDK Connection and my code currently looks like that:
import { growthbookAdapter } from "@flags-sdk/growthbook";
import type { Identify } from "flags";
import { flag } from "flags/next";
growthbookAdapter.setTrackingCallback(async (experiment, result) => {
console.log("Viewed Experiment", {
experimentId: experiment.key,
variationId: result.key,
});
});
type UserAttributes = {
id: string;
};
export const identify = (() => {
return { id: "abc" };
}) satisfies Identify<UserAttributes>;
export const testFlag = flag<boolean>({
key: "test_feature",
adapter: growthbookAdapter.feature<boolean>(),
identify,
});
export const stringTestFeature = flag<string>({
key: "string_test_feature",
adapter: growthbookAdapter.feature<string>(),
identify,
});
My issue is that whenever I change the value for any of my flags, the SDK returns old value until I restart my local server. Is it only because locally it's a long running server and the issue is not gonna be present when deployed to Vercel, or do I have to perform some additional steps in order to enforce refetching the data from Growthbook?
Thanks upfront!fresh-football-47124
fresh-football-47124
nutritious-match-31698
09/11/2025, 7:44 AMfresh-football-47124
fresh-football-47124
nutritious-match-31698
09/11/2025, 7:54 AMnutritious-match-31698
09/11/2025, 12:23 PMimport { createGrowthbookAdapter } from "@flags-sdk/growthbook";
import { flag } from "flags/next";
import { env } from "~/env.mjs";
const createAdapter = () =>
createGrowthbookAdapter({
clientKey: env.GROWTHBOOK_CLIENT_KEY,
initOptions: {
skipCache: true,
},
clientOptions: {
disableCache: true,
trackingCallback: (experiment, result) => {
console.log("Viewed Experiment", {
experimentId: experiment.key,
variationId: result.key,
});
},
},
});
type UserAttributes = {
id: string;
};
type GetFlagValueArgs = {
key: "string_test_feature" | "test_feature";
attributes: UserAttributes;
};
export function getFlagValue<T>({ key, attributes }: GetFlagValueArgs) {
const adapter = createAdapter();
const value = flag<T>({
key,
adapter: adapter.feature<T>(),
identify: () => attributes,
});
return value();
}nutritious-match-31698
09/11/2025, 12:39 PMadapter.growthbook.refreshFeatures() instead of recreating the adapter each time. So now my code looks like this:
import { createGrowthbookAdapter } from "@flags-sdk/growthbook";
import { flag } from "flags/next";
import { env } from "~/env.mjs";
const adapter = createGrowthbookAdapter({
clientKey: env.GROWTHBOOK_CLIENT_KEY,
clientOptions: {
trackingCallback: (experiment, result) => {
console.log("Viewed Experiment", {
experimentId: experiment.key,
variationId: result.key,
});
},
},
});
type UserAttributes = {
id: string;
};
type GetFlagValueArgs = {
key: "string_test_feature" | "test_feature";
attributes: UserAttributes;
};
export async function getFlagValue<T>({ key, attributes }: GetFlagValueArgs) {
await adapter.growthbook.refreshFeatures({ skipCache: true });
const value = flag<T>({
key,
adapter: adapter.feature<T>(),
identify: () => attributes,
});
return value();
}
And now, knowing that I can just call adapter.growthbook.refreshFeatures() , I can do one of the following for the long term solutions:
• run this periodically as a cron job (e.g. every 5 minutes)
• leverage Growthbook's webhooks to call it on demand when feature flags change in the dashboard
Am I on the right track?