11import { MetroModules , PropsFinder , PropsFinderAll } from "@types" ;
2+ import { instead } from "@lib/patcher" ;
23
34// Metro require
45declare const __r : ( moduleId : number ) => any ;
56
7+ // Internal Metro error reporting logic
8+ const originalHandler = window . ErrorUtils . getGlobalHandler ( ) ;
9+
610// Function to blacklist a module, preventing it from being searched again
711const blacklist = ( id : number ) => Object . defineProperty ( window . modules , id , {
812 value : window . modules [ id ] ,
@@ -30,8 +34,12 @@ const filterModules = (modules: MetroModules, single = false) => (filter: (m: an
3034 const id = Number ( key ) ;
3135 const module = modules [ id ] ?. publicModule ?. exports ;
3236
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
3339 if ( ! modules [ id ] . isInitialized ) try {
40+ window . ErrorUtils . setGlobalHandler ( ( ) => { } ) ;
3441 __r ( id ) ;
42+ window . ErrorUtils . setGlobalHandler ( originalHandler ) ;
3543 } catch { }
3644
3745 if ( ! module ) {
@@ -71,4 +79,4 @@ export const findByDisplayName = (displayName: string, defaultExp = true) => fin
7179export const findByDisplayNameAll = ( displayName : string , defaultExp = true ) => findAll ( dNameFilter ( displayName , defaultExp ) ) ;
7280export const findByTypeName = ( typeName : string , defaultExp = true ) => find ( tNameFilter ( typeName , defaultExp ) ) ;
7381export 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