pmndrs / react-three-fiber

🇨🇭 A React renderer for Three.js
https://docs.pmnd.rs/react-three-fiber
MIT License
27.62k stars 1.6k forks source link

TypeError: Cannot read properties of undefined (reading 'removeEventListener') during run testing library react #3371

Closed jjuszkiewicz closed 1 month ago

jjuszkiewicz commented 1 month ago

Hello, in version 8.17.9 appear below error. Error appears during run tests by testing library react:

TypeError: Cannot read properties of undefined (reading 'removeEventListener') at removeListeners (../../node_modules/.pnpm/@react-three+fiber@8.17.9_react-dom@18.2.0_react@18.2.0__react@18.2.0_three@0.153.0/node_modules/@react-three/fiber/dist/react-three-fiber.cjs.dev.js:138:26)

Looks like the problem is in this code:

if (state.current.orientationHandler) {
  screen.orientation.removeEventListener('orientationchange', state.current.orientationHandler);
}

The version 8.17.8 works fine.

Could you verify on your side?

DennisSmolek commented 1 month ago

I’ve heard this is on Linux too. Either they don’t have a screen global or no orientation prop.

I’ll work on a pr of this

dll21 commented 1 month ago

Hey, I get the following error with the Canvas component, while testing my app on iOS safari. TypeError: undefined is not an object (evaluating ‘screen.orientation.removeEventListener’)

It might be related to the issue you're facing @jjuszkiewicz

Also switching to version 8.17.8 didn't resolve the problem

It seems like the screen.orientation API is being called in the iOS environment, but it’s not supported there. see issue https://github.com/akamai/boomerang/issues/214

dll21 commented 1 month ago

@DennisSmolek commenting the screen.orientation code fix the issue

https://github.com/pmndrs/react-three-fiber/blob/e5f96f97acb6c5bfcb57c0debd4607953c6a6d35/packages/fiber/src/web/use-measure.ts#L135C4-L135C81