-
Notifications
You must be signed in to change notification settings - Fork 68
Closed
Description
The Problem
Currently, our app that relies on the LaunchDarkly service is render blocked by the actual LD Service. In other words, if the LD Service fails to connect, our app will never load.
Specifically if this line fails, we never know.
This is in a nutshell how we use the React SDK
import React from 'react'
export const App: React.FC<Props> = props => {
const { userID } = props;
/** PROBLEM: THIS MAY NEVER INIT AND BE UNDEFINED FOREVER */
const client = useLDClient();
const [isLoading, setLoading] = React.useState<boolean>(true)
React.useEffect(() => {
if (client && userID) {
client
.identify({
key: userID
})
/**
* set loaded to true if client fails or succeeds.
*
* We don't want to render block if the flags can't be loaded.
*/
.then(() => setLoading(false))
.catch(() => setLoading(false));
}
}, [client, userID]);
if (isLoading) {
return null;
}
return <App />;
};
export default App;but the issue here is that we have no way of knowing whether or not the connection succeeded.
Ideal Solution
Provide a new prop, maybe called ldConnectionError to the <WrappedComponent /> here..
So that could open a consumer component up to the following possibilities
import React from 'react'
export const App: React.FC<Props> = props => {
const { userID } = props;
const [client, clientError] = useLDClient();
const [isLoading, setLoading] = React.useState<boolean>(true)
React.useEffect(() => {
if (client && userID) {
client
.identify({
key: userID
})
/**
* set loaded to true if client fails or succeeds.
*
* We don't want to render block if the flags can't be loaded.
*/
.then(() => setLoading(false))
.catch(() => setLoading(false));
}
}, [client, userID, clientError]);
if (isLoading && !clientError) {
return null;
}
return <App />;
};
export default App;Metadata
Metadata
Assignees
Labels
No labels