Skip to content

Commit

Permalink
fix(metro/modules): patch registry instead
Browse files Browse the repository at this point in the history
  • Loading branch information
pylixonly committed Sep 4, 2024
1 parent 87913ce commit 4b94b7f
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
1 change: 0 additions & 1 deletion src/entry.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ async function initializeBunny() {
Object.freeze = Object.seal = Object;

await require("@metro/internals/caches").initMetroCache();
require("@metro/internals/modules");
await require(".").default();
} catch (e) {
const { ClientInfoManager } = require("@lib/api/native/modules");
Expand Down
12 changes: 7 additions & 5 deletions src/metro/internals/modules.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ const functionToString = Function.prototype.toString;

let patchedInspectSource = false;
let patchedImportTracker = false;
let patchedNativeComponentRegistry = false;
let _importingModuleId: number = -1;

for (const key in metroModules) {
Expand Down Expand Up @@ -89,16 +90,17 @@ function onModuleRequire(moduleExports: any, id: Metro.ModuleID) {
}

// There are modules registering the same native component
if (moduleExports?.default?.name === "requireNativeComponent") {
instead("default", moduleExports, (args: any, origFunc: any) => {
if (!patchedNativeComponentRegistry && ["customBubblingEventTypes", "customDirectEventTypes", "register", "get"].every(x => moduleExports[x])) {
instead("register", moduleExports, (args: any, origFunc: any) => {
try {
return origFunc(...args);
} catch {
return args[0];
}
} catch { }
});

patchedNativeComponentRegistry = true;
}


// Hook DeveloperExperimentStore
if (moduleExports?.default?.constructor?.displayName === "DeveloperExperimentStore") {
moduleExports.default = new Proxy(moduleExports.default, {
Expand Down

0 comments on commit 4b94b7f

Please sign in to comment.