fix: BackHandler crash on RN 0.79+ — replace react-native-modal with core Modal - #61
shaiunterslak wants to merge 1 commit into
Conversation
… RN 0.79+) react-native-modal 13.0.1 still calls BackHandler.removeEventListener in componentWillUnmount; React Native deprecated it in 0.77 and removed it, so closing the widget crashes any app on RN 0.79+ / Expo SDK 53+ (chatwoot#52). A dependency bump is not clean: 13.0.2 is deprecated on npm as "mistakenly released" (so ^13.0.1 keeps resolving to 13.0.1) and 14.x is still an RC. The widget only uses a full-screen modal with four props, so React Native's built-in Modal covers it with zero dependencies: - isVisible -> visible - onBackButtonPress -> onRequestClose (Android back) - slideInUp default -> animationType="slide" - coverScreen/backdropColor/margin:0 -> unnecessary (full-screen Modal) onBackdropPress is dropped: a coverScreen full-screen modal has no visible backdrop to press. This also removes the react-native-modal / react-native-animatable subtree from consumers. Verified with render tests in an RN 0.81 jest environment: mounts with the webview, Android back triggers closeModal, and unmounting no longer crashes. Fixes chatwoot#52
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: d80555e205
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
| "dependencies": { | ||
| "react-native-modal": "^13.0.1" | ||
| }, | ||
| "peerDependencies": { |
There was a problem hiding this comment.
Add prop-types as a direct dependency
Removing the only runtime dependencies block also removes the transitive provider for prop-types, but the published entry path still imports prop-types from src/App.js and src/WebView.js. In a fresh consumer app that does not already install prop-types, Metro will fail to resolve the widget immediately after this package is imported; add prop-types as a direct dependency or remove those runtime imports.
Useful? React with 👍 / 👎.
Fixes #52 (same crash as the accidentally-closed #53).
Problem
react-native-modal@13.0.1still callsBackHandler.removeEventListenerincomponentWillUnmount. React Native deprecated it in 0.77 and has since removed it, so closing the widget crashes any app on RN 0.79+ / Expo SDK 53+:Today every consumer has to carry a patch-package fix for this (we run this widget in four production apps and each one needs the patch).
Why not bump react-native-modal
13.0.2contains the fix but is deprecated on npm as "mistakenly released", which is exactly why the current^13.0.1range keeps resolving to the broken13.0.1.14.xonly exists as release candidates (14.0.0-rc.1), and the library is in low-maintenance mode.Fix
The widget only renders a full-screen modal and uses four props, all of which React Native's built-in
Modalcovers — so this drops the dependency entirely:isVisiblevisibleonBackButtonPressonRequestClose(Android back)slideInUp/slideOutDownanimationType="slide"coverScreen,backdropColor,margin: 0styleonBackdropPressis dropped: withcoverScreen+ full-screen styling there is no visible backdrop to press, so it was dead code. Consumers also lose thereact-native-modal+react-native-animatablesubtree from their installs, and the patch-package workaround becomes unnecessary.Example/carries a vendored copy of the same component, so it gets the same change; itspackage-lock.jsonalso picks up the pre-existing^0.0.20manifest sync.Testing
onRequestClosefirescloseModal, and unmounting no longer crashes (the old crash fired incomponentWillUnmount).eslintclean on the changed files.🤖 Generated with Claude Code