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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Box from @mui/material conflicts with Box from @react-three/drei #29176

Closed
1 of 2 tasks
vivere-dally opened this issue Oct 20, 2021 · 7 comments
Closed
1 of 2 tasks

Box from @mui/material conflicts with Box from @react-three/drei #29176

vivere-dally opened this issue Oct 20, 2021 · 7 comments
Labels
status: waiting for author Issue with insufficient information

Comments

@vivere-dally
Copy link

  • The issue is present in the latest release.
  • I have searched the issues of this repository and believe that this is not a duplicate.

Current Behavior 馃槸

If I add @react-three/drei package as a dependency, then all my components that use Box from @mui/material start producing the following error:

Expression produces a union type that is too complex to represent.ts(2590)

Expected Behavior 馃

There should not be any errors.

Steps to Reproduce 馃暪

Steps:

  1. Setup a cra app: npx create-react-app my-app --template typescript
  2. Add the following packages to your package.json
  "dependencies": {
    "@azure/msal-browser": "^2.18.0",
    "@azure/msal-react": "^1.1.0",
    "@emotion/react": "^11.5.0",
    "@emotion/styled": "^11.3.0",
    "@mui/icons-material": "^5.0.4",
    "@mui/lab": "^5.0.0-alpha.51",
    "@mui/material": "^5.0.4",
    "@mui/system": "^5.0.4",
    "@react-three/drei": "^7.16.8",
    "@react-three/fiber": "^7.0.17",
    "axios": "^0.23.0",
    "dotenv": "^10.0.0",
    "localforage": "^1.10.0",
    "react": "^17.0.2",
    "react-dom": "^17.0.2",
    "react-router": "^5.2.1",
    "react-router-dom": "^5.3.0",
    "react-scripts": "4.0.3",
    "three": "^0.133.1",
    "three-stdlib": "^2.5.4",
    "web-vitals": "^1.1.2",
    "zustand": "^3.5.14"
  },
  "devDependencies": {
    "@testing-library/jest-dom": "^5.14.1",
    "@testing-library/react": "^11.2.7",
    "@testing-library/user-event": "^12.8.3",
    "@types/jest": "^26.0.24",
    "@types/node": "^12.20.33",
    "@types/react": "^17.0.30",
    "@types/react-dom": "^17.0.9",
    "@types/react-router-dom": "^5.3.1",
    "@types/three": "^0.133.1",
    "@typescript-eslint/eslint-plugin": "^4.29.3",
    "@typescript-eslint/parser": "^4.29.3",
    "cross-env": "^7.0.3",
    "eslint-config-airbnb": "^18.2.1",
    "eslint-config-airbnb-typescript": "^14.0.1",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-import": "^2.25.2",
    "eslint-plugin-jsx-a11y": "^6.4.1",
    "eslint-plugin-react": "^7.26.1",
    "eslint-plugin-react-hooks": "^4.2.0",
    "jest-when": "^3.4.1",
    "rimraf": "^3.0.2",
    "typescript": "^4.4.4"
  },
  1. Run npm install
  2. Make sure you're running on Typescript v4.4.4
  3. Add the following component to your src. I name it ThreeRenderer.tsx:
import { Html, OrbitControls, PerspectiveCamera, useGLTF, useProgress } from '@react-three/drei';
import { Canvas, useFrame } from '@react-three/fiber';
import { FC, Suspense, useEffect, useRef, useState } from 'react';
import { AnimationAction, AnimationMixer } from 'three';
import { GLTF, GLTFLoader } from 'three-stdlib';
import create from 'zustand';
import { devtools } from 'zustand/middleware';

export const useGLTFModel = create<{ readonly model: () => GLTF | undefined }>(
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  devtools((set) => ({
    model: () => undefined
  }))
);

export const useGLTFAnimationAction = create<{ readonly animationAction: () => AnimationAction[] | undefined }>(
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
  devtools((set) => ({
    animationAction: () => undefined
  }))
);

interface ModelProps {
  readonly gltfPath: string;
  readonly onLoad: () => void;
}

const Model: FC<ModelProps> = ({ gltfPath, onLoad }) => {
  const model = useGLTF(gltfPath, undefined, undefined, (loader: GLTFLoader) => {
    loader.manager.onLoad = onLoad;
  });

  // Refs
  const rootRef = useRef();
  const animationActionsRef = useRef<AnimationAction[]>();

  // Mixer
  const [mixer] = useState(() => new AnimationMixer(model.scene));
  useFrame((_state, delta) => mixer.update(delta));

  // Effects
  useEffect(() => {
    useGLTFModel.setState({ model: () => model });

    animationActionsRef.current = model.animations.map((animation) => mixer.clipAction(animation, rootRef.current));
    useGLTFAnimationAction.setState({ animationAction: () => animationActionsRef.current });

    return () => {
      model.animations.map((animation) => mixer.uncacheClip(animation));
    };
  }, [model, mixer]);

  return <primitive ref={rootRef.current} object={model.scene} />;
};

const Progress = () => {
  const { progress } = useProgress();
  return (
    <Html center>
      <span style={{ color: 'white' }}>{progress}% loaded</span>
    </Html>
  );
};

