Skip to content
This repository was archived by the owner on Feb 6, 2024. It is now read-only.

Commit 4e9934f

Browse files
committed
[Metro] Fix for 191.3, courtesy of pylix
Co-authored-by: [email protected]
1 parent cf09dbc commit 4e9934f

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

src/lib/metro/filters.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import { MetroModules, PropsFinder, PropsFinderAll } from "@types";
2+
import { instead } from "@lib/patcher";
23

34
// Metro require
45
declare 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
711
const 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
7179
export const findByDisplayNameAll = (displayName: string, defaultExp = true) => findAll(dNameFilter(displayName, defaultExp));
7280
export const findByTypeName = (typeName: string, defaultExp = true) => find(tNameFilter(typeName, defaultExp));
7381
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

Comments
 (0)