react icon indicating copy to clipboard operation
react copied to clipboard

fix: Null check added when resolving event's priority

Open classicdocs opened this issue 1 year ago • 5 comments

Summary

I wanted to migrate from React 17 to React 18 and experienced issues with rendering when using new root API.

When window.event is null, Uncaught TypeError: Cannot read properties of null (reading 'type')error can be thrown when calling render function.

✅ Example with React 17 where nothing breaks and component is rendered correctly: https://jsfiddle.net/9zg3t4mc/1/

❌ Example with React 18 where error is thrown and component is not rendered: https://jsfiddle.net/92wtjb0g/

How did you test this change?

I run yarn build and then use React-prod.js inside fiddle that is throwing an error and with this change render is working now. image

classicdocs avatar Sep 24 '24 14:09 classicdocs

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Comments Updated (UTC)
react-compiler-playground ✅ Ready (Inspect) Visit Preview 💬 Add feedback Sep 27, 2024 4:08pm

vercel[bot] avatar Sep 24 '24 14:09 vercel[bot]

Hmm, the repro you provided is overriding a global to be null. I think that shouldn't ever happen in practice, though. Is there a legitimate case in some supported browser where the event can be null as opposed to undefined?

josephsavona avatar Sep 24 '24 15:09 josephsavona

@josephsavona Thanks for quick answer. Yes, indeed it shouldn't be overwritten, but in real world I have experienced that client's app somehow is overriding this and I'm injecting a script into theirs app where I'm rendering react app and it will give me this error.

classicdocs avatar Sep 24 '24 15:09 classicdocs

Fair. This seems reasonable to add, but we also need a regression test. Can you add on here?

josephsavona avatar Sep 27 '24 15:09 josephsavona

@josephsavona I have added a test to cover this case. Cheers

classicdocs avatar Sep 27 '24 16:09 classicdocs

This pull request has been automatically marked as stale. If this pull request is still relevant, please leave any comment (for example, "bump"), and we'll keep it open. We are sorry that we haven't been able to prioritize reviewing it yet. Your contribution is very much appreciated.

github-actions[bot] avatar Dec 26 '24 17:12 github-actions[bot]

Closing this pull request after a prolonged period of inactivity. If this issue is still present in the latest release, please ask for this pull request to be reopened. Thank you!

github-actions[bot] avatar Jan 02 '25 18:01 github-actions[bot]

Any news about merging this PR? I've experienced similar issues to what @classicdocs has described.

okejminja avatar Apr 24 '25 11:04 okejminja

@josephsavona Can we reopen this PR ?

classicdocs avatar May 15 '25 19:05 classicdocs