Skip to content

🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.

fix(app): google chrome translate shouldn't crash app (#9888)

Nimar86080e8e84b9
diff --git a/web/src/pages/_app.tsx b/web/src/pages/_app.tsx
index 14811487c3..05f2dcdf24 100644
--- a/web/src/pages/_app.tsx
+++ b/web/src/pages/_app.tsx
@@ -29,6 +29,46 @@ import "core-js/features/array/to-sorted";
import "react18-json-view/src/style.css";
+// Polyfill to prevent React crashes when Google Translate modifies the DOM.
+// Google Translate wraps text nodes in <font> elements, which breaks React's
+// reconciliation when it tries to remove/insert nodes that no longer exist
+// in the expected location. This catches NotFoundError and prevents crashes
+// while still allowing translation to work.
+// See: https://github.com/facebook/react/issues/11538
+// See also: https://issues.chromium.org/issues/41407169
+if (typeof window !== "undefined") {
+ const originalRemoveChild = Element.prototype.removeChild;
+ const originalInsertBefore = Element.prototype.insertBefore;
+
+ Element.prototype.removeChild = function <T extends Node>(child: T): T {
+ try {
+ return originalRemoveChild.call(this, child) as T;
+ } catch (error) {
+ if (error instanceof DOMException && error.name === "NotFoundError") {
+ // Node was likely moved by Google Translate - silently ignore
+ return child;
+ }
+ throw error;
+ }
+ };
+
+ Element.prototype.insertBefore = function <T extends Node>(
+ newNode: T,
+ referenceNode: Node | null,
+ ): T {
+ try {
+ return originalInsertBefore.call(this, newNode, referenceNode) as T;
+ } catch (error) {
+ if (error instanceof DOMException && error.name === "NotFoundError") {
+ // Reference node was likely moved by Google Translate
+ // Fallback: append to end (DOM is already inconsistent anyway)
+ return this.appendChild(newNode) as T;
+ }
+ throw error;
+ }
+ };
+}
+
import { DetailPageListsProvider } from "@/src/features/navigate-detail-pages/context";
import { env } from "@/src/env.mjs";
import { ThemeProvider } from "@/src/features/theming/ThemeProvider";