-
Notifications
You must be signed in to change notification settings - Fork 577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
RJS-2784: Clear internal state to avoid crashes when React Native app is reloaded #6612
Conversation
packages/realm/src/Realm.ts
Outdated
//Set default logger and log level. | ||
// Clear the internal state to prevent crashes when reloading on React Native | ||
binding.RealmCoordinator.clearAllCaches(); | ||
binding.App.clearCachedApps(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting approach 👍 I suppose there's a time between the runtime being torn down until this code runs, where there could potentially fire an event which would crash the app 🤔 But ... it's probably a lot better than nothing.
I wonder if it would make sense to simply call the Realm.shutdown
instead? That would also cancel outstanding async open tasks, etc.
Also, since this is relevant only for React Native, it might make sense to move it into the platform specific wrapper:
realm-js/packages/realm/src/platform/react-native/index.ts
Lines 25 to 26 in 5dab798
import { Realm } from "../../Realm"; | |
export = Realm; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting approach
No, just a hack 😄
simply call the
Realm.shutdown
instead
I had an issue with Realm.shutdown
since RealmProgressPromise
is undefined.
move it into the platform specific wrapper
I agree.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've tested this as well with the RN test app (on iOS and Android) and it seems to work. I'm not all that familiar with the ins and outs of this change so I'll leave it up to Kraen to approve 👍
Co-authored-by: LJ <81748770+elle-j@users.noreply.github.com>
Coverage tests crashed with "free(): invalid pointer", and we should investigate it |
* main: Installing dependencies again after checkout [12.7.1] Bump version (#6632) RJS-2806: Upgrade to Realm Core v14.5.2 (#6629) RJS-2804: remove incorrect privacy manifest for iOS (#6627) Adding permissions fix "Resource not accessible by integration" RJS-2143: Tests to clarify number conversion (#6623) Fixing unstable test (#6625) Adding a script to update submodules Update to the new documentation URL (#6597) Prepare for vNext [12.7.0] Bump version (#6622) RJS-2757: Add Apple Privacy Manifest (#6605) RJS-2784: Clear internal state to avoid crashes when React Native app is reloaded (#6612) Use CMake 3.29.2 (#6619) RJS-2801: Upgrade to Realm Core v14.5.1 (#6611)
What, How & Why?
This closes #6579
During development it is common to reload a React Native app. As it is a rough process, it is important to clear the previous state - including listeners. Realm Core provides some low-level method to clear many internal data structures, and by invoking these when the SDK is initialized (loaded in the app), any state from the previous app instance is removed.
Testing is difficult, and I have only tried it manually in a app running locally on my computer.
☑️ ToDos
Compatibility
label is updated or copied from previous entryCOMPATIBILITY.md
package.json
s (if updating internal packages)Breaking
label has been applied or is not necessary