1
1
import { MetroModules , PropsFinder , PropsFinderAll } from "@types" ;
2
+ import { instead } from "@lib/patcher" ;
2
3
3
4
// Metro require
4
5
declare const __r : ( moduleId : number ) => any ;
5
6
7
+ // Internal Metro error reporting logic
8
+ const originalHandler = window . ErrorUtils . getGlobalHandler ( ) ;
9
+
6
10
// Function to blacklist a module, preventing it from being searched again
7
11
const blacklist = ( id : number ) => Object . defineProperty ( window . modules , id , {
8
12
value : window . modules [ id ] ,
@@ -30,8 +34,12 @@ const filterModules = (modules: MetroModules, single = false) => (filter: (m: an
30
34
const id = Number ( key ) ;
31
35
const module = modules [ id ] ?. publicModule ?. exports ;
32
36
37
+ // HACK: Override the function used to report fatal JavaScript errors (that crash the app) to prevent module-requiring side effects
38
+ // Credit to @pylixonly (492949202121261067) for the initial version of this fix
33
39
if ( ! modules [ id ] . isInitialized ) try {
40
+ window . ErrorUtils . setGlobalHandler ( ( ) => { } ) ;
34
41
__r ( id ) ;
42
+ window . ErrorUtils . setGlobalHandler ( originalHandler ) ;
35
43
} catch { }
36
44
37
45
if ( ! module ) {
@@ -71,4 +79,4 @@ export const findByDisplayName = (displayName: string, defaultExp = true) => fin
71
79
export const findByDisplayNameAll = ( displayName : string , defaultExp = true ) => findAll ( dNameFilter ( displayName , defaultExp ) ) ;
72
80
export const findByTypeName = ( typeName : string , defaultExp = true ) => find ( tNameFilter ( typeName , defaultExp ) ) ;
73
81
export const findByTypeNameAll = ( typeName : string , defaultExp = true ) => findAll ( tNameFilter ( typeName , defaultExp ) ) ;
74
- export const findByStoreName = ( name : string ) => find ( storeFilter ( name ) ) ;
82
+ export const findByStoreName = ( name : string ) => find ( storeFilter ( name ) ) ;
0 commit comments