Skip to content
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

Window is not defined error when using @react-three/xr with Next.js #331

Closed
rajput-hemant opened this issue Aug 10, 2024 · 2 comments
Closed

Comments

@rajput-hemant
Copy link

I am working on a project using Next.js and have integrated @react-three/xr to create an immersive XR experience. However, I keep encountering a window is not defined error, which I suspect is related to the createXRStore function.

Additionally, the XR experience does not get triggered on my mobile device when using Next.js.

Could an example or guidance on how to properly use @react-three/xr in a Next.js environment be provided? Any help or advice would be greatly appreciated.

Thanks!

@bbohlender
Copy link
Collaborator

thanks, will fix asap

@timhc22
Copy link

timhc22 commented Sep 19, 2024

I had to do something like this in NextJS:

const DynamicMainCanvas = dynamic(() => import('@/components/MainCanvas').then(mod => mod.default as React.ComponentType<MainCanvasProps>), { ssr: false });

export default function CanvasWrapper({ meta }: any) {
  const [store, setStore] = useState<any>(null);

  useEffect(() => {
    // Dynamically import createXRStore to prevent SSR issues
    import('@react-three/xr').then(({ createXRStore }) => {
      const xrStore = createXRStore();
      setStore(xrStore);
    });
  }, []);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants