Any way to handle useLoader fail #1881
Replies: 3 comments 5 replies
-
I'd look into error boundaries for this. You can catch errors from multiple components there. We use this for the Canvas component to contain errors within it: /**
* Generic error boundary. Calls its `set` prop on error.
*/
class ErrorBoundary extends React.Component<{ set: React.Dispatch<any> }, { error: boolean }> {
state = { error: false }
static getDerivedStateFromError = () => ({ error: true })
componentDidCatch(error: any) {
this.props.set(error)
}
render() {
return this.state.error ? null : this.props.children
}
} |
Beta Was this translation helpful? Give feedback.
-
Using ErrorBoundary on the Canvas level can cause an empty scene especially with PCDLoader & 502 response.. But putting try..catch on the render level can solve the issue of the useLoader.
|
Beta Was this translation helpful? Give feedback.
-
I've noticed that some useGLTF errors don't get caught by the error boundary (since react error boundaries only handle errors that impact the react tree). If you cause the decoding to fail, by say deleting random bytes out of a glb file, something inside useGLTF will throw but not be caught by the error boundary. This just causes the app to crash and a blank canvas. I'm running into this on a high traffic site where a small percentage of network requests for my glb file get interrupted. Any advice on how to handle cases like these? |
Beta Was this translation helpful? Give feedback.
-
I have this piece of code where I try to load an OBJ file stored on the cloud. My challenge is that when the file is not there or there is a network issue the whole page crashes:
Example of an error that occured:
Is there a way to handle errors that occur in this hook?
Beta Was this translation helpful? Give feedback.
All reactions