Skip to content

Commit

Permalink
Merge pull request #214 from uwx/feature/group-prefix-wp-modules
Browse files Browse the repository at this point in the history
Fix very laggy Sources tab in DevTools when using "Patch all" in Spacepack
  • Loading branch information
Cynosphere authored Feb 13, 2025
2 parents b39af37 + 221b3b4 commit cb34ba0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { RepositoryManifest, UpdateState } from "../types";
import { ConfigExtension, DetectedExtension } from "@moonlight-mod/types";
import DiscoveryClasses from "@moonlight-mod/wp/discord/modules/discovery/web/Discovery.css";

const MODULE_REGEX = /Webpack-Module-(\d+)/g;
const MODULE_REGEX = /Webpack-Module\/(\d+)\/(\d+)/g;

const logger = moonlight.getLogger("moonbase/crashScreen");

Expand Down Expand Up @@ -139,10 +139,10 @@ export function wrapAction({ action, state }: WrapperProps) {
const causes = React.useMemo(() => {
const causes = new Set<string>();
if (state.error.stack) {
for (const [, id] of state.error.stack.matchAll(MODULE_REGEX))
for (const [, , id] of state.error.stack.matchAll(MODULE_REGEX))
for (const ext of moonlight.patched.get(id) ?? []) causes.add(ext);
}
for (const [, id] of state.info.componentStack.matchAll(MODULE_REGEX))
for (const [, , id] of state.info.componentStack.matchAll(MODULE_REGEX))
for (const ext of moonlight.patched.get(id) ?? []) causes.add(ext);
return [...causes];
}, []);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ export const spacepack: Spacepack = {
"module",
"exports",
"require",
`(${funcStr}).apply(this, arguments)\n` + `//# sourceURL=Webpack-Module-${module}`
`(${funcStr}).apply(this, arguments)\n` + `//# sourceURL=Webpack-Module/${module.slice(0, 3)}/${module}`
) as WebpackModuleFunc;
},

Expand Down
5 changes: 3 additions & 2 deletions packages/core/src/patch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ function patchModules(entry: WebpackJsonpEntry[1]) {
const wrapped =
`(${replaced}).apply(this, arguments)\n` +
`// Patched by moonlight: ${patchedStr}\n` +
`//# sourceURL=Webpack-Module-${id}`;
`//# sourceURL=Webpack-Module/${id.slice(0, 3)}/${id}`;

try {
const func = new Function("module", "exports", "require", wrapped) as WebpackModuleFunc;
Expand Down Expand Up @@ -205,7 +205,8 @@ function patchModules(entry: WebpackJsonpEntry[1]) {

if (moonlightNode.config.patchAll === true) {
if ((typeof id !== "string" || !id.includes("_")) && !entry[id].__moonlight) {
const wrapped = `(${moduleCache[id]}).apply(this, arguments)\n` + `//# sourceURL=Webpack-Module-${id}`;
const wrapped =
`(${moduleCache[id]}).apply(this, arguments)\n` + `//# sourceURL=Webpack-Module/${id.slice(0, 3)}/${id}`;
entry[id] = new Function("module", "exports", "require", wrapped) as WebpackModuleFunc;
entry[id].__moonlight = true;
}
Expand Down

0 comments on commit cb34ba0

Please sign in to comment.