react-client-sdk icon indicating copy to clipboard operation
react-client-sdk copied to clipboard

needs loading flag that whether ld has fetched flags

Open sudokzt opened this issue 2 years ago • 14 comments

Is your feature request related to a problem? Please describe. I would love to wait until what LD fetches flags. In current, I'm realizing it with flag state that returns value by useFlags().

Describe the solution you'd like I'm looking forward to return loading value from useFlags().

Describe alternatives you've considered In current, useFlags returns only flags. And whether the LD got the flag is checked by whether the value of useFlags() is null. But, it's unintuitive. So I want a loading flag.

sudokzt avatar Mar 28 '22 09:03 sudokzt

Hello @sudokzt, thank you for reaching out. Please let me know and elaborate if the following answer doesn't quite answer your question.

It seems you want to make sure you wait for the flag values from LD instead of using the Client immediately. If that is the case, would the asyncWithLDProvider(config: AsyncProviderConfig) in here which wait for the ldClient to be ready works for you?

louis-launchdarkly avatar Apr 01 '22 23:04 louis-launchdarkly

An alternative to using useFlags would be to use the useLDClient hook - it will return undefined until the client is ready. For example, an "is ready" custom hook might look something like this,

import { useLDClient } from 'launchdarkly-react-client-sdk'

export default function useIsLDReady(): boolean {
  const ldClient = useLDClient()

  return ldClient !== undefined
}

XieX avatar Aug 16 '22 20:08 XieX

Hello @louis-launchdarkly I have tried using asyncWithLDProvider({}), but on the initial app load useFlags() is still returning an empty object, but it returns the object with the flags after a few seconds. When the object is empty for some reason the flags are retuning false, but the actual values are true on launch darkly panel. This is causing flickering of components within the app, How can I overcome this? Here is my index.tsx file

(async () => {
  const LDProvider = await asyncWithLDProvider({
    clientSideID: .............,
    user: {
      anonymous: true,
    },
  });

  return ReactDOM.render(
    <LDProvider>
      <App />
    </LDProvider>,
    document.getElementById('root'),
  );
})()

Hamad-98 avatar Jan 13 '23 17:01 Hamad-98

I am currently having the same issues in regards to this. Commenting to follow the solution

lschwall4 avatar May 08 '23 20:05 lschwall4

Does anyone have a solution for this flickering yet? Also experiencing it.

gideon-grossman avatar Jul 07 '23 20:07 gideon-grossman

What is stopping Launch Darkly from having something like

const { isLoading } = useLDClient();

Also why is useLDClient returning undefined even when it's wrapped in withLDProvider. Shouldn't useLDClient never return undefined if it's nested under a withLDProvider?

bnussman avatar Oct 24 '23 23:10 bnussman

Also finding this issue is still ongoing.

yougotashovel avatar Nov 23 '23 17:11 yougotashovel

likewise issue is still occuring

13mikj avatar Dec 11 '23 18:12 13mikj

Following

JoshClopton avatar Jan 03 '24 21:01 JoshClopton

We've been running into a similar issue that has been mentioned in this thread. By initializing the client first (awaiting it), and then wrapping the React app with the provider, on load we get no values for our feature flags, when the client should've already been initialized. We've started seeing this more lately, which could've been after we upgraded to Webpack 5. I wonder if there is any polyfill the LD client relies on that might be causing this to happen ?(since webpack 5 stopped polyfilling a bunch of node utils) It seems to be sporadic, haven't been able to pinpoint when/why.

juanporley avatar Jan 26 '24 16:01 juanporley

Following

hkedia321 avatar Jan 29 '24 07:01 hkedia321

Try this from docs: https://docs.launchdarkly.com/sdk/client-side/javascript/?q=waitforinitialization#use-promises-to-determine-when-the-client-is-ready

there are waitUntilReady and waitForInitialization methods exposed by SDK on useLDClient

yevhen-logosha avatar Jun 17 '24 13:06 yevhen-logosha