const ThreeRenderer: FC<ModelProps> = ({ gltfPath, onLoad }): JSX.Element => {
  const cameraRef = useRef();

  return (
    <Canvas>
      <PerspectiveCamera ref={cameraRef} position={[0, 5, 5]} />
      <OrbitControls camera={cameraRef.current} />
      <ambientLight intensity={0.5} />
      <Suspense fallback={<Progress />}>
        {/* <Environment preset="city" /> */}
        <Model gltfPath={gltfPath} onLoad={onLoad} />
      </Suspense>
    </Canvas>
  );
};

export default ThreeRenderer;
  1. Go to App.tsx and add a Box component from @mui/material.
import React from 'react';
import logo from './logo.svg';
import './App.css';
import {Box} from '@mui/material';

function App() {
  return (
    <div className="App">
      <header className="App-header">
        <img src={logo} className="App-logo" alt="logo" />
        <p>
          Edit <code>src/App.tsx</code> and save to reload.
        </p>
        <a
          className="App-link"
          href="https://reactjs.org"
          target="_blank"
          rel="noopener noreferrer"
        >
          Learn React
        </a>
        <Box>

        </Box>
      </header>
    </div>
  );
}

export default App;
  1. You should see the error appear. What I see:
    image

Context 馃敠

I'm using three js for some 3D components. But they have no relationship with the components I use from MUI. Basically, they are on different branches in the DOM tree. Moreover, I'm not importing both Box types in the same file. My guess is that the TS engine is somewhat caching both Box type representations and then mixes them up in some way or another? That's why in the steps to reproduce I mentioned that a component that uses three types should be added.

Your Environment 馃寧

`npx @mui/envinfo`
  System:
    OS: Windows 10 10.0.19043
  Binaries:
    Node: 16.10.0 - C:\Program Files\nodejs\node.EXE
    Yarn: Not Found
    npm: 7.24.0 - C:\Program Files\nodejs\npm.CMD
  Browsers:
    Chrome: Not Found
    Edge: Spartan (44.19041.1266.0), Chromium (94.0.992.50)
  npmPackages:
    @emotion/react: ^11.5.0 => 11.5.0
    @emotion/styled: ^11.3.0 => 11.3.0
    @mui/core:  5.0.0-alpha.51
    @mui/icons-material: ^5.0.4 => 5.0.4
    @mui/lab: ^5.0.0-alpha.51 => 5.0.0-alpha.51
    @mui/material: ^5.0.4 => 5.0.4
    @mui/private-theming:  5.0.1
    @mui/styled-engine:  5.0.1
    @mui/system: ^5.0.4 => 5.0.4
    @mui/types:  7.0.0
    @mui/utils:  5.0.1
    @types/react: ^17.0.30 => 17.0.30
    react: ^17.0.2 => 17.0.2
    react-dom: ^17.0.2 => 17.0.2
    typescript: ^4.4.4 => 4.4.4

The tsconfig that I use:

{
  "compilerOptions": {
    "target": "es5",
    "lib": [
      "dom",
      "dom.iterable",
      "esnext"
    ],
    "allowJs": true,
    "skipLibCheck": true,
    "esModuleInterop": true,
    "allowSyntheticDefaultImports": true,
    "strict": true,
    "forceConsistentCasingInFileNames": true,
    "noFallthroughCasesInSwitch": true,
    "module": "esnext",
    "moduleResolution": "node",
    "resolveJsonModule": true,
    "isolatedModules": true,
    "noEmit": true,
    "jsx": "react-jsx"
  },
  "include": [
    "src"
  ]
}

I'm using the tsversion from the node modules, i.e. v4.4.4.

NOTE

I did not manage to reproduce this issue in codesandbox. Probably they're using a different TS version and I saw that I'm not able to change it and use the one I want.

@vivere-dally vivere-dally added the status: waiting for maintainer These issues haven't been looked at yet by a maintainer label Oct 20, 2021
@FlyingTigerReally
Copy link

I have the same problem
I'm also using react three / Drei
Box has been unable to use!!

@mnajdova
Copy link
Member

Can you please share a repository/codesandbox that we can take a look into?

@mnajdova mnajdova added status: waiting for author Issue with insufficient information and removed status: waiting for maintainer These issues haven't been looked at yet by a maintainer labels Oct 26, 2021
@Brunoestevaochagas
Copy link

Can you please share a repository/codesandbox that we can take a look into?

https://codesandbox.io/s/ecstatic-leakey-k0nrj?file=/src/App.tsx

image

@kenianbei
Copy link

Same issue, though adding a component="div" to Box fixes it.

@Q16solver
Copy link

This seems more like a workaround than a fix, I don't think I would want to add this to hundreds of my Box components just because I wanted to use the react-three package. Is it possible to have an actual fix for this from mui's side? Or does it have to be from react-three's side

@mayteio
Copy link

mayteio commented Apr 7, 2022

It appears this has been solved in a recent (~ December) release. Are any of the maintainers able to point me in the direction of what fixed it? We're having the same issue with @chakra-ui/react and I'd love to fix it there too 馃憤馃徎

@adc0de
Copy link

adc0de commented Feb 27, 2023

Same issue, though adding a component="div" to Box fixes it.

While this approach provide a bit of assistance, it does not a complete solution to the issue at hand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting for author Issue with insufficient information
Projects
None yet
Development

No branches or pull requests

9 participants