Replies: 2 comments 3 replies
-
I'm not sure I understand, context loss is necessary when then canvas component unmounts, without that you'd have a memory leak. When it remounts it will build a new one. there's no secret trick in react that allows a component that's being unmounted to not be, its useEffect cleanup is called and it goes away. If you don't want that you should not unmount. To me it sounds like your problem is with RR. If you expect a component to live through route changes and somehow it doesn't the problem must be with how you set up these routes. |
Beta Was this translation helpful? Give feedback.
-
As drcmda says, if you don't want the GL context to go away, you can't unmount the You just need some mechanism then for the components inside the route to supply content that will go into the canvas: this sounds like you want // global
const myStore = new MyFavouriteReactStoreLibrary();
function ContentFromStore() {
const content = useStore(store => store.getContent());
return content;
}
// in your page content
<Canvas {...canvasProps>
<ContentFromStore>
</Canvas>
<Route component={Home} />
function Home() {
myStore.setContent(<mesh />);
} |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi there.
I'm trying to build an SPA with react-router-dom, electron, create-react-app and react-three-fiber.
Here comes the issue.
I have a Login screen in
<Route component={Login} path="/"/>
.I have my Main Content screen in
<Route component={Main} path="/main"/>
.So, since r-r-d UNMOUNTS the current view/component whether you switch between them. A WebGLContext loss occurs, because the
<Canvas>
doesn't exists anymore when you go to '/'... from '/main'The problem gets worse.
In my Main component, I have another nested routes that some of them includes a Canvas.
Even if I'm not unmounting Main view and just switching some nested routes over there, the context loss appears.
<Route component={Home} path="/main/"/>
----?<Canvas><group>....</group></Canvas>
<Route component={Profile} path="/main/profile"/>
----?<div>...</div>
<Route component={Inventory} path="/main/inventory"/>
----?<Canvas><group>....</group></Canvas>
<Route component={Shop} path="/main/shop"/>
----?<div>...</div>
Is there any solution to permit the Canvas be unmounted after route switch?
I've tried a less complex as an example and the issue is exactly the same.
Thank you so much for your time, happy coding.
Beta Was this translation helpful? Give feedback.
All reactions