-
Notifications
You must be signed in to change notification settings - Fork 713
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
useProgress - Warning: Cannot update a component (Loader
) while rendering a different component
#314
Comments
Hi @nestorchura2019, Thanks for this, I believe this is an issue with some changes made in #304. @RenaudRohlinger, would you mind looking into this? Or shall I just revert that commit? |
thanks |
@joshuaellis That's a known issue that has always been here. My last PR couldn't affect that part. I don't really know how to fix that, maybe refactor the whole hook? |
This isn't the case with v3.8.0 – https://codesandbox.io/s/oficce-with-loading-ui-forked-sjgs4?file=/src/App.js the example you've sent over uses a version of |
@joshuaellis We did not had this error between 3.4.0 and 3.8.0 because I tried to fix it by using a separate instance of the loader for async multi loading which was wrong and broke the loader (between these 2 versions the loader was stuck at 0%). So I would not recommend reverting any commit. You can try any version before 3.4.0 and you will see the same error. Ref introduced in 3.4.0: #289 The only solution would be to refactor the loader. There is a setter in the DefaultManager onStart event (https://github.com/pmndrs/drei/blob/master/src/core/useProgress.tsx#L16) but if multiple elements are loaded at the same time it will throw "Cannot update a component while rendering a different component" since they are conflicting with each other because they all use the same loading manager. As I said in my last PR the only clean fix would be to work on the loading manager of threejs. Using the defaultManager of threejs is not the best solution and my last PR is just an improvement of something unstable from the beginning that allows to handle a new instance of loading |
What version of three.js is the recommended or compatible? |
@nestorchura2019 in the meantime you could check the implementation with the official Loader component of Drei: https://codesandbox.io/s/oficce-with-loading-ui-forked-y6m2y?file=/src/App.js It won't throw any error. Maybe something to dig here @joshuaellis ? |
I'm closing this due to inactivity, it seems like a really niche issue & something weird |
Hi @joshuaellis! I'm running into the same problem right now and I think that I might have to disagree with you on it being a niche issue. Personally, I find myself wanting to use multiple loaders within a single component quite often. It's especially useful if you want to dispatch all the loaders within a scene in one context providing component for reusability purposes. The solution above from @RenaudRohlinger with the drei component didn't work for me btw. It's probably a separate issue, but the completed state triggered too early with the useCubeTexture loader. I'm relatively green when it comes to r3f so please do tell me if I'm missing something obvious here. ✌🏻 |
Im having the same problem. Any updates on this? |
I encountered this error recently as soon as I added a I figured out a solution that solved the issue for me though. Delay every export function withNextTickLoading<T, L extends LoaderProto<T>>(Proto: L): L {
return class NextTickLoader extends Proto {
load(
...args: Parameters<Loader<T extends unknown ? any : T>['load']>
): void {
setTimeout(() => super.load(...args), 0);
}
};
}
interface Loader<T> extends THREE.Loader {
load(
url: string,
onLoad?: (result: T) => void,
onProgress?: (event: ProgressEvent) => void,
onError?: (event: ErrorEvent) => void
): unknown;
}
type LoaderProto<T> = new (...args: any) => Loader<T extends unknown ? any : T>; Which can be used like so: - const data = useLoader(THREE.FileLoader, url);
+ const data = useLoader(withNextTickLoading(THREE.FileLoader), url); I applied it to @nestorchura2019's code and it seems to fix it too: https://codesandbox.io/s/oficce-with-loading-ui-fixed-zcm2fh Just thought I'd share in case this brings us closer to identifying what the proper fix for |
I'm also running into this issue. I have a scene set up with a As a sibling to the scene loader, there is a So overall: <Canvas>
<GLTFSceneLoader /> // contains useProgress & useGltf
<EnvironmentContainer /> // contains <Environment /> (which wraps useEnvironment)
</Canvas> Oddly when the scene loader is calling a URL through Unfortunately, in my case the hooks used are built around |
I see this PR in the R3F repository that enables loader instances within |
That React warning is a real bug, so I'm elevating this issue. |
I confirm, useProgress crashes whole app on start, what is teh status of this bug ? |
if that matters, useTexture is also raising the same issue in latest version 9.108.3 (in dev mode only, the red warning leaves in production but that remains scary) |
I confirm the issue also with |
I also encountered the same problem when I used useGltf and useAnimations in a component and wrapped Suspense outside of it. When I tried to use useProgress to read the loading status, it would trigger this bug at a certain loading moment. But it seems to be caused by react. By the way, It is my version info: "@react-three/drei": "^9.109.5","@react-three/fiber": "^8.17.5","three": "^0.167.1","react": "^18.3.1", "react-dom": "^18.3.1", |
Also having this issue with multiple loaders in a component, rather easy to achieve with common usecases. @lukehorvat's timeout is a clever hack but IMO going with a loader design that animates indeterminate progress avoiding |
I've experienced the same, but in my case it must be because I am rendering a component (which is loading a texture) inside an imported model, so it throws the same error. |
Im loading a gltb model and a texture(lightMap),
when using the useProgress I get the error, if I don't load the texture (const texture = useTexture("balightmap2.jpg")), the error is not displayed, I think the error comes out because I'm loading two things, the glb and the texture
Codesandbox - https://codesandbox.io/s/z8zjw?file=/src/App.js
The text was updated successfully, but these errors were encountered: