-
Notifications
You must be signed in to change notification settings - Fork 33
feat(code): introduce TanStack Router file-based routing #2455
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| import path from "node:path"; | ||
| import { fileURLToPath } from "node:url"; | ||
| import { Generator, getConfig } from "@tanstack/router-generator"; | ||
|
|
||
| const __dirname = path.dirname(fileURLToPath(import.meta.url)); | ||
| const root = path.resolve(__dirname, ".."); | ||
|
|
||
| const config = getConfig( | ||
| { | ||
| target: "react", | ||
| autoCodeSplitting: true, | ||
| routesDirectory: path.resolve(root, "src/renderer/routes"), | ||
| generatedRouteTree: path.resolve(root, "src/renderer/routeTree.gen.ts"), | ||
| }, | ||
| root, | ||
| ); | ||
|
|
||
| const generator = new Generator({ config, root }); | ||
| await generator.run(); | ||
| console.log("Generated routeTree.gen.ts"); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
| import { | ||
| createHashHistory, | ||
| createRouter as createTanStackRouter, | ||
| } from "@tanstack/react-router"; | ||
| import { routeTree } from "./routeTree.gen"; | ||
|
|
||
| export const router = createTanStackRouter({ | ||
| routeTree, | ||
| history: createHashHistory(), | ||
| defaultPreload: "intent", | ||
| scrollRestoration: false, | ||
| }); | ||
|
|
||
| declare module "@tanstack/react-router" { | ||
| interface Register { | ||
| router: typeof router; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -2,24 +2,14 @@ import { HeaderRow } from "@components/HeaderRow"; | |
| import { HedgehogMode } from "@components/HedgehogMode"; | ||
| import { KeyboardShortcutsSheet } from "@components/KeyboardShortcutsSheet"; | ||
| import { SpaceSwitcher } from "@components/SpaceSwitcher"; | ||
|
|
||
| import { ArchivedTasksView } from "@features/archive/components/ArchivedTasksView"; | ||
| import { UsageLimitModal } from "@features/billing/components/UsageLimitModal"; | ||
| import { CommandMenu } from "@features/command/components/CommandMenu"; | ||
| import { CommandCenterView } from "@features/command-center/components/CommandCenterView"; | ||
| import { InboxView } from "@features/inbox/components/InboxView"; | ||
| import { useInboxDeepLink } from "@features/inbox/hooks/useInboxDeepLink"; | ||
| import { McpServersView } from "@features/mcp-servers/components/McpServersView"; | ||
| import { FolderSettingsView } from "@features/settings/components/FolderSettingsView"; | ||
| import { SettingsDialog } from "@features/settings/components/SettingsDialog"; | ||
| import { useSetupDiscovery } from "@features/setup/hooks/useSetupDiscovery"; | ||
| import { MainSidebar } from "@features/sidebar/components/MainSidebar"; | ||
| import { useSidebarData } from "@features/sidebar/hooks/useSidebarData"; | ||
| import { useVisualTaskOrder } from "@features/sidebar/hooks/useVisualTaskOrder"; | ||
| import { SkillsView } from "@features/skills/components/SkillsView"; | ||
| import { TaskDetail } from "@features/task-detail/components/TaskDetail"; | ||
| import { TaskInput } from "@features/task-detail/components/TaskInput"; | ||
| import { TaskPendingView } from "@features/task-detail/components/TaskPendingView"; | ||
| import { useTasks } from "@features/tasks/hooks/useTasks"; | ||
| import { TourOverlay } from "@features/tour/components/TourOverlay"; | ||
| import { | ||
|
|
@@ -35,23 +25,23 @@ import { useCommandMenuStore } from "@stores/commandMenuStore"; | |
| import { useNavigationStore } from "@stores/navigationStore"; | ||
| import { useShortcutsSheetStore } from "@stores/shortcutsSheetStore"; | ||
| import { useQueryClient } from "@tanstack/react-query"; | ||
| import { createRootRoute, Outlet } from "@tanstack/react-router"; | ||
| import { TanStackRouterDevtools } from "@tanstack/react-router-devtools"; | ||
| import { logger } from "@utils/logger"; | ||
| import { useCallback, useEffect, useRef } from "react"; | ||
| import { GlobalEventHandlers } from "../components/GlobalEventHandlers"; | ||
| import { useNewTaskDeepLink } from "../hooks/useNewTaskDeepLink"; | ||
| import { useTaskDeepLink } from "../hooks/useTaskDeepLink"; | ||
| import { GlobalEventHandlers } from "./GlobalEventHandlers"; | ||
|
|
||
| const log = logger.scope("main-layout"); | ||
| const log = logger.scope("root-route"); | ||
|
|
||
| export function MainLayout() { | ||
| const { | ||
| view, | ||
| hydrateTask, | ||
| navigateToTaskInput, | ||
| navigateToTask, | ||
| taskInputReportAssociation, | ||
| taskInputCloudRepository, | ||
| } = useNavigationStore(); | ||
| export const Route = createRootRoute({ | ||
| component: RootLayout, | ||
| }); | ||
|
|
||
| function RootLayout() { | ||
| const { view, hydrateTask, navigateToTaskInput, navigateToTask } = | ||
| useNavigationStore(); | ||
| const { | ||
| isOpen: commandMenuOpen, | ||
| setOpen: setCommandMenuOpen, | ||
|
|
@@ -70,7 +60,6 @@ export function MainLayout() { | |
| const billingEnabled = useFeatureFlag(BILLING_FLAG); | ||
| const syncCloudTasksEnabled = useFeatureFlag(SYNC_CLOUD_TASKS_FLAG); | ||
|
|
||
| // Space switcher data | ||
| const sidebarData = useSidebarData({ activeView: view }); | ||
| const visualTaskOrder = useVisualTaskOrder(sidebarData); | ||
| const activeTaskId = | ||
|
|
@@ -100,8 +89,6 @@ export function MainLayout() { | |
| if (missing.length === 0) return; | ||
| const missingIds = missing.map((t) => t.id); | ||
| for (const id of missingIds) reconcilingTaskIds.current.add(id); | ||
| // Single batched IPC instead of one mutation per task — with many cloud | ||
| // tasks the per-task pattern saturates the main thread at boot. | ||
| workspaceApi | ||
| .reconcileCloudWorkspaces(missingIds) | ||
| .then((result) => { | ||
|
|
@@ -140,42 +127,8 @@ export function MainLayout() { | |
| <HeaderRow /> | ||
| <Flex flexGrow="1" overflow="hidden"> | ||
| <MainSidebar /> | ||
|
|
||
| <Box flexGrow="1" overflow="hidden"> | ||
| {view.type === "task-input" && ( | ||
| <TaskInput | ||
| initialPrompt={view.initialPrompt} | ||
| initialPromptKey={view.taskInputRequestId} | ||
| initialCloudRepository={ | ||
| view.initialCloudRepository ?? taskInputCloudRepository | ||
| } | ||
| initialModel={view.initialModel} | ||
| initialMode={view.initialMode} | ||
| reportAssociation={ | ||
| view.reportAssociation ?? taskInputReportAssociation | ||
| } | ||
| /> | ||
| )} | ||
|
|
||
| {view.type === "task-detail" && view.data && ( | ||
| <TaskDetail key={view.data.id} task={view.data} /> | ||
| )} | ||
|
|
||
| {view.type === "task-pending" && view.pendingTaskKey && ( | ||
| <TaskPendingView pendingTaskKey={view.pendingTaskKey} /> | ||
| )} | ||
|
|
||
| {view.type === "folder-settings" && <FolderSettingsView />} | ||
|
|
||
| {view.type === "inbox" && <InboxView />} | ||
|
|
||
| {view.type === "archived" && <ArchivedTasksView />} | ||
|
|
||
| {view.type === "command-center" && <CommandCenterView />} | ||
|
|
||
| {view.type === "skills" && <SkillsView />} | ||
|
|
||
| {view.type === "mcp-servers" && <McpServersView />} | ||
| <Outlet /> | ||
| </Box> | ||
| </Flex> | ||
|
|
||
|
|
@@ -200,6 +153,9 @@ export function MainLayout() { | |
| <TourOverlay /> | ||
| {billingEnabled && <UsageLimitModal />} | ||
| <HedgehogMode /> | ||
| {import.meta.env.DEV && ( | ||
| <TanStackRouterDevtools position="bottom-right" /> | ||
|
Comment on lines
155
to
+157
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Prompt To Fix With AIThis is a comment left during a code review.
Path: apps/code/src/renderer/routes/__root.tsx
Line: 155-157
Comment:
**DevTools bundle not tree-shaken in prod** — The top-level `import { TanStackRouterDevtools } from "@tanstack/react-router-devtools"` is unconditional, so the entire devtools chunk is included in the production bundle regardless of the `import.meta.env.DEV` guard on the JSX. The fix is to use `React.lazy` with a conditional dynamic import so the module is only ever loaded in development builds.
How can I resolve this? If you propose a fix, please make it concise.Note: If this suggestion doesn't match your team's coding style, reply to this and let me know. I'll remember it for next time! |
||
| )} | ||
| </Flex> | ||
| ); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { ArchivedTasksView } from "@features/archive/components/ArchivedTasksView"; | ||
| import { createFileRoute } from "@tanstack/react-router"; | ||
|
|
||
| export const Route = createFileRoute("/code/archived")({ | ||
| component: ArchivedTasksView, | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { InboxView } from "@features/inbox/components/InboxView"; | ||
| import { createFileRoute } from "@tanstack/react-router"; | ||
|
|
||
| export const Route = createFileRoute("/code/inbox")({ | ||
| component: InboxView, | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,44 @@ | ||
| import { TaskInput } from "@features/task-detail/components/TaskInput"; | ||
| import { useNavigationStore } from "@stores/navigationStore"; | ||
| import { createFileRoute } from "@tanstack/react-router"; | ||
|
|
||
| export const Route = createFileRoute("/code/")({ | ||
| component: CodeIndexRoute, | ||
| }); | ||
|
|
||
| function CodeIndexRoute() { | ||
| const view = useNavigationStore((s) => s.view); | ||
| const taskInputReportAssociation = useNavigationStore( | ||
| (s) => s.taskInputReportAssociation, | ||
| ); | ||
| const taskInputCloudRepository = useNavigationStore( | ||
| (s) => s.taskInputCloudRepository, | ||
| ); | ||
|
|
||
| const initialPrompt = | ||
| view.type === "task-input" ? view.initialPrompt : undefined; | ||
| const initialPromptKey = | ||
| view.type === "task-input" ? view.taskInputRequestId : undefined; | ||
| const initialCloudRepository = | ||
| view.type === "task-input" | ||
| ? (view.initialCloudRepository ?? taskInputCloudRepository) | ||
| : taskInputCloudRepository; | ||
| const initialModel = | ||
| view.type === "task-input" ? view.initialModel : undefined; | ||
| const initialMode = view.type === "task-input" ? view.initialMode : undefined; | ||
| const reportAssociation = | ||
| view.type === "task-input" | ||
| ? (view.reportAssociation ?? taskInputReportAssociation) | ||
| : taskInputReportAssociation; | ||
|
|
||
| return ( | ||
| <TaskInput | ||
| initialPrompt={initialPrompt} | ||
| initialPromptKey={initialPromptKey} | ||
| initialCloudRepository={initialCloudRepository} | ||
| initialModel={initialModel} | ||
| initialMode={initialMode} | ||
| reportAssociation={reportAssociation} | ||
| /> | ||
| ); | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
window.history.pushState({ settingsOpen: true })call inopen()is now dead (see companion comment), the guard here readingwindow.history.state?.settingsOpenis always false andwindow.history.back()is never called. This dead branch can be removed, leaving just therouter.navigate({ to: "/code" })path to handle the URL change on close.Prompt To Fix With AI