Skip to content

Commit

Permalink
fix(RTTR): set initial size for NaN in viewport (#3137)
Browse files Browse the repository at this point in the history
  • Loading branch information
AbsharHassan authored and krispya committed Mar 20, 2024
1 parent e07fccf commit 037b5f9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/test-renderer/src/__tests__/RTTR.hooks.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ describe('ReactThreeTestRenderer Hooks', () => {
return <group />
}

await ReactThreeTestRenderer.create(<Component />)
await ReactThreeTestRenderer.create(<Component />, { width: 1280, height: 800 })

expect(result.camera instanceof THREE.Camera).toBeTruthy()
expect(result.scene instanceof THREE.Scene).toBeTruthy()
expect(result.raycaster instanceof THREE.Raycaster).toBeTruthy()
expect(result.size).toEqual({ height: 0, width: 0, top: 0, left: 0 })
expect(result.size).toEqual({ height: 800, width: 1280, top: 0, left: 0 })
})

it('can handle useLoader hook', async () => {
Expand Down
13 changes: 12 additions & 1 deletion packages/test-renderer/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,18 @@ extend(THREE as any)
const create = async (element: React.ReactNode, options?: Partial<CreateOptions>): Promise<Renderer> => {
const canvas = createCanvas(options)

const _root = createRoot(canvas).configure({ frameloop: 'never', ...options, events: undefined })
const _root = createRoot(canvas).configure({
frameloop: 'never',
// TODO: remove and use default behavior
size: {
width: options?.width ?? 1280,
height: options?.height ?? 800,
top: 0,
left: 0,
},
...options,
events: undefined,
})
const _store = mockRoots.get(canvas)!.store

await act(async () => _root.render(element))
Expand Down

0 comments on commit 037b5f9

Please sign in to comment.