bring back the MMKV patch

This commit is contained in:
Samuel Newman
2025-09-12 16:35:56 +03:00
parent 31a74f8d31
commit 35414b82c1
2 changed files with 94 additions and 0 deletions
+91
View File
@@ -0,0 +1,91 @@
diff --git a/node_modules/react-native-mmkv/lib/commonjs/createMMKV.js b/node_modules/react-native-mmkv/lib/commonjs/createMMKV.js
index b9b9d69..9ec36f9 100644
--- a/node_modules/react-native-mmkv/lib/commonjs/createMMKV.js
+++ b/node_modules/react-native-mmkv/lib/commonjs/createMMKV.js
@@ -38,8 +38,8 @@ const createMMKV = config => {
}
// Check if we are running on-device (JSI)
- if (global.nativeCallSyncHook == null || MMKVModule.install == null) {
- throw new Error('Failed to create a new MMKV instance: React Native is not running on-device. MMKV can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead.');
+ if (isRemoteDebuggingInChrome() || MMKVModule.install == null) {
+ throw new Error(`Failed to create a new MMKV instance: React Native is not running on-device. MMKV can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead. isRemoteDebuggingInChrome(): ${isRemoteDebuggingInChrome()}; MMKVModule.install == null: ${MMKVModule.install == null}`);
}
// Call the synchronous blocking install() function
@@ -51,5 +51,13 @@ const createMMKV = config => {
}
return global.mmkvCreateNewInstance(config);
};
+function isRemoteDebuggingInChrome() {
+ // Remote debugging in Chrome is not supported in bridgeless
+ if ('RN$Bridgeless' in global && RN$Bridgeless === true) {
+ return false;
+ }
+
+ return __DEV__ && typeof global.nativeCallSyncHook === 'undefined';
+}
exports.createMMKV = createMMKV;
//# sourceMappingURL=createMMKV.js.map
diff --git a/node_modules/react-native-mmkv/lib/module/createMMKV.js b/node_modules/react-native-mmkv/lib/module/createMMKV.js
index 644840d..6e704d6 100644
--- a/node_modules/react-native-mmkv/lib/module/createMMKV.js
+++ b/node_modules/react-native-mmkv/lib/module/createMMKV.js
@@ -32,8 +32,8 @@ export const createMMKV = config => {
}
// Check if we are running on-device (JSI)
- if (global.nativeCallSyncHook == null || MMKVModule.install == null) {
- throw new Error('Failed to create a new MMKV instance: React Native is not running on-device. MMKV can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead.');
+ if (isRemoteDebuggingInChrome() || MMKVModule.install == null) {
+ throw new Error(`Failed to create a new MMKV instance: React Native is not running on-device. MMKV can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead. isRemoteDebuggingInChrome(): ${isRemoteDebuggingInChrome()}; MMKVModule.install == null: ${MMKVModule.install == null}`);
}
// Call the synchronous blocking install() function
@@ -45,4 +45,13 @@ export const createMMKV = config => {
}
return global.mmkvCreateNewInstance(config);
};
+
+function isRemoteDebuggingInChrome() {
+ // Remote debugging in Chrome is not supported in bridgeless
+ if ('RN$Bridgeless' in global && RN$Bridgeless === true) {
+ return false;
+ }
+
+ return __DEV__ && typeof global.nativeCallSyncHook === 'undefined';
+}
//# sourceMappingURL=createMMKV.js.map
diff --git a/node_modules/react-native-mmkv/src/createMMKV.ts b/node_modules/react-native-mmkv/src/createMMKV.ts
index 15d29a0..55675fd 100644
--- a/node_modules/react-native-mmkv/src/createMMKV.ts
+++ b/node_modules/react-native-mmkv/src/createMMKV.ts
@@ -46,9 +46,9 @@ export const createMMKV = (config: MMKVConfiguration): NativeMMKV => {
}
// Check if we are running on-device (JSI)
- if (global.nativeCallSyncHook == null || MMKVModule.install == null) {
+ if (isRemoteDebuggingInChrome() || MMKVModule.install == null) {
throw new Error(
- 'Failed to create a new MMKV instance: React Native is not running on-device. MMKV can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead.'
+ `Failed to create a new MMKV instance: React Native is not running on-device. MMKV can only be used when synchronous method invocations (JSI) are possible. If you are using a remote debugger (e.g. Chrome), switch to an on-device debugger (e.g. Flipper) instead. isRemoteDebuggingInChrome(): ${isRemoteDebuggingInChrome()}; MMKVModule.install == null: ${MMKVModule.install == null}`
);
}
@@ -68,3 +68,16 @@ export const createMMKV = (config: MMKVConfiguration): NativeMMKV => {
return global.mmkvCreateNewInstance(config);
};
+
+declare global {
+ const RN$Bridgeless: boolean;
+}
+
+function isRemoteDebuggingInChrome() {
+ // Remote debugging in Chrome is not supported in bridgeless
+ if ('RN$Bridgeless' in global && RN$Bridgeless === true) {
+ return false;
+ }
+
+ return __DEV__ && typeof global.nativeCallSyncHook === 'undefined';
+}
@@ -0,0 +1,3 @@
# react-native-mmkv+2.12.2.patch.md
Patch of https://github.com/mrousavy/react-native-mmkv/pull/778