Affected: React Web client-side SDK
Symptoms
The React Web SDK offers the optional flags property in the configuration to help define fallback values for your flags.
When there are errors connecting to LaunchDarkly during initialization, the flags object will return undefined values for flags instead of the fallback values defined in the flags property.
Cause
This is expected behavior. If any error occurs during initialization, the flags object will be returned as an empty object. The code from the React Web SDK source contains the following:
function handleFailure(error: Error) {
cleanup();
resolve({ flags: {}, ldClient, error });
} Wrap
The flags property will only work as expected for errors that occur after successful initialization.
Solution
Check for initialization errors in the react context and handle the error accordingly. Use the useLDClientError hook to get the error.