pmndrs / react-three-fiber

🇨🇭 A React renderer for Three.js
https://docs.pmnd.rs/react-three-fiber
MIT License
27.62k stars 1.6k forks source link

`findByProps({ name: ... })` returns multiple instances #3339

Open DeepUpRosenthal opened 3 months ago

DeepUpRosenthal commented 3 months ago

My scene-graph (renderer.toGraph()):

‌[
  {
    "type":"Group",
    "name":"MEASUREMENT",
    "children":[
      {
        "type":"Line2",
        "name":"MEASUREMENT-LINE",
        "children":[

        ]
      },
      {
        "type":"Group",
        "name":"MEASUREMENT-TEXT",
        "children":[

        ]
      }
    ]
  },
  {
    "type":"Group",
    "name":"SCANS",
    "children":[
      {
        "type":"Group",
        "name":"SCAN-CENTERED:scan-id-1",
        "children":[
          {
            "type":"Mesh",
            "name":"SCAN:scan-id-1",
            "children":[

            ]
          }
        ]
      },
      {
        "type":"Group",
        "name":"SCAN-CENTERED:scan-id-2",
        "children":[
          {
            "type":"Mesh",
            "name":"SCAN:scan-id-2",
            "children":[

            ]
          }
        ]
      }
    ]
  }
]

Now executing scene.findByProps({ name: "MEASUREMENT-LINE" }) results in an error:

Error: RTTR: Expected 1 but found 2 instances with props: {"name":"MEASUREMENT-LINE"}

This seems to be a bug.

My packages:

"react": "18.3.1",
"react-dom": "18.3.1",
"three": "0.167.1",
"@react-three/drei": "^9.111.2",
"@react-three/fiber": "^8.17.5",
"@react-three/test-renderer": "8.2.1",
"@testing-library/dom": "10.4.0",
"@testing-library/jest-dom": "6.4.8",
"@testing-library/react": "16.0.0",
"@testing-library/user-event": "14.5.2",
"jest": "27.5.1",

Node.js v20.15.0

Can you help me?

DeepUpRosenthal commented 3 months ago

UPDATE: I found the findAll-function under node_modules/@react-three/test-renderer/dist/react-three-test-renderer.cjs.dev.js which is responsible for iterating the tree. There in line 704 it uses root.allChildren.forEach. Switched it to root.children.forEach, which works.

Do you have any idea why?