-
Couldn't load subscription status.
- Fork 12
useFlags stuck fetching in standalone build after upgrading from Next 13.5.2 -> Next 13.5.6 #60
Description
We currently use HappyKit in a Next project with the following setup:
"@happykit/flags": "^3.3.0",
...
"next": "13.5.2",This project uses a standalone next build running in a docker container. We deploy this same image to multiple tenant envs, using env vars to control things like tenant_id and api keys. Internally, we leverage Next's public runtime config to propagate unique env vars instead of NEXT_PUBLIC... method of baking values into images.
const { publicRuntimeConfig } = getConfig() as {
publicRuntimeConfig: {
_MY_PUBLIC_TENANT_ID: string;
_MY_PUBLIC_HAPPY_KIT_FLAGS_PUBLIC_KEY: string;
};
};
const FeatureFlagContext = createContext<AppFlags | null>(null);
export const FeatureFlagContextProvider = ({ children }: PropsWithChildren) => {
const useFlags = createUseFlags<AppFlags>({
envKey: publicRuntimeConfig._MY_PUBLIC_HAPPY_KIT_FLAGS_PUBLIC_KEY,
defaultFlags: DEFAULT_FLAGS,
} as Configuration<AppFlags>);
const { flags, error } = useFlags({
user: publicRuntimeConfig._MY_PUBLIC_TENANT_ID
? {
key: publicRuntimeConfig._MY_PUBLIC_TENANT_ID,
}
: undefined,
});
if (error) {
console.error(
"Failed to use flags, falling back to defaults. Error: ",
error,
);
}
return (
<FeatureFlagContext.Provider value={flags ?? DEFAULT_FLAGS}>
{children}
</FeatureFlagContext.Provider>
);
};This setup has worked for us for a while now.
We're now attempting an upgrade from Next 13.5.2 to Next 13.5.6 - the only change in our app like so:
- "next": "13.5.2",
+ "next": "13.5.6",After this upgrade, everything is working as expected in a dev environment. However our production standalone and dockerized builds are failing to resolve flags. Debugging the issue in such a production build, I can see
- the Provider component is stuck in an infinite re-render loop
- the publicRuntimeConfig behavior has not changed, and is not triggering the re-renders
- viewing the network requests to happykit, I can see the requests are going out with the correct payload but the requests are immediately cancelled
Any help debugging further would be appreciated.