This repository has been archived by the owner on Dec 15, 2021. It is now read-only.
Fix database open failing consistently when reloading the app through the dev menu on Android. #5
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi there, thanks so much for this module! We're finding this super useful so far, really great to have a working leveldown implementation for React Native.
I discovered a slight rough edge in the Android bindings: it's not possible to
open
a database once the app has been reloaded using the dev menu.To reproduce
open
a database.open
the database again (in our case, this is happening automatically on app startup.)Expected
The database opens as usual.
Actual
The following error is thrown:
Strangely, it's not possible to catch this error by wrapping
open
in try/catch. I still need to investigate why that is the case, but I thought it'd be better to fix this first.Solution
onHostDestroy
is a lifecycle event for theReactRootView
activity. We currently close all resources in this method. However, this does not get called when the dev menu reload happens, as the actual root view activity does not get destroyed. Instead, we use theonCatalystInstanceDestroy()
method to trigger this close.In classic React Native style, this isn't documented anywhere, and it took me ages to find out how to intercept this reload event. See facebook/react-native#9773 for similar frustrations. Linked from this I found invertase/react-native-firebase#1535, which implements the same solution.
Hope this makes sense, let me know if there's anything you need me to do to get this released :)