From 25f101602dcfbf75e5082b3c8965e44e74a7a8c1 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Thu, 26 Oct 2023 21:03:05 +0200 Subject: [PATCH] fix modules being patched multiple times --- src/webpack/patchWebpack.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/webpack/patchWebpack.ts b/src/webpack/patchWebpack.ts index 880aa255..0a3f6d14 100644 --- a/src/webpack/patchWebpack.ts +++ b/src/webpack/patchWebpack.ts @@ -229,12 +229,17 @@ function patchPush(webpackGlobal: any) { } handlePush.$$vencordOriginal = webpackGlobal.push; + // Webpack overwrites .push with its own push like so: `d.push = n.bind(null, d.push.bind(d));` + // it wraps the old push (`d.push.bind(d)`). this old push is in this case our handlePush. + // If we then repatched the new push, we would end up with recursive patching, which leads to our patches + // being applied multiple times. + // Thus, override bind to use the original push + handlePush.bind = (...args: unknown[]) => handlePush.$$vencordOriginal.bind(...args); + Object.defineProperty(webpackGlobal, "push", { get: () => handlePush, set(v) { - delete webpackGlobal.push; - webpackGlobal.push = v; - patchPush(webpackGlobal); + handlePush.$$vencordOriginal = v; }, configurable: true });