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 Jan 2, 2024
1 parent 59d022c commit 6d733ed
Show file tree
Hide file tree
Showing 2 changed files with 15 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 @@ -29,12 +29,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, updateStyle: false })
expect(result.size).toEqual({ height: 800, width: 1280, top: 0, left: 0, updateStyle: true })
})

it('can handle useLoader hook', async () => {
Expand Down
14 changes: 13 additions & 1 deletion packages/test-renderer/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,19 @@ const act = _act as unknown as Act
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,
updateStyle: typeof HTMLCanvasElement !== 'undefined' && canvas instanceof HTMLCanvasElement,
},
...options,
events: undefined,
})
const _store = mockRoots.get(canvas)!.store

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

0 comments on commit 6d733ed

Please sign in to comment.