I am removing some specific meshes from the model

I am removing some specific meshes from the model, but it gives error :-
Am doing this
this.bike.traverse((child) => { if (child instanceof THREE.Mesh) { if (child.name === "polySurface1") { child.material.dispose(); child.geometry.dispose(); child.parent.remove(child); console.log("1", child); this.experience.renderer.instance.renderLists.dispose(); } if (child.name === "polySurface2") { child.material.dispose(); child.geometry.dispose(); child.parent.remove(child); console.log("2", child); this.experience.renderer.instance.renderLists.dispose(); } }});

But its giving error:-
Uncaught TypeError: Cannot read properties of undefined (reading ‘traverse’)
at Group.traverse (three.module.js:7690:18)
at Group.traverse (three.module.js:7690:18)

Can anyone help regarding this?

As per docs:

Note: Modifying the scene graph inside the callback is discouraged.

You should not modify (ie. add or remove) children when traversing an object.

I am traversing like this now after pushing the child’s into the seatMeshes array and it worked, But when i check with raycaster, that mesh is still getting triggered.

Is the mesh still Present in the scene or is it some kind of raycaster bug?

for (let i = 0; i < seatMeshes.length; i++) {