kirillzyusko / react-native-keyboard-controller

Keyboard manager which works in identical way on both iOS and Android
https://kirillzyusko.github.io/react-native-keyboard-controller/
MIT License
1.8k stars 81 forks source link

[WEB] ReferenceError: setImmediate is not defined #712

Closed devoren closed 6 days ago

devoren commented 1 week ago

Describe the bug I get an error when I use react-native-keyboard-controller on the web. When i open website: If I use it in another page and not in the page that is open, then I can use it when I go to the page where I use react-native-keyboard-controller. But if I reload the tab in those pages that I use react-native-keyboard-controller or the first page uses react-native-keyboard-controller, then it will not have time to initialize somehow and gives an error: ReferenceError: setImmediate is not defined

I USED npx expo export -p web THEN npx serve dist --single (same in the prod)

Code snippet In my case i use KeyboardAwareScrollView

<KeyboardAwareScrollView>
  {children}
</KeyboardAwareScrollView>

Repo for reproducing https://github.com/devoren/rnkc-web-bug

To Reproduce Steps to reproduce the behavior:

  1. Init new expo app
  2. Add RNKC
  3. Build expo web app (npx expo export -p web && npx serve dist --single)
  4. Reload the tab you are in on a page that uses the react-native-keyboard-controller component and See error

Expected behavior Reload without any issues

Screenshots If applicable, add screenshots to help explain your problem. image

Smartphone (please complete the following information):

Additional context This only happens when I build the expo web app via npx expo export -p web and if I use it in development mode it works without any issues.

"web": {
    "bundler": "metro",
    "favicon": "./assets/images/favicon.png"
},

As I see, setImmediate is used once in the codebase: https://github.com/kirillzyusko/react-native-keyboard-controller/blob/737e452faf39e1203d87f877517bd2177cd66ad9/src/internal.ts#L52

I hope that these issues and pulls can help: https://github.com/software-mansion/react-native-reanimated/issues/4140 https://github.com/software-mansion/react-native-reanimated/pull/4276

kirillzyusko commented 1 week ago

Thank you @devoren for issue and all the information ❤️

I'll try to see if I can use queueMicrotask to solve the original problem when I added setImmediate. Thank you again!

kirillzyusko commented 1 week ago

@devoren may I ask you to test https://github.com/kirillzyusko/react-native-keyboard-controller/pull/715 to confirm it fixes the problem?

devoren commented 1 week ago

@kirillzyusko Hey! Ok thank you! I'll try

devoren commented 6 days ago

@kirillzyusko Hello! I think #715 fixed the problem!

kirillzyusko commented 6 days ago

@devoren awesome! Merged it and will publish under 1.15.0 this month 😊