-
Notifications
You must be signed in to change notification settings - Fork 11
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useFlags stuck fetching in standalone build after upgrading from Next 13.5.2 -> Next 13.5.6 #60
Comments
@dferber90 friendly bump. This is blocking our upgrade of Nextjs, which has security vulnerabilities at the moment. |
Thanks for the report! Unfortunately it's hard to help without a reproduction. One thing I noticed is that you're defining |
@dferber90 To clarify the problem and rule out this culprit, i reran the code with hardcoded keys and useFlags defined outside the component, removing any use of "public runtime config". I'm still facing the same issues with standalone builds using Next 13.5.6. Code below. import { createContext, useContext, type PropsWithChildren } from "react";
import { createUseFlags } from "@happykit/flags/client";
import { type Configuration } from "@happykit/flags/config";
const FeatureFlagContext = createContext<AppFlags | null>(null);
type AppFlags = {
my_flag: boolean;
};
const useFlags = createUseFlags<AppFlags>({
envKey: "MY_KEY",
defaultFlags: {
my_flag: false,
},
} as Configuration<AppFlags>);
export const FeatureFlagContextProvider = ({ children }: PropsWithChildren) => {
const { flags, error } = useFlags({
user: { key: "dev" },
});
if (error) {
console.error(
"Failed to use flags, falling back to defaults. Error: ",
error,
);
}
return (
<FeatureFlagContext.Provider value={flags ?? { my_flag: false }}>
{children}
</FeatureFlagContext.Provider>
);
}; |
I noticed you're manually creating a context which is not expected. Check out the example on https://flags.happykit.dev/demo/context with its source code here https://github.com/happykit/flags/blob/master/example/pages/demo/context.tsx. Here's a version of your code that's working for me import { type PropsWithChildren, useState } from "react";
import { createUseFlags } from "@happykit/flags/client";
import { type Configuration } from "@happykit/flags/config";
import { useFlagBag } from "flags/client";
import { FlagBagProvider } from "@happykit/flags/context";
type AppFlags = {
my_flag: boolean;
};
const useFlags = createUseFlags<AppFlags>({
envKey: process.env.NEXT_PUBLIC_FLAGS_ENV_KEY,
defaultFlags: {
my_flag: false,
},
} as Configuration<AppFlags>);
const FeatureFlagContextProvider = ({ children }: PropsWithChildren) => {
const flagBag = useFlags({
user: { key: "dev" },
});
return <FlagBagProvider value={flagBag}>{children}</FlagBagProvider>;
};
export default function Page() {
return (
<FeatureFlagContextProvider>
<Inner />
</FeatureFlagContextProvider>
);
}
function Inner() {
const [x, setX] = useState(0);
const flags = useFlagBag();
console.log(flags);
return (
<p
onClick={() => {
setX((p) => p + 1);
}}
>
cool {x}
</p>
);
} Note that this
|
@dferber90 were you able to get the above working in a standalone build using the latest Next 13? (13.5.6)?? The context workarounds listed previously were introduced in order to leverage runtime environment variables that are not baked into the build. I didn't see an easy route around them. Putting that aside to focus on the underlying issue, here is an even simpler example. The following code works in dev, but is broken when running standalone Next 13.5.6 build. const useFlags = createUseFlags<AppFlags>({
envKey: "MY_KEY",
defaultFlags: DEFAULT_FLAGS,
} as Configuration<AppFlags>);
export default function FlagPrinter() {
const flagBag = useFlags({
user: { key: "dev" },
});
return <div>{JSON.stringify(flagBag.flags)}</div>;
} |
Yes it's working for me. Could you provide a repository which reproduces this? Without a reproduction it's very hard to help here |
Running into this same issue where it's unable to resolve after deploying and getting a bunch of API calls but it's working fine on local |
@idarwishman do you have a reproduction repo? |
We currently use HappyKit in a Next project with the following setup:
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.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:
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
Any help debugging further would be appreciated.
The text was updated successfully, but these errors were encountered: