From e69575f2735363e884fb73b8a682f2b5de24241e Mon Sep 17 00:00:00 2001 From: Vendicated Date: Tue, 13 May 2025 21:15:03 +0200 Subject: [PATCH 1/3] fix canary --- src/webpack/patchWebpack.ts | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/src/webpack/patchWebpack.ts b/src/webpack/patchWebpack.ts index 9b66a5b4..a542cb9b 100644 --- a/src/webpack/patchWebpack.ts +++ b/src/webpack/patchWebpack.ts @@ -412,9 +412,12 @@ function runFactoryWithWrap(patchedFactory: PatchedModuleFactory, thisArg: unkno exports = module.exports; if (typeof require === "function" && require.c) { - if (_blacklistBadModules(require.c, exports, module.id)) { - return factoryReturn; - } + // module might not have been fully initialised yet + try { + if (_blacklistBadModules(require.c, exports, module.id)) { + return factoryReturn; + } + } catch { } } if (exports == null) { From d5420959938865aa9cf81ab7abc7a7d49a31ecd5 Mon Sep 17 00:00:00 2001 From: Vendicated Date: Tue, 13 May 2025 21:34:11 +0200 Subject: [PATCH 2/3] fix ContextMenus on canary --- src/webpack/common/menu.ts | 11 +++++++---- src/webpack/patchWebpack.ts | 14 ++++++++------ 2 files changed, 15 insertions(+), 10 deletions(-) diff --git a/src/webpack/common/menu.ts b/src/webpack/common/menu.ts index 9896b3a2..e77b5456 100644 --- a/src/webpack/common/menu.ts +++ b/src/webpack/common/menu.ts @@ -27,10 +27,13 @@ waitFor(m => m.name === "MenuCheckboxItem", (_, id) => { // we have to do this manual require by ID because m is in this case the MenuCheckBoxItem instead of the entire module const module = wreq(id); - for (const e of Object.values(module)) { - if (typeof e === "function" && e.name.startsWith("Menu")) { - Menu[e.name] = e; - } + for (const key in module) { + try { + const e = module[key]; + if (typeof e === "function" && e.name.startsWith("Menu")) { + Menu[e.name] = e; + } + } catch { } } }); diff --git a/src/webpack/patchWebpack.ts b/src/webpack/patchWebpack.ts index a542cb9b..3186b503 100644 --- a/src/webpack/patchWebpack.ts +++ b/src/webpack/patchWebpack.ts @@ -445,13 +445,15 @@ function runFactoryWithWrap(patchedFactory: PatchedModuleFactory, thisArg: unkno } for (const exportKey in exports) { - const exportValue = exports[exportKey]; + try { + const exportValue = exports[exportKey]; - if (exportValue != null && filter(exportValue)) { - waitForSubscriptions.delete(filter); - callback(exportValue, module.id); - break; - } + if (exportValue != null && filter(exportValue)) { + waitForSubscriptions.delete(filter); + callback(exportValue, module.id); + break; + } + } catch { } } } catch (err) { logger.error("Error while firing callback for Webpack waitFor subscription:\n", err, filter, callback); From 8c7225d106674d934acdd897eda362ef9d28baf1 Mon Sep 17 00:00:00 2001 From: Nuckyz <61953774+Nuckyz@users.noreply.github.com> Date: Tue, 13 May 2025 17:09:57 -0300 Subject: [PATCH 3/3] Clean up circular imports fixes --- src/webpack/common/menu.ts | 20 ++++++++++++-------- src/webpack/patchWebpack.ts | 26 +++++++++++++------------- src/webpack/webpack.ts | 9 ++++++++- 3 files changed, 33 insertions(+), 22 deletions(-) diff --git a/src/webpack/common/menu.ts b/src/webpack/common/menu.ts index e77b5456..5b1056dd 100644 --- a/src/webpack/common/menu.ts +++ b/src/webpack/common/menu.ts @@ -24,16 +24,20 @@ export const Menu = {} as t.Menu; // Relies on .name properties added by the MenuItemDemanglerAPI waitFor(m => m.name === "MenuCheckboxItem", (_, id) => { - // we have to do this manual require by ID because m is in this case the MenuCheckBoxItem instead of the entire module - const module = wreq(id); + // We have to do this manual require by ID because m in this case is the MenuCheckBoxItem instead of the entire module + const exports = wreq(id); - for (const key in module) { + for (const exportKey in exports) { + // Some exports might have not been initialized yet due to circular imports, so try catch it. try { - const e = module[key]; - if (typeof e === "function" && e.name.startsWith("Menu")) { - Menu[e.name] = e; - } - } catch { } + var exportValue = exports[exportKey]; + } catch { + continue; + } + + if (typeof exportValue === "function" && exportValue.name.startsWith("Menu")) { + Menu[exportValue.name] = exportValue; + } } }); diff --git a/src/webpack/patchWebpack.ts b/src/webpack/patchWebpack.ts index 3186b503..4f5899bc 100644 --- a/src/webpack/patchWebpack.ts +++ b/src/webpack/patchWebpack.ts @@ -412,12 +412,9 @@ function runFactoryWithWrap(patchedFactory: PatchedModuleFactory, thisArg: unkno exports = module.exports; if (typeof require === "function" && require.c) { - // module might not have been fully initialised yet - try { - if (_blacklistBadModules(require.c, exports, module.id)) { - return factoryReturn; - } - } catch { } + if (_blacklistBadModules(require.c, exports, module.id)) { + return factoryReturn; + } } if (exports == null) { @@ -445,15 +442,18 @@ function runFactoryWithWrap(patchedFactory: PatchedModuleFactory, thisArg: unkno } for (const exportKey in exports) { + // Some exports might have not been initialized yet due to circular imports, so try catch it. try { - const exportValue = exports[exportKey]; + var exportValue = exports[exportKey]; + } catch { + continue; + } - if (exportValue != null && filter(exportValue)) { - waitForSubscriptions.delete(filter); - callback(exportValue, module.id); - break; - } - } catch { } + if (exportValue != null && filter(exportValue)) { + waitForSubscriptions.delete(filter); + callback(exportValue, module.id); + break; + } } } catch (err) { logger.error("Error while firing callback for Webpack waitFor subscription:\n", err, filter, callback); diff --git a/src/webpack/webpack.ts b/src/webpack/webpack.ts index 0e3d641b..c1847474 100644 --- a/src/webpack/webpack.ts +++ b/src/webpack/webpack.ts @@ -156,7 +156,14 @@ export function _blacklistBadModules(requireCache: NonNullable