From 0aa8c62980fdbe6d822b8488572d2d3b2a3286bf Mon Sep 17 00:00:00 2001 From: Kenneth Geisshirt Date: Fri, 12 Apr 2024 16:03:13 +0200 Subject: [PATCH 1/4] Clear internal state to avoid crashes when React Native app is reloaded --- CHANGELOG.md | 1 + packages/realm/src/Realm.ts | 6 +++++- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 78bdd0d00f..63155cf2fd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,6 +37,7 @@ * `data` and `string` are now strongly typed for comparisons and queries. This change is especially relevant when querying for a string constant on a Mixed property, as now only strings will be returned. If searching for `data` is desired, then that type must be specified by the constant. In RQL the new way to specify a binary constant is to use `mixed = bin('xyz')` or `mixed = binary('xyz')`. ([realm/realm-core#6407](https://github.com/realm/realm-core/issues/6407)) * Fixed diverging history due to a bug in the replication code when setting default null values (embedded objects included). ([realm/realm-core#7536](https://github.com/realm/realm-core/issues/7536)) * Null pointer exception may be triggered when logging out and async commits callbacks not executed. ([realm/realm-core#7434](https://github.com/realm/realm-core/issues/7434), since v12.6.0) +* Fixed a bug when caused crashes when reloading React Native apps. ([#6579](https://github.com/realm/realm-js/issues/6579), since v12.0.0) ### Compatibility * React Native >= v0.71.4 diff --git a/packages/realm/src/Realm.ts b/packages/realm/src/Realm.ts index 1395c2ec33..eb08ee46ac 100644 --- a/packages/realm/src/Realm.ts +++ b/packages/realm/src/Realm.ts @@ -1360,6 +1360,10 @@ export namespace Realm { export import PushClient = internal.PushClient; } -//Set default logger and log level. +// Clear the internal state to prevent crashes when reloading on React Native +binding.RealmCoordinator.clearAllCaches(); +binding.App.clearCachedApps(); + +// Set default logger and log level. Realm.setLogger(defaultLogger); Realm.setLogLevel(defaultLoggerLevel); From 20df0888506516af8dbe15ac6e47de4434ec9234 Mon Sep 17 00:00:00 2001 From: Kenneth Geisshirt Date: Mon, 15 Apr 2024 16:01:17 +0200 Subject: [PATCH 2/4] PR feedback --- packages/realm/src/Realm.ts | 4 ---- packages/realm/src/platform/react-native/index.ts | 4 ++++ 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/realm/src/Realm.ts b/packages/realm/src/Realm.ts index eb08ee46ac..5ed5aab8e7 100644 --- a/packages/realm/src/Realm.ts +++ b/packages/realm/src/Realm.ts @@ -1360,10 +1360,6 @@ export namespace Realm { export import PushClient = internal.PushClient; } -// Clear the internal state to prevent crashes when reloading on React Native -binding.RealmCoordinator.clearAllCaches(); -binding.App.clearCachedApps(); - // Set default logger and log level. Realm.setLogger(defaultLogger); Realm.setLogLevel(defaultLoggerLevel); diff --git a/packages/realm/src/platform/react-native/index.ts b/packages/realm/src/platform/react-native/index.ts index 6974fd57a2..1c564dd1cf 100644 --- a/packages/realm/src/platform/react-native/index.ts +++ b/packages/realm/src/platform/react-native/index.ts @@ -22,5 +22,9 @@ import "./fs"; import "./device-info"; import "./sync-proxy-config"; +// Clear the internal state to prevent crashes when reloading the app +binding.RealmCoordinator.clearAllCaches(); +binding.App.clearCachedApps(); + import { Realm } from "../../Realm"; export = Realm; From a80cd1091166bbc87baff38e4a421c6ca465f103 Mon Sep 17 00:00:00 2001 From: Kenneth Geisshirt Date: Mon, 15 Apr 2024 10:18:02 +0200 Subject: [PATCH 3/4] Update CHANGELOG.md Co-authored-by: LJ <81748770+elle-j@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 63155cf2fd..ddd9b6daf1 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -37,7 +37,7 @@ * `data` and `string` are now strongly typed for comparisons and queries. This change is especially relevant when querying for a string constant on a Mixed property, as now only strings will be returned. If searching for `data` is desired, then that type must be specified by the constant. In RQL the new way to specify a binary constant is to use `mixed = bin('xyz')` or `mixed = binary('xyz')`. ([realm/realm-core#6407](https://github.com/realm/realm-core/issues/6407)) * Fixed diverging history due to a bug in the replication code when setting default null values (embedded objects included). ([realm/realm-core#7536](https://github.com/realm/realm-core/issues/7536)) * Null pointer exception may be triggered when logging out and async commits callbacks not executed. ([realm/realm-core#7434](https://github.com/realm/realm-core/issues/7434), since v12.6.0) -* Fixed a bug when caused crashes when reloading React Native apps. ([#6579](https://github.com/realm/realm-js/issues/6579), since v12.0.0) +* Fixed a bug which caused crashes when reloading React Native apps. ([#6579](https://github.com/realm/realm-js/issues/6579), since v12.0.0) ### Compatibility * React Native >= v0.71.4 From fe65839b96b16485599d961dde796e3e3146ead9 Mon Sep 17 00:00:00 2001 From: Kenneth Geisshirt Date: Tue, 16 Apr 2024 10:38:17 +0200 Subject: [PATCH 4/4] Fix linting --- packages/realm/src/platform/react-native/index.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/packages/realm/src/platform/react-native/index.ts b/packages/realm/src/platform/react-native/index.ts index 1c564dd1cf..4eff6da924 100644 --- a/packages/realm/src/platform/react-native/index.ts +++ b/packages/realm/src/platform/react-native/index.ts @@ -22,9 +22,11 @@ import "./fs"; import "./device-info"; import "./sync-proxy-config"; +import { Realm } from "../../Realm"; +import { binding } from "../binding"; + // Clear the internal state to prevent crashes when reloading the app binding.RealmCoordinator.clearAllCaches(); binding.App.clearCachedApps(); -import { Realm } from "../../Realm"; export = Realm;