Handle primitives in test-renderer and fix queries in TestInstances #3507
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Handle primitives in test-renderer and fix queries in TestInstances
Description
This PR addresses two significant issues in the React Three Test Renderer:
Primitive Children Not Visible: Previously, when using
<primitive object={object} />
components, the children of these objects were not visible in the test renderer's output. This made it impossible to test or traverse the full scene graph when primitives were used.Incorrect Query Behavior: The search methods (
findByType
, etc.) were including the current node in search results, which made it difficult to search for nested elements of the same type.Changes
Added Primitive Children Support
createTestInstance.ts
to detect primitive components and include their THREE.js children in the virtual treecreateVirtualInstance
helper that creates instance representations for THREE.js objectsgraph.ts
to properly include primitive children in the scene graph outputFixed Query Methods
Added tests
Other improvements
Note on implementation
I've tried to keep the implementation minimal to address just the specific issues. For the createVirtualInstance function, I couldn't directly import the prepare method from fiber's utils.tsx, so I created a simplified version that follows the same pattern.
I'm happy to make any modification you could suggest to improve the PR if needed.