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

Commit

Permalink
[Metro] Fix for 191.3, courtesy of pylix
Browse files Browse the repository at this point in the history
Co-authored-by: Amsyar Rasyiq <82711525+amsyarasyiq@users.noreply.github.com>
  • Loading branch information
maisymoe and pylixonly committed Aug 4, 2023
1 parent cf09dbc commit 06dee4c
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/lib/metro/filters.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
import { MetroModules, PropsFinder, PropsFinderAll } from "@types";
import { instead } from "@lib/patcher";

// Metro require
declare const __r: (moduleId: number) => any;

// Internal Metro error reporting logic
const originalHandler = window.ErrorUtils.getGlobalHandler();

// Function to blacklist a module, preventing it from being searched again
const blacklist = (id: number) => Object.defineProperty(window.modules, id, {
value: window.modules[id],
Expand Down Expand Up @@ -30,8 +34,12 @@ const filterModules = (modules: MetroModules, single = false) => (filter: (m: an
const id = Number(key);
const module = modules[id]?.publicModule?.exports;

// HACK: Override the function used to report fatal JavaScript errors (that crash the app) to prevent module-requiring side effects
// Credit to @pylixonly (492949202121261067) for the initial version of this fix
if (!modules[id].isInitialized) try {
window.ErrorUtils.setGlobalHandler(() => {});
__r(id);
window.ErrorUtils.setGlobalHandler(originalHandler);
} catch {}

if (!module) {
Expand Down Expand Up @@ -71,4 +79,4 @@ export const findByDisplayName = (displayName: string, defaultExp = true) => fin
export const findByDisplayNameAll = (displayName: string, defaultExp = true) => findAll(dNameFilter(displayName, defaultExp));
export const findByTypeName = (typeName: string, defaultExp = true) => find(tNameFilter(typeName, defaultExp));
export const findByTypeNameAll = (typeName: string, defaultExp = true) => findAll(tNameFilter(typeName, defaultExp));
export const findByStoreName = (name: string) => find(storeFilter(name));
export const findByStoreName = (name: string) => find(storeFilter(name));

0 comments on commit 06dee4c

Please sign in to comment.