Skip to content
TypeScript

perf(web): the root route compiles with the React Compiler (#20585)

Julius Marminge20851e304eb5
diff --git a/apps/web/src/routes/__root.tsx b/apps/web/src/routes/__root.tsx
index f8826276d76..ece2903be3d 100644
--- a/apps/web/src/routes/__root.tsx
+++ b/apps/web/src/routes/__root.tsx
@@ -12,7 +12,7 @@ import {
useRouter,
} from "@tanstack/react-router";
import { Check, Copy } from "lucide";
-import { useEffect, useEffectEvent, useMemo, useRef, useState } from "react";
+import { useEffect, useEffectEvent, useRef, useState } from "react";
import { APP_BASE_NAME, APP_DISPLAY_NAME, APP_STAGE_LABEL, APP_VERSION } from "../branding";
import { resolveServerBackedAppDisplayName } from "../branding.logic";
@@ -152,19 +152,11 @@ function RootRouteView() {
authGateState.status === "hosted-static",
);
- useEffect(() => {
- const frame = window.requestAnimationFrame(() => {
- syncBrowserChromeTheme();
- });
- return () => {
- window.cancelAnimationFrame(frame);
- };
- }, [pathname]);
-
if (pathname === "/pair" || pathname === "/connect" || pathname === "/connect-agent") {
return (
<>
<DocumentTitleSync />
+ <BrowserChromeThemeSync key={pathname} />
<Outlet />
</>
);
@@ -176,6 +168,7 @@ function RootRouteView() {
return (
<>
<DocumentTitleSync />
+ <BrowserChromeThemeSync key={pathname} />
{hostedPromptLinkLanding}
</>
);
@@ -186,6 +179,7 @@ function RootRouteView() {
<ToastProvider>
<AnchoredToastProvider>
<DocumentTitleSync />
+ <BrowserChromeThemeSync key={pathname} />
<ContrastAppearanceSync />
<EnvironmentThemeSync />
<GlassAppearanceSync />
@@ -206,6 +200,7 @@ function RootRouteView() {
return (
<>
<DocumentTitleSync />
+ <BrowserChromeThemeSync key={pathname} />
<Outlet />
</>
);
@@ -223,6 +218,7 @@ function RootRouteView() {
<ToastProvider>
<AnchoredToastProvider>
<DocumentTitleSync />
+ <BrowserChromeThemeSync key={pathname} />
<ContrastAppearanceSync />
<EnvironmentThemeSync />
<GlassAppearanceSync />
@@ -342,6 +338,19 @@ function FontAppearanceSync() {
return null;
}
+/** Keyed by pathname: each route paints its own surface, which the browser chrome samples. */
+function BrowserChromeThemeSync() {
+ useEffect(() => {
+ const frame = window.requestAnimationFrame(() => {
+ syncBrowserChromeTheme();
+ });
+ return () => {
+ window.cancelAnimationFrame(frame);
+ };
+ }, []);
+ return null;
+}
+
function DocumentTitleSync() {
const primaryServerVersion =
useAtomValue(primaryServerConfigAtom)?.environment.serverVersion ?? null;
@@ -392,7 +401,7 @@ function RootRouteErrorView({ error }: ErrorComponentProps) {
const message = errorMessage(error);
// Router pathname rather than window.location: desktop uses hash history, where the window path is always "/".
const pathname = useLocation({ select: (location) => location.pathname });
- const report = useMemo(() => errorReport(error, pathname), [error, pathname]);
+ const report = errorReport(error, pathname);
return (
<StandalonePage tone="error">