[Patcher > Base] Fix getting original for FluxDispatcher in unpatch fail

pull/70/head
CanadaHonk 2 years ago committed by GitHub
parent 1150eb8b4b
commit fd52228e3f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -111,14 +111,14 @@ export const patch = (parent, functionName, handler, before = false, instead = f
const keyName = `gm-${functionName}`;
if (!modIndex[id][keyName]) {
const originalFunctionClone = Object.assign({}, parent)[functionName];
const original = parent[functionName];
parent[functionName] = Object.assign(generateNewFunction(parent[functionName], id, functionName, keyName), originalFunctionClone);
parent[functionName] = Object.assign(generateNewFunction(original, id, functionName, keyName), originalFunctionClone);
parent[functionName].toString = () => originalFunctionClone.toString(); // You cannot just set directly a.toString = b.toString like we used to because strange internal JS prototype things, so make a new function just to run original function
let toHarden = false;
if (isReactComponent(parent[functionName])) toHarden = true;
if (isReactComponent(original)) toHarden = true;
if (parent.render) {
if (functionName !== 'render') {
patch(parent, 'render', () => {}); // Noop patch in component render to force harden
@ -127,7 +127,7 @@ export const patch = (parent, functionName, handler, before = false, instead = f
}
}
if (parent[functionName].displayName?.endsWith('Item')) toHarden = false;
if (original.displayName?.endsWith('Item')) toHarden = false;
modIndex[id][keyName] = {
before: [],
@ -135,7 +135,7 @@ export const patch = (parent, functionName, handler, before = false, instead = f
instead: [],
harden: toHarden,
original: originalFunctionClone
original
};
}

Loading…
Cancel
Save