Просмотр исходного кода

Add debug logging for multi-table WebSocket issue

Adds console.log statements to track:
- When setBaseUrl is called and with what values
- What WebSocket URLs are generated
- Table restoration from localStorage and URL comparison

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
tuanchris 2 недель назад
Родитель
Сommit
b69f0c67cc
2 измененных файлов с 18 добавлено и 3 удалено
  1. 12 1
      frontend/src/contexts/TableContext.tsx
  2. 6 2
      frontend/src/lib/apiClient.ts

+ 12 - 1
frontend/src/contexts/TableContext.tsx

@@ -91,7 +91,18 @@ export function TableProvider({ children }: { children: React.ReactNode }) {
             // Set base URL for remote tables (tables not on the current origin)
             // Use normalized URL comparison to handle port differences (e.g., :80 vs no port)
             // Don't rely on isCurrent flag as it may be stale from localStorage
-            if (normalizeUrlOrigin(active.url) !== window.location.origin) {
+            const normalizedActiveUrl = normalizeUrlOrigin(active.url)
+            const currentOrigin = window.location.origin
+            const isRemoteTable = normalizedActiveUrl !== currentOrigin
+            console.log('[TableContext] Restoring active table:', {
+              activeId,
+              activeUrl: active.url,
+              normalizedActiveUrl,
+              currentOrigin,
+              isRemoteTable,
+              willSetBaseUrl: isRemoteTable,
+            })
+            if (isRemoteTable) {
               apiClient.setBaseUrl(active.url)
             }
           }

+ 6 - 2
frontend/src/lib/apiClient.ts

@@ -35,6 +35,7 @@ class ApiClient {
     const newUrl = url.replace(/\/$/, '')
     // Only notify if the URL actually changed
     if (newUrl === this._baseUrl) return
+    console.log('[ApiClient] setBaseUrl:', { from: this._baseUrl || '(empty)', to: newUrl || '(empty)' })
     this._baseUrl = newUrl
     // Notify listeners
     this._listeners.forEach(listener => listener(this._baseUrl))
@@ -131,11 +132,12 @@ class ApiClient {
     // Ensure endpoint starts with /
     const path = endpoint.startsWith('/') ? endpoint : `/${endpoint}`
 
+    let wsUrl: string
     if (this._baseUrl) {
       // Parse the base URL to get host
       const url = new URL(this._baseUrl)
       const protocol = url.protocol === 'https:' ? 'wss:' : 'ws:'
-      return `${protocol}//${url.host}${path}`
+      wsUrl = `${protocol}//${url.host}${path}`
     } else {
       // Use current page's host for relative URLs
       const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:'
@@ -144,8 +146,10 @@ class ApiClient {
       const host = window.location.hostname
       const port = import.meta.env.DEV ? '8080' : window.location.port
       const portSuffix = port ? `:${port}` : ''
-      return `${protocol}//${host}${portSuffix}${path}`
+      wsUrl = `${protocol}//${host}${portSuffix}${path}`
     }
+    console.log('[ApiClient] getWebSocketUrl:', { baseUrl: this._baseUrl || '(empty)', wsUrl })
+    return wsUrl
   }
 
   /**