fix: Fix galaxy node clicking and navigation bugs
This commit fixes two critical bugs in the galaxy navigation: **Bug #1: Direct node URLs redirected to /chat** - Updated AppStateMachine to recognize /galaxy/* paths (including query params) as galaxy state - Changed line 55 from `pathname === '/galaxy'` to `pathname === '/galaxy' || pathname.startsWith('/galaxy/')` - Changed line 89 to compare pathname instead of lastNavigatedPathRef to preserve query params **Bug #2: Modal closed when clicking nodes** - Refactored ThoughtGalaxy to use URL query params (?node=xxx) instead of route params (/galaxy/node:xxx) - This prevents component unmounting when switching between nodes - Deleted app/galaxy/[node-id]/page.tsx (no longer needed) - Updated app/galaxy/page.tsx with documentation comment - Modified ThoughtGalaxy to: - Use useSearchParams() hook - Get selectedNodeId from query params - Update URL with query params on node click (doesn't cause remount) - Clear query params when modal closes **Testing:** - Verified manually with Playwright MCP that /galaxy?node=xxx preserves query params - Verified state machine correctly recognizes galaxy state - Created comprehensive Playwright test suite in tests/playwright/galaxy.spec.ts **Files changed:** - components/AppStateMachine.tsx: Fixed state machine to handle /galaxy/* paths and preserve query params - components/ThoughtGalaxy.tsx: Refactored to use query params instead of route params - app/galaxy/page.tsx: Added documentation - app/galaxy/[node-id]/page.tsx: Deleted (replaced with query param approach) - tests/playwright/galaxy.spec.ts: Added comprehensive test suite 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -52,7 +52,7 @@ export function AppStateMachineProvider({ children }: { children: React.ReactNod
|
||||
initialEvent = 'NAVIGATE_TO_CONVO';
|
||||
} else if (pathname === '/edit') {
|
||||
initialEvent = 'NAVIGATE_TO_EDIT';
|
||||
} else if (pathname === '/galaxy') {
|
||||
} else if (pathname === '/galaxy' || pathname.startsWith('/galaxy/')) {
|
||||
initialEvent = 'NAVIGATE_TO_GALAXY';
|
||||
}
|
||||
|
||||
@@ -84,8 +84,9 @@ export function AppStateMachineProvider({ children }: { children: React.ReactNod
|
||||
targetPath = '/galaxy';
|
||||
}
|
||||
|
||||
// ONLY navigate if we have a target path and haven't already navigated to it
|
||||
if (targetPath && targetPath !== lastNavigatedPathRef.current) {
|
||||
// ONLY navigate if we need to change the pathname (not the whole URL)
|
||||
// This preserves query params and prevents unnecessary navigation
|
||||
if (targetPath && pathname !== targetPath) {
|
||||
console.log('[App Provider] State machine navigating to:', targetPath);
|
||||
lastNavigatedPathRef.current = targetPath;
|
||||
router.push(targetPath);
|
||||
|
||||
Reference in New Issue
Block a user