Has anyone been able to properly figure out the hy...
# ask-questions
l
Has anyone been able to properly figure out the hydration issues for feature flags using Next.js and the pages router? Documentation doesn't seem to address this properly,
useFeatureIsOn
and
IfFeatureEnabled
both throw hydration errors whenever the feature is flipped. Images and more details in 🧵
I've got the GrowthbookProvider set up correctly, data is being fetched correctly, and in fact if I dismiss the error and flip the feature back and forth, it even shows the showing/hiding of the content I have set up. But upon refreshing, lots of errors. Really not sure what I'm missing here. I've attempted using
next/dynamic
and I just get the same errors.
The only way I've been able to moderately get it to work is by using
getStaticProps
and dropping in the data, but that will only be valid at build time, so it doesn't seem to make too much sense. Attempting with
getServerSideProps
is also minorly successful, but it removes the benefits of having a statically generated page.
s
Next.js hydration issues with feature flags can be tricky. On first glance, I'm not sure exactly where the mismatch is occurring, but I did want to share our Next.js pages example repo, which includes best practices for integrating GB with Next.js and the pages router: https://github.com/growthbook/examples/tree/main/next-js-pages Lmk if you've already seen it and are still running into issues.
l
@strong-mouse-55694 Thanks for the response. I've gone through all of these examples, though unfortunately some of it quite out of date. Most of the code is deprecated in current Growthbook packages, as you can see in the attached images. For example the package is using
0.17.0
even though the latest version is
1.3.1
. For example when updating the packages (including growthbook, next, react, and react-dom), the Pure Serverside Rendering example no longer functions properly, and all of the pages have deprecation warnings. All that being said, I think I've worked out a possible way to use the Provider alongside static pages, though I need to give it some more thorough testing.
s
Thanks for letting me know. We also have a more up-to-date example with the app router that may be useful until we have a chance to update the pages examples: https://github.com/growthbook/examples/tree/main/next-js