Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: don't overwrite public cameras #2796

Merged
merged 3 commits into from
Mar 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/fiber/src/core/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ function createRoot<TCanvas extends Canvas>(canvas: TCanvas): ReconcilerRoot<TCa
if (!is.equ(params, raycaster.params, shallowLoose))
applyProps(raycaster as any, { params: { ...raycaster.params, ...params } })

// Create default camera
if (!is.equ(lastCamera, shallowLoose)) {
// Create default camera, don't overwrite any user-set state
if (!state.camera || (state.camera === lastCamera && !is.equ(lastCamera, cameraOptions, shallowLoose))) {
lastCamera = cameraOptions
const isCamera = cameraOptions instanceof THREE.Camera
const camera = isCamera
Expand Down
19 changes: 19 additions & 0 deletions packages/fiber/tests/core/renderer.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -875,4 +875,23 @@ describe('renderer', () => {
expect(one).toBeCalledTimes(1)
expect(two).toBeCalledTimes(0)
})

it("camera props shouldn't overwrite state", async () => {
const camera = new THREE.OrthographicCamera()

function Test() {
const set = useThree((state) => state.set)
React.useMemo(() => set({ camera }), [set])
return null
}

const store = await act(async () => root.render(<Test />))
expect(store.getState().camera).toBe(camera)

root.configure({ camera: { name: 'test' } })

await act(async () => root.render(<Test />))
expect(store.getState().camera).toBe(camera)
expect(camera.name).not.toBe('test')
})
})