some fixes (#745)

* UserAreaAPI: fix shrink for buttons

* ContextMenuAPI: fix

* LoadLazyChunks: fix
This commit is contained in:
prism 2026-02-08 15:10:39 +01:00 • committed by GitHub
parent cd14790316
commit 8bb0d8314d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 33 additions and 16 deletions

View file

@ -29,6 +29,18 @@ function getWebpackChunkMap() {
return v;
}
async function promiseAllSettledBatched<T>(tasks: (() => Promise<T>)[], batchSize = 8): Promise<T[]> {
const results: T[] = [];
for (let i = 0; i < tasks.length; i += batchSize) {
const batch = tasks.slice(i, i + batchSize);
const settled = await Promise.allSettled(batch.map(t => t()));
for (const r of settled) {
if (r.status === "fulfilled") results.push(r.value);
}
}
return results;
}
export async function loadLazyChunks() {
const LazyChunkLoaderLogger = new Logger("LazyChunkLoader");
@ -59,7 +71,7 @@ export async function loadLazyChunks() {
const shouldForceDefer = false;
await Promise.all(Array.from(lazyChunks).map(async ([, rawChunkIds, entryPoint]) => {
await promiseAllSettledBatched(Array.from(lazyChunks).map(([, rawChunkIds, entryPoint]) => async () => {
const chunkIds = rawChunkIds ? Array.from(rawChunkIds.matchAll(Webpack.ChunkIdsRegex)).map(m => {
const numChunkId = Number(m[1]);
return Number.isNaN(numChunkId) ? m[1] : numChunkId;
@ -104,9 +116,9 @@ export async function loadLazyChunks() {
}));
// Loads all found valid chunk groups
await Promise.all(
await promiseAllSettledBatched(
Array.from(validChunkGroups)
.map(([chunkIds]) =>
.map(([chunkIds]) => () =>
Promise.all(chunkIds.map(id => wreq.e(id)))
)
);
@ -182,7 +194,7 @@ export async function loadLazyChunks() {
return !(validChunks.has(id) || invalidChunks.has(id));
});
await Promise.all(chunksLeft.map(async id => {
await promiseAllSettledBatched(chunksLeft.map(id => async () => {
const isWorkerAsset = await fetch(wreq.p + wreq.u(id))
.then(r => r.text())
.then(t => /importScripts\(|self\.postMessage/.test(t));

View file

@ -10,7 +10,7 @@ import { Devs } from "@utils/constants";
import definePlugin from "@utils/types";
import { findCssClassesLazy } from "@webpack";
const { iconForeground } = findCssClassesLazy("iconForeground", "autocompleteRowContent");
const { iconForeground } = findCssClassesLazy("iconForeground", "accountPopoutButtonWrapper");
export default definePlugin({
name: "UserAreaAPI",
@ -20,10 +20,17 @@ export default definePlugin({
patches: [
{
find: "#{intl::ACCOUNT_SPEAKING_WHILE_MUTED}",
replacement: {
match: /(?<=className:(\i)\.\i,style:\i,)children:\[/,
replace: "children:[...$self.renderButtons(arguments[0],$1),"
}
replacement: [
{
match: /(?<=className:(\i)\.\i,style:\i,)children:\[/,
replace: "children:[...$self.renderButtons(arguments[0],$1),"
},
// fix discord weird shrink with extra buttons
{
match: /(?<=\{ref:\i,)style:(\i)(?=,onMouseEnter:\i,onMouseDown:\i,onClick)/,
replace: "style:{...$1,minWidth:0}"
}
]
}
],

View file

@ -40,13 +40,11 @@ export default definePlugin({
replacement: [
{
match: /navId:(?=.+?([,}].*?\)))/g,
replace: (m, rest) => {
// Check if this navId: match is a destructuring statement, ignore it if it is
const destructuringMatch = rest.match(/}=.+/);
if (destructuringMatch == null) {
return `contextMenuAPIArguments:typeof arguments!=='undefined'?arguments:[],${m}`;
}
return m;
replace: (m, rest, ...args) => {
if (rest.match(/}=.+/)) return m;
const src = args[1]?.slice(Math.max(0, +args[0] - 2000), +args[0]);
if (src && Math.max(src.lastIndexOf("PureComponent{"), src.lastIndexOf("Component{")) > src.lastIndexOf("function")) return m;
return `contextMenuAPIArguments:typeof arguments!=='undefined'?arguments:[],${m}`;
}
}
]