hermes-agent/apps/desktop/src/main.tsx
ethernet f1af945f6c
fix(desktop): slow session switch (#65890)
react-router v7's HashRouter wraps every route state update in
React.startTransition() by default. In React 19's concurrent renderer,
transitions are non-urgent — React can yield mid-render and come back
later. When the app is under load (streaming token deltas, gateway
events, store updates from active sessions), those higher-priority
updates keep interrupting the transition, starving the route change commit.

This matches every symptom of the session-switch lag:
- Main thread is free (animations run, clicks work) — startTransition
  defers, it does not block
- navigate() does not take effect for seconds — the transition keeps
  getting interrupted by higher-priority updates
- Worse under load — more concurrent re-renders = more interruptions
- The whole UI (sidebar + main pane) does not update — the entire route
  change is one transition, so nothing commits until it finishes

Pass useTransitions={false} to HashRouter so route state updates are
synchronous at default React priority instead of deferred transition
priority. navigate() now commits and paints immediately.

See: react-router v7 chunk-BIP66BKV.js HashRouter implementation.
2026-07-16 15:34:53 -04:00

53 lines
2.2 KiB
TypeScript

import './styles.css'
// Side-effect: applies the persisted window translucency on load.
import './store/translucency'
import { QueryClientProvider } from '@tanstack/react-query'
import { StrictMode } from 'react'
import { createRoot } from 'react-dom/client'
import { HashRouter } from 'react-router-dom'
import App from './app'
import { ErrorBoundary } from './components/error-boundary'
import { HapticsProvider } from './components/haptics-provider'
import { I18nProvider } from './i18n'
import { installClipboardShim } from './lib/clipboard'
import { queryClient } from './lib/query-client'
import { ThemeProvider } from './themes/context'
installClipboardShim()
if (import.meta.env.MODE !== 'production') {
import('./app/chat/perf-probe')
}
if (new URLSearchParams(window.location.search).get('win') === 'overlay') {
void import('./app/pet-overlay/overlay-root').then(({ mountPetOverlay }) => mountPetOverlay())
} else {
createRoot(document.getElementById('root')!).render(
<StrictMode>
<ErrorBoundary label="root">
<QueryClientProvider client={queryClient}>
<I18nProvider>
<ThemeProvider>
<HapticsProvider>
{/* useTransitions={false}: react-router v7's HashRouter wraps every
route state update in React.startTransition() by default. In
React 19's concurrent renderer, transitions are non-urgent — React
can yield mid-render and resume later. When the app is under load
(streaming token deltas, gateway events, store updates), those
higher-priority updates keep interrupting the transition, starving
the route change commit. The session sidebar highlight + main pane
both freeze for seconds despite the main thread being free.
Disabling transitions makes navigate() commit at default priority. */}
<HashRouter useTransitions={false}>
<App />
</HashRouter>
</HapticsProvider>
</ThemeProvider>
</I18nProvider>
</QueryClientProvider>
</ErrorBoundary>
</StrictMode>
)
}