-
Notifications
You must be signed in to change notification settings - Fork 3.3k
feat: implement core routing architecture with hybrid strategy #11460
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
base: v2
Are you sure you want to change the base?
Conversation
- Added AppStateService for managing application state in the database, including methods for getting, setting, and deleting state. - Introduced new API endpoint for app state storage with GET and PUT methods. - Integrated TanStack Router for routing, enabling a tabbed interface with dynamic routing and state synchronization. - Created AppShell component to manage layout and routing, including a sidebar and tab management. - Developed useTabs hook for handling tab state, including adding, closing, and switching tabs. - Updated package.json and yarn.lock to include necessary dependencies for routing and state management. This commit enhances the application's architecture by providing a robust state management system and a flexible routing mechanism, improving user experience and maintainability.
|
Note This issue/comment/review was translated by Claude. URL → DB: Listens to location.pathname and updates active tab's URL in SQLite This is a typical Cache behavior, not a DB behavior. Interacting with the DB brings unnecessary complexity. Original ContentURL → DB: Listens to location.pathname and updates active tab's URL in SQLite 这是个典型的 Cache 行为,而不是 db行为,和db交互,带来了没必要的复杂化 |
Note This issue/comment/review was translated by Claude. The top tabs need to be stored so that when users reopen the application, these tabs are retained, similar to browser tabs. I was struggling between using db or cache... I'll change it. Original Content顶部的Tab是需要做存储的,这样用户重新打开应用会保留这些Tab,行为类似浏览器tab |
|
- Remove /app/state/:key API endpoint from apiSchemas - Remove appStateService handler from API handlers - Add Tab/TabsState types to persist cache schema - Refactor useTabs to use usePersistCache instead of useQuery/useMutation - Delete unused routeTree.gen.ts This change improves performance by avoiding unnecessary IPC + DB roundtrips for UI state that can be safely stored in localStorage with 200ms debounce. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
|
Note This issue/comment/review was translated by Claude. There are naming conventions for cache keys. I've updated ESLint, you can adjust it further. Original Contentcache key的命名有规范,我更新了ESLint,可以再调整下 |
|
Note This issue/comment/review was translated by Claude.
ok Original Content
ok |
- Remove redundant 'ui.activeTabId' from UseCacheSchema (already in TabsState) - Rename 'tabs_state' to 'ui.tab.state' to follow ESLint naming rule - Update useTabs hook to use new cache key 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
- Introduced new markdown files detailing the architecture for Multi Page Application (MPA) with process isolation and Multi MemoryRouter instances. - The MPA document outlines the concept, configuration, implementation, and performance analysis, emphasizing faster initial load and crash isolation. - The Multi MemoryRouter document presents a recommended architecture for state preservation and tab management, addressing key requirements and providing a migration strategy. - The Single Router + Outlet document describes a hybrid approach for tab management, focusing on state synchronization and webview handling. This addition enhances the project's documentation, providing clear guidelines for future development and architectural decisions.
…r enhancements - Changed code snippets in the architecture documentation to use the `text` syntax for better clarity. - Replaced CSS `display:none` with React 19.2 `<Activity>` component for improved effect management and memory optimization. - Documented the design decision to use a Pure MemoryRouter over HashRouter for detached windows, emphasizing simplicity and consistency. - Enhanced the Tab Detach implementation with detailed explanations of state passing via URL query and IPC, along with architecture flow diagrams. - Added new components and functions to support detached tab functionality, including state restoration and memory management strategies. These updates improve the documentation and functionality of the tab management system, ensuring better performance and user experience.
…eTree.gen.ts - Added src/renderer/src/routeTree.gen.ts to the ESLint includes for linting. - Updated biome.jsonc to exclude src/renderer/src/routeTree.gen.ts from processing. - Ensured consistent formatting in routeTree.gen.ts by adding missing commas and disabling ESLint for the file.
- Introduced a new TabRouter component to manage routing for each tab independently, enhancing the tab management system. - Updated the AppShell component to utilize the new TabRouter, allowing for true KeepAlive behavior with isolated history. - Refactored the Sidebar component for improved navigation and tab creation, now supporting internal app routes. - Enhanced the useTabs hook to ensure at least one default tab exists, improving user experience on initial load. - Updated cacheSchemas to reflect changes in tab types and metadata structure. These changes significantly improve the architecture and functionality of the tab system, providing a more robust user experience.
|
Note This issue/comment/review was translated by Claude. Testing TSR + Tab + Multi MemoryRouter + Keepalive 20251205-170641.mp4Original Content测试 TSR + Tab + Multi MemoryRouter + Keepalive 20251205-170641.mp4 |
…docs - Fix TanStack Router path config using resolve() for absolute paths - Add openTab API to useTabs hook for Tab-level navigation - Remove AppRouter.tsx (merged into AppShell) - Add developer documentation (README.md, README.zh-CN.md) - Add settings route placeholder - Update App.tsx with TODO comments for migration 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
Summary
This PR implements the core routing architecture for Cherry Studio, with comprehensive research on Tab System + Router integration patterns.
Architecture Research
We identified a fundamental contradiction between URL Router design (single active view) and Tab system requirements (multiple views coexisting with state preservation). Three architecture approaches were documented:
architecture-single-outlet.mdarchitecture-multi-memory-router.mdarchitecture-mpa-webcontents.mdKey Requirements
Current Implementation
TanStack Router Integration
routes/__root.tsx,routes/index.tsx,routes/settings.tsx)routeTree.gen.ts)resolve()for absolute pathsMulti MemoryRouter Architecture
TabRoutercomponent with React 19<Activity>for KeepAliveMemoryRouterinstanceTab State Management
useTabshook withopenTabAPI for Tab-level navigationuseNavigatefor in-Tab navigationDeveloper Documentation
routes/README.md- English developer guideroutes/README.zh-CN.md- Chinese developer guideFiles Changed
TODO List
Feature 1: Multi-Tab Core ✅
TabRoutercomponent with React 19.2<Activity>for visibility controlcreateMemoryHistory+createRouterper Tab instanceuseTabshook enhancement withopenTabAPI (add/remove/switch/update)Tab,TabType,OpenTabOptions)Feature 2: Route Pages (In Progress)
/chat/$assistantId/$topicId)/settings)Feature 3: Tab Detach (Drag Out to Window)
DetachedTabWindowcomponent (read URL Query, init MemoryRouter)BrowserWindowwith query params)Feature 4: Tab Attach (Drag Back to Main)
tab:attach-request/tab:attach-response)Feature 5: Memory Management
🤖 Generated with Claude Code
Co-Authored-By: Claude [email protected]