ConfigCat SDK for React. ConfigCat is a hosted feature flag service: https://configcat.com. Manage feature toggles across frontend, backend, mobile, desktop apps. Alternative to LaunchDarkly. Management app + feature flag SDKs.
It turned out that simply switching to axios instead of XMLHttpRequest would only hide the original issue but it won't fix the problem.
I added 'use client' to the entry points to indicate that the SDK is intented to be used only on client side.
However it wasn't enough for Next.JS as it prerendered our code on the server side even if I specified the 'use client'.
That would not be a problem by default but we initialized the configcatclient in the ConfigCatProvider's constructor. So when Next.JS prerendered the ConfigCatProvider, it started the polling on the server side as well.
I refactored the code to only initialize the client in componentDidMount. componentDidMount is not running on the server side during the prerendering, so the client will not be initialized on the server side.
Unfortunately I had to introduce a breaking changes to be able to achieve this functionality: from now, the useConfigCatClient hook can return undefined until the Provider is not mounted.
I also created a sample Next.JS app that can use our React SDK.
Describe the purpose of your pull request
Using the SDK in Next.JS had issues on the server side - XMLHttpRequest is not defined (https://github.com/configcat/react-sdk/issues/40, https://github.com/configcat/react-sdk/issues/7).
It turned out that simply switching to axios instead of XMLHttpRequest would only hide the original issue but it won't fix the problem. I added 'use client' to the entry points to indicate that the SDK is intented to be used only on client side. However it wasn't enough for Next.JS as it prerendered our code on the server side even if I specified the 'use client'. That would not be a problem by default but we initialized the configcatclient in the ConfigCatProvider's constructor. So when Next.JS prerendered the ConfigCatProvider, it started the polling on the server side as well. I refactored the code to only initialize the client in componentDidMount. componentDidMount is not running on the server side during the prerendering, so the client will not be initialized on the server side.
Unfortunately I had to introduce a breaking changes to be able to achieve this functionality: from now, the useConfigCatClient hook can return undefined until the Provider is not mounted.
I also created a sample Next.JS app that can use our React SDK.
Related issues (only if applicable)
https://github.com/configcat/react-sdk/issues/40 https://github.com/configcat/react-sdk/issues/7
Requirement checklist (only if applicable)