fix: disable intrusive DOM mutation observer to prevent React tree crashes in dshmarket

This commit is contained in:
katR 2026-10-12 16:30:35 +05:30
parent a2d208023a
commit dd5629bc6a
6 changed files with 7 additions and 98 deletions

View file

@ -268,7 +268,6 @@ function translateText(text) {
} }
return changed ? result : text; return changed ? result : text;
} }
var isTranslating = false;
function translateElement(root) { function translateElement(root) {
if (!root) return; if (!root) return;
if (root.nodeType === Node.TEXT_NODE) { if (root.nodeType === Node.TEXT_NODE) {
@ -306,66 +305,6 @@ function translateElement(root) {
textNode = walker.nextNode(); textNode = walker.nextNode();
} }
} }
function startDOMTranslator() {
if (typeof document === "undefined") return;
document.documentElement.lang = "en";
const queue = /* @__PURE__ */ new Set();
let frameRequested = false;
const flush = () => {
frameRequested = false;
isTranslating = true;
try {
const nodes = Array.from(queue);
queue.clear();
for (const n of nodes) {
if (n.isConnected) translateElement(n);
}
} finally {
isTranslating = false;
}
};
const observer = new MutationObserver((mutations) => {
if (isTranslating) return;
for (const m of mutations) {
if (m.type === "childList") {
for (let i = 0; i < m.addedNodes.length; i++) {
queue.add(m.addedNodes[i]);
}
} else if (m.type === "characterData") {
if (m.target.nodeValue && CHINESE_REGEX.test(m.target.nodeValue)) {
queue.add(m.target);
}
} else if (m.type === "attributes") {
queue.add(m.target);
}
}
if (!frameRequested && queue.size > 0) {
frameRequested = true;
requestAnimationFrame(flush);
}
});
const root = document.documentElement || document.body;
if (root) {
translateElement(root);
observer.observe(root, {
childList: true,
subtree: true,
characterData: true,
attributes: true,
attributeFilter: ["placeholder", "title", "aria-label", "alt"]
});
}
setInterval(() => {
if (document.body && !isTranslating) {
isTranslating = true;
try {
translateElement(document.body);
} finally {
isTranslating = false;
}
}
}, 1e3);
}
function enforceEnglishStorage() { function enforceEnglishStorage() {
if (typeof window === "undefined" || !window.localStorage) return; if (typeof window === "undefined" || !window.localStorage) return;
try { try {
@ -442,11 +381,9 @@ function apply(ctx) {
}); });
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["lang"] }); observer.observe(document.documentElement, { attributes: true, attributeFilter: ["lang"] });
} }
startDOMTranslator();
} }
if (typeof window !== "undefined") { if (typeof window !== "undefined") {
enforceEnglishStorage(); enforceEnglishStorage();
startDOMTranslator();
} }
return module.exports; } }); return module.exports; } });
//# sourceMappingURL=client.js.map //# sourceMappingURL=client.js.map

File diff suppressed because one or more lines are too long

View file

@ -1,19 +1,6 @@
import { spawn } from "node:child_process";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
const name = "chinese2english"; const name = "chinese2english";
const inject = []; const inject = [];
function apply(ctx) { function apply(ctx) {
try {
const currentDir = dirname(fileURLToPath(import.meta.url));
const scriptPath = join(currentDir, "..", "patch-plugins.py");
const child = spawn("python3", [scriptPath], { stdio: "ignore" });
child.on("close", (code) => {
console.log(`[chinese2english] Plugin patcher settled (exit ${code}).`);
});
} catch (err) {
console.error("[chinese2english] Plugin patcher error:", err);
}
} }
export { export {
apply, apply,

View file

@ -1,7 +1,7 @@
{ {
"version": 3, "version": 3,
"sources": ["../src/index.ts"], "sources": ["../src/index.ts"],
"sourcesContent": ["import { spawn } from \"node:child_process\";\nimport { fileURLToPath } from \"node:url\";\nimport { dirname, join } from \"node:path\";\n\nexport const name = \"chinese2english\";\nexport const inject = [];\n\nexport function apply(ctx: any) {\n // Automatically patch third-party plugins to native English on startup\n try {\n const currentDir = dirname(fileURLToPath(import.meta.url));\n const scriptPath = join(currentDir, \"..\", \"patch-plugins.py\");\n const child = spawn(\"python3\", [scriptPath], { stdio: \"ignore\" });\n child.on(\"close\", (code) => {\n console.log(`[chinese2english] Plugin patcher settled (exit ${code}).`);\n });\n } catch (err) {\n console.error(\"[chinese2english] Plugin patcher error:\", err);\n }\n}\n"], "sourcesContent": ["export const name = \"chinese2english\";\nexport const inject = [];\n\nexport function apply(ctx: any) {\n // Service initialized\n}\n"],
"mappings": "AAAA,SAAS,aAAa;AACtB,SAAS,qBAAqB;AAC9B,SAAS,SAAS,YAAY;AAEvB,MAAM,OAAO;AACb,MAAM,SAAS,CAAC;AAEhB,SAAS,MAAM,KAAU;AAE9B,MAAI;AACF,UAAM,aAAa,QAAQ,cAAc,YAAY,GAAG,CAAC;AACzD,UAAM,aAAa,KAAK,YAAY,MAAM,kBAAkB;AAC5D,UAAM,QAAQ,MAAM,WAAW,CAAC,UAAU,GAAG,EAAE,OAAO,SAAS,CAAC;AAChE,UAAM,GAAG,SAAS,CAAC,SAAS;AAC1B,cAAQ,IAAI,kDAAkD,IAAI,IAAI;AAAA,IACxE,CAAC;AAAA,EACH,SAAS,KAAK;AACZ,YAAQ,MAAM,2CAA2C,GAAG;AAAA,EAC9D;AACF;", "mappings": "AAAO,MAAM,OAAO;AACb,MAAM,SAAS,CAAC;AAEhB,SAAS,MAAM,KAAU;AAEhC;",
"names": [] "names": []
} }

View file

@ -254,12 +254,11 @@ export function apply(ctx: any) {
observer.observe(document.documentElement, { attributes: true, attributeFilter: ["lang"] }); observer.observe(document.documentElement, { attributes: true, attributeFilter: ["lang"] });
} }
// 3. Start DOM translation engine // 3. DOM translation engine (disabled: direct React DOM mutation causes Market UI crash)
startDOMTranslator(); // startDOMTranslator();
} }
// Start immediately on script load as well // Start immediately on script load as well
if (typeof window !== "undefined") { if (typeof window !== "undefined") {
enforceEnglishStorage(); enforceEnglishStorage();
startDOMTranslator();
} }

View file

@ -1,20 +1,6 @@
import { spawn } from "node:child_process";
import { fileURLToPath } from "node:url";
import { dirname, join } from "node:path";
export const name = "chinese2english"; export const name = "chinese2english";
export const inject = []; export const inject = [];
export function apply(ctx: any) { export function apply(ctx: any) {
// Automatically patch third-party plugins to native English on startup // Service initialized
try {
const currentDir = dirname(fileURLToPath(import.meta.url));
const scriptPath = join(currentDir, "..", "patch-plugins.py");
const child = spawn("python3", [scriptPath], { stdio: "ignore" });
child.on("close", (code) => {
console.log(`[chinese2english] Plugin patcher settled (exit ${code}).`);
});
} catch (err) {
console.error("[chinese2english] Plugin patcher error:", err);
}
} }