-
-
Notifications
You must be signed in to change notification settings - Fork 8
Open
Description
Suspense is loading infinitely when i use useLoader on a component and wrap it with Suspense. The image gets loaded, but the the scene isn't redrawn until i make trigger a rerender or resize. i had to come up with something like this for it to work
function useTextureLoader(url: string) {
const gl = useOGL((state) => state.gl);
const [texture, setTexture] = useState<OGL.Texture | null>(null);
const [promise, setPromise] = useState<Promise<void> | null>(null);
useEffect(() => {
const img = new Image();
const loadPromise = new Promise<void>((resolve) => {
img.onload = () => {
const t = new OGL.Texture(gl);
t.image = img;
setTexture(t);
resolve();
};
});
setPromise(loadPromise);
img.src = url;
}, [gl, url]);
if (!texture && promise) {
throw promise;
}
return texture;
}I'm using NextJS 16.1.0 with React 19.2.3
Metadata
Metadata
Assignees
Labels
No labels