History

Stabilize root app shell renders

Cursor Agent committed 5 months ago

Commit 4b87dbf1 parent d1e85c41 file · +22 −18Browse files

Unified · Split

apps/web/src/routes/__root.tsx+22−18
@@ -99,19 +99,20 @@ export const Route = createRootRouteWithContext<{ · 98 unmodified lines
9999 }),
100100 });
101101
102+const APP_SHELL = (
103+ <CommandPalette>
104+ <AppSidebarLayout>
105+ <Outlet />
106+ </AppSidebarLayout>
107+ </CommandPalette>
108+);
109+
102110 function RootRouteView() {
103111 const pathname = useLocation({ select: (location) => location.pathname });
104112 const { authGateState } = Route.useRouteContext();
105113 const primaryEnvironmentAuthenticated = authGateState.status === "authenticated";
106114
107− useEffect(() => {
108− const frame = window.requestAnimationFrame(() => {
109− syncBrowserChromeTheme();
110− });
111− return () => {
112− window.cancelAnimationFrame(frame);
113− };
114− }, [pathname]);
115+ useBrowserChromeThemeSync(pathname);
115116
116117 if (pathname === "/pair") {
117118 return <Outlet />;
@@ -121,14 +122,6 @@ function RootRouteView() { · 3 unmodified lines
121122 return <Outlet />;
122123 }
123124
124− const appShell = (
125− <CommandPalette>
126− <AppSidebarLayout>
127− <Outlet />
128− </AppSidebarLayout>
129− </CommandPalette>
130− );
131−
132125 return (
133126 <ToastProvider>
134127 <AnchoredToastProvider>
@@ -142,15 +135,26 @@ function RootRouteView() { · 7 unmodified lines
142135 {primaryEnvironmentAuthenticated ? <WebSocketConnectionCoordinator /> : null}
143136 {primaryEnvironmentAuthenticated ? <SlowRpcAckToastCoordinator /> : null}
144137 {primaryEnvironmentAuthenticated ? (
145− <WebSocketConnectionSurface>{appShell}</WebSocketConnectionSurface>
138+ <WebSocketConnectionSurface>{APP_SHELL}</WebSocketConnectionSurface>
146139 ) : (
147− appShell
140+ APP_SHELL
148141 )}
149142 </AnchoredToastProvider>
150143 </ToastProvider>
151144 );
152145 }
153146
147+function useBrowserChromeThemeSync(pathname: string) {
148+ useEffect(() => {
149+ const frame = window.requestAnimationFrame(() => {
150+ syncBrowserChromeTheme();
151+ });
152+ return () => {
153+ window.cancelAnimationFrame(frame);
154+ };
155+ }, [pathname]);
156+}
157+
154158 function HostedStaticEnvironmentBootstrap() {
155159 const savedEnvironmentCount = useSavedEnvironmentRegistryStore(
156160 (state) => Object.keys(state.byId).length,