-
Notifications
You must be signed in to change notification settings - Fork 614
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
Bridgeless Mode support (New Architecture) [0.74] #1769
Comments
Have you been able to make it work even with the bridge on 74? On Android there is no longer |
@radex do you think you can take a look at this to solve the breaking change introduced by RN 74 ? |
|
@angelo-hub Any progress on this one? |
@enahum Is there any progress on this issue? I have the same problem. |
@radex any plan for new arch? |
@radex Can we get an answer in this thread? |
Yes, sorry for staying quiet about it. Yes, I'm planning to work on this likely in August. |
Hey @radex - I am happy to help with chores and low hanging fruit re new architecture support. Not my area of expertise but if there is a pull request I will contribute |
I'm happy to help too |
I got it working on 0.74.5 (with bridge) with this patch, it reverts the deprecation and removes BridgelessCatalystInstance.kt. It might be possible to do the same with 0.75, but it will be more difficult because there they actually removed the JSIModule stuff. I might try it later though Be sure to enable building from source on Android (android/settings.gradle): includeBuild('../node_modules/react-native') {
dependencySubstitution {
substitute(module("com.facebook.react:react-android")).using(project(":packages:react-native:ReactAndroid"))
substitute(module("com.facebook.react:react-native")).using(project(":packages:react-native:ReactAndroid"))
substitute(module("com.facebook.react:hermes-android")).using(project(":packages:react-native:ReactAndroid:hermes-engine"))
substitute(module("com.facebook.react:hermes-engine")).using(project(":packages:react-native:ReactAndroid:hermes-engine"))
}
} The patch:
Really frustrating that the RN changelog mentions that this was unused in open source, idk how they missed this huge repo |
@radex Could you update how you see the progress of this work? We're trying to get the app ready for the new architecture as of version 0.76 and are looking for issues among the key libraries. Without watermelonDB it probably won't be possible, so any information about the progress/plans would be super valuable. Maybe someone advanced from the community would be able to help solve some problems. |
Hi, Any update on solution for this? |
WatermelonDB JSI module can be registered like this in React Native 0.74+: MainApplication.kt import others....
import com.facebook.react.ReactInstanceManager
import com.nozbe.watermelondb.jsi.JSIInstaller
import com.facebook.react.bridge.ReactContext
import com.facebook.react.bridge.UiThreadUtil
class MainApplication : Application(), ReactApplication {
....
private var listenerAdded = false
override fun onCreate() {
super.onCreate()
....
registerJSIModules()
}
private fun runOnJSQueueThread(action: () -> Unit) {
reactNativeHost.reactInstanceManager.currentReactContext?.runOnJSQueueThread {
action()
} ?: UiThreadUtil.runOnUiThread {
reactNativeHost.reactInstanceManager.currentReactContext?.runOnJSQueueThread {
action()
}
}
}
@Suppress("DEPRECATION")
private fun registerJSIModules() {
val reactInstanceManager = reactNativeHost.reactInstanceManager
if (!listenerAdded) {
listenerAdded = true
reactInstanceManager.addReactInstanceEventListener(object : ReactInstanceManager.ReactInstanceEventListener {
override fun onReactContextInitialized(context: ReactContext) {
runOnJSQueueThread {
registerWatermelonJSI(context)
}
}
})
}
}
private fun registerWatermelonJSI(context: ReactContext) {
val holder = context.javaScriptContextHolder?.get()
if (holder != null) {
JSIInstaller.install(context, holder)
}
}
} A patch is also required to make JSIInstaller class and methods public. diff --git a/native/android-jsi/src/main/java/com/nozbe/watermelondb/jsi/JSIInstaller.java b/native/android-jsi/src/main/java/com/nozbe/watermelondb/jsi/JSIInstaller.java
index 055cede2f20cd6a75ffb79d156e35396c1438c91..fb7ca33847aa9ad1349b10b35d4e27575e843479 100755
--- a/native/android-jsi/src/main/java/com/nozbe/watermelondb/jsi/JSIInstaller.java
+++ b/native/android-jsi/src/main/java/com/nozbe/watermelondb/jsi/JSIInstaller.java
@@ -1,8 +1,8 @@
package com.nozbe.watermelondb.jsi;
import android.content.Context;
-class JSIInstaller {
- static void install(Context context, long javaScriptContextHolder) {
+public class JSIInstaller {
+ public static void install(Context context, long javaScriptContextHolder) {
JSIInstaller.context = context;
new JSIInstaller().installBinding(javaScriptContextHolder);
Didn't get the time to test this, but probably should work? |
The above works, but I have not tested it with 0.75.x |
I did try the workaround above but it did not work for me.
MainApplication.kt package something.something
import android.app.Application
import android.content.res.Configuration
import com.facebook.react.PackageList
import com.facebook.react.ReactApplication
import com.facebook.react.ReactHost
import com.facebook.react.ReactNativeHost
import com.facebook.react.ReactPackage
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint.load
import com.facebook.react.defaults.DefaultReactHost.getDefaultReactHost
import com.facebook.react.defaults.DefaultReactNativeHost
import com.facebook.soloader.SoLoader
import java.util.Arrays
import com.facebook.react.bridge.JSIModulePackage
import com.facebook.react.bridge.JSIModule
import com.facebook.react.bridge.JSIModuleSpec
import com.facebook.react.bridge.ReactApplicationContext
import com.facebook.react.bridge.JavaScriptContextHolder
import expo.modules.ApplicationLifecycleDispatcher
import expo.modules.ReactNativeHostWrapper
import com.nozbe.watermelondb.jsi.WatermelonDBJSIPackage
import com.facebook.react.ReactInstanceManager
import com.nozbe.watermelondb.jsi.JSIInstaller
import com.facebook.react.bridge.ReactContext
import com.facebook.react.bridge.UiThreadUtil
class MainApplication : Application(), ReactApplication {
private var listenerAdded = false
override val reactNativeHost: ReactNativeHost =
ReactNativeHostWrapper(this, object : DefaultReactNativeHost(this) {
override fun getPackages(): List<ReactPackage> =
PackageList(this).packages.apply {
// Packages that cannot be autolinked yet can be added manually here, for example:
// add(MyReactNativePackage())
}
override fun getJSMainModuleName(): String = "index"
override fun getUseDeveloperSupport(): Boolean = BuildConfig.DEBUG
override val isNewArchEnabled: Boolean = BuildConfig.IS_NEW_ARCHITECTURE_ENABLED
override val isHermesEnabled: Boolean = BuildConfig.IS_HERMES_ENABLED
})
override val reactHost: ReactHost
get() = ReactNativeHostWrapper.createReactHost(applicationContext, reactNativeHost)
override fun onCreate() {
super.onCreate()
SoLoader.init(this, false)
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
// If you opted-in for the New Architecture, we load the native entry point for this app.
load()
}
ApplicationLifecycleDispatcher.onApplicationCreate(this)
registerJSIModules()
}
private fun runOnJSQueueThread(action: () -> Unit) {
reactNativeHost.reactInstanceManager.currentReactContext?.runOnJSQueueThread {
action()
} ?: UiThreadUtil.runOnUiThread {
reactNativeHost.reactInstanceManager.currentReactContext?.runOnJSQueueThread {
action()
}
}
}
@Suppress("DEPRECATION")
private fun registerJSIModules() {
val reactInstanceManager = reactNativeHost.reactInstanceManager
if (!listenerAdded) {
listenerAdded = true
reactInstanceManager.addReactInstanceEventListener(object : ReactInstanceManager.ReactInstanceEventListener {
override fun onReactContextInitialized(context: ReactContext) {
runOnJSQueueThread {
registerWatermelonJSI(context)
}
}
})
}
}
private fun registerWatermelonJSI(context: ReactContext) {
val holder = context.javaScriptContextHolder?.get()
if (holder != null) {
JSIInstaller.install(context, holder)
}
}
override fun onConfigurationChanged(newConfig: Configuration) {
super.onConfigurationChanged(newConfig)
ApplicationLifecycleDispatcher.onConfigurationChanged(this, newConfig)
}
} I also patched WatermelonDB as follows: @nozbe+watermelondb+0.27.1.patch diff --git a/node_modules/@nozbe/watermelondb/native/android-jsi/src/main/java/com/nozbe/watermelondb/jsi/JSIInstaller.java b/node_modules/@nozbe/watermelondb/native/android-jsi/src/main/java/com/nozbe/watermelondb/jsi/JSIInstaller.java
index 055cede..fb7ca33 100755
--- a/node_modules/@nozbe/watermelondb/native/android-jsi/src/main/java/com/nozbe/watermelondb/jsi/JSIInstaller.java
+++ b/node_modules/@nozbe/watermelondb/native/android-jsi/src/main/java/com/nozbe/watermelondb/jsi/JSIInstaller.java
@@ -1,8 +1,8 @@
package com.nozbe.watermelondb.jsi;
import android.content.Context;
-class JSIInstaller {
- static void install(Context context, long javaScriptContextHolder) {
+public class JSIInstaller {
+ public static void install(Context context, long javaScriptContextHolder) {
JSIInstaller.context = context;
new JSIInstaller().installBinding(javaScriptContextHolder); I have also verified that all the changes stated in JSI setup on https://watermelondb.dev/docs/Installation#android-react-native are applied. Any help will be greatly appreciated. Thank youu! :) |
@ishan-chhabra Do you have JSI enabled in your adapter? const adapter = new SQLiteAdapter({
schema,
migrations,
jsi: true,
}) |
@prathameshmm02 JSI SQLiteAdapter not available… falling back to asynchronous operation. This will happen if you're using remote debugger, and may happen if you forgot to recompile native app after WatermelonDB update |
Have you followed JSI installation docs in Android section given here? After doing that, recompile your app and it should work fine. |
How to implement this.it show override nothing error `// ...
} |
Looks like this library is no longer supported. Very sad news. |
yeah if you want to continue using SQL on react-native recommend the |
Has anyone thought about migrating to a new library? Currently eyeing https://github.com/OP-Engineering/op-sqlite however not sure how stable it is and also it will be a pain to have to do migration... |
i’m in their discord their talking about rust seems like passionate folks
Angelo Girardi
Full-Stack Developer
c: 216-785-7619
…On Mon, Nov 18, 2024 at 21:11 elsa17z ***@***.***> wrote:
Has anyone thought about migrating to a new library? Currently eyeing
https://github.com/OP-Engineering/op-sqlite however not sure how stable
it is and also it will be a pain to have to do migration...
—
Reply to this email directly, view it on GitHub
<#1769 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AC374QQSE4HGWOMZBLEQOR32BLCARAVCNFSM6AAAAABGDANGX6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIOBUG4ZDGMBSHA>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Have you had any thoughts on a strategy for migrating to something like expo-sqlite could be done for existing apps? |
I would very much rather not migrate. It is always a risk, but if I am forced to do it I would suggest migrating it by initially migrating only 1 table with a fallback value provider function. Kind of like maintaining a replica and you should write to both databases, then once you are sure it works switch to it completely. |
Agreed I would rather not but fear it might be required. In any case, moving that discussion to #1861 |
Hi everyone, Apologies for the long time with no updates. Unfortunately, I have not been able to find enough time recently to work on WatermelonDB. I'm very sorry about promising/suggesting that this would be done in August given that I was not able to deliver on that promise. I have a new pre-release version: v0.28.0-1 - that should fix building of the project on Android/JSI. Note that you need to move Feedback on the pre-release would be appreciated! |
I can confirm v0.28.0-1 is working in our product with react-native: 0.76.3 old arch with db jsi enabled. At first glance, it looks like it's working properly 👍 |
will this also work on the 0.76+ new arch and jsi enabled ? because i am getting strange errors like this when i reload the app @radex can you confirm this please. Using pre-release version 0.28.1 |
In Expo SDK 52, React Native 0.76, New Arch Enable and JSI Disable on Android, i receiving this message in android: Diagnostic error: NativeModules.WMDatabaseBridge is not defined! This means that you haven't properly linked WatermelonDB native module. Refer to docs for instructions about installation (and the changelog if this happened after an upgrade). I implemented manual link described in Installation.MDX, I try to update my application to the new arch. |
Did it work with the manual link? |
No. |
I had managed to use it without newArch, for the link on Android I installed @react-native-community/cli and added EXPO_USE_COMMUNITY_AUTOLINKING=1 as suggested in the expo documentation, but my app randomly stopped working. Expo Autolinking: https://docs.expo.dev/modules/autolinking/#opting-out-of-expo-autolinking |
anyone gotten this to link properly on android yet? still getting
|
@radex I am also getting the same error. Could you please provide a fix for this? |
@radex any rough idea on when the new arch will be supported? What is left to be done that maybe anyone here could help with? |
Is anyone having issues with the pre-release? i have been using it on a group of beta testers for a week now and is working fine. Setup: |
@clmoreno having issue with react Native cli |
Fix for Bridgeless Architecture Error on App ReloadIf you're running into the following error with the new architecture when reloading your app:
This issue arises because the new Bridgeless architecture does not support SolutionThe fix involves replacing diff --git a/native/android/src/main/java/com/nozbe/watermelondb/WMDatabaseBridge.java b/native/android/src/main/java/com/nozbe/watermelondb/WMDatabaseBridge.java
index 117b2bc1f75217c685bc9cfa76b4e55b22e015dc..a678d5d1715d633c4518a04b11fd1198c53157e9 100644
--- a/native/android/src/main/java/com/nozbe/watermelondb/WMDatabaseBridge.java
+++ b/native/android/src/main/java/com/nozbe/watermelondb/WMDatabaseBridge.java
@@ -248,7 +248,7 @@ public class WMDatabaseBridge extends ReactContextBaseJavaModule {
public void invalidate() {
// NOTE: See Database::install() for explanation
super.invalidate();
- reactContext.getCatalystInstance().getReactQueueConfiguration().getJSQueueThread().runOnQueue(() -> {
+ reactContext.runOnJSQueueThread(() -> {
try {
Class<?> clazz = Class.forName("com.nozbe.watermelondb.jsi.WatermelonJSI");
Method method = clazz.getDeclaredMethod("onCatalystInstanceDestroy");
I’ve submitted a pull request with this fix and would appreciate it being merged. Hope this helps! |
Is it cleaner to use |
@dppo You're right, and |
@limbo56 will this change also work with react native 0.76.0 and watermelon db version 0.28.1-1? |
@saurabhsaneja Yes, I'm running React Native 0.76.6 and WatermelonDB 0.28.0-1, and that change resolved the issue. |
@limbo56 thanks |
Are you using it with newArch enabled? |
@Rohit3523 Yes |
@limbo56 are you importing com.nozbe.watermelondb.jsi.WatermelonDBJSIPackage in MainApplication.kt file and adding it like this: packages.add(WatermelonDBJSIPackage()) or are you importing com.nozbe.watermelondb.jsi.JSIInstaller and registering it using registerWatermelonJSI method like @prathameshmm02 mentioned when i am importing com.nozbe.watermelondb.jsi.WatermelonDBJSIPackage like this, i am getting NativeModules.WMDatabaseBridge is not defined error also, are you linking watermelon db manually or linking it using JSI installation (Optional, recommended) like mentioned in documention link below: Post-thought: I think you are not installing watermelon db with jsi |
@saurabhspinny Apologies for getting back so late. I am installing WatermelonDB with JSI. Here's what I did:
If you're running into the For reference, I’m using a bare workflow Expo project with SDK 52. |
@limbo56 Hey, thanks for getting back. I was able to make it work with manual linking and changing just one line of watermelon db like you mentioned. Maybe for react native cli project 0.76 version, jsi installation has issues @Rohit3523 |
Bridgeless Mode is going to be default in 0.74 can offer some bandwidth to migrate to bridgeless mode as this is a super cool project
The text was updated successfully, but these errors were encountered: