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
Integration with NextJS #86
Comments
Hi @wongshennan , thanks for creating the issue, I will bring it up with the team and get back to you |
Hey, @wongshennan 🙋🏼 Thanks for opening the issue: I think the base issue at hand here is that Next tries to initialize the client during its server-side rendering. However, const UnleashProvider: typeof FlagProvider = ({ config = {}, children }) => {
// To prevent from throwing during SSR, pass a dummy storage provider
const storageProvider = isNode
? new DummyStorageProvider()
: window.localStorage;
// Similarly, pass a dummy fetch provider
const fetchProvider = isNode ? fetch : undefined;
return (
<FlagProvider
config={{
storageProvider,
fetch: fetchProvider,
url: process.env["UNLEASH_URL"],
clientKey: process.env["UNLEASH_CLIENT_KEY"],
refreshInterval: 15,
appName: process.env["APP_NAME"],
environment: process.env["APP_ENV"],
...config,
}}
>
{children}
</FlagProvider>
);
}; If I'm correct, then that should solve your issue here. But you might also want to consider whether creating an unleash client on every request is the right way to go or not. Doing it this way will delay rendering as the client needs to be constructed and fetch toggles. Instead, you might want to consider alternate approaches. For instance:
Does that help? |
would be great to have a better integration with NextJS 👍 |
Probably fixed with Unleash/unleash-proxy-client-js#134 @BkSouX agree. I'm working on it. |
Describe the bug
I've tried to set-up Unleash on an existing NextJS repository, following the steps in the quickstart guide:
without creating a custom-server, as denoted here, is there another way to configure a nextjs app to accept unleash flags?
Steps to reproduce the bug
The unleash configs are as follows:
Expected behavior
No response
Logs, error output, etc.
The text was updated successfully, but these errors were encountered: