Skip to content

fix(editor): keep query results when switching between connections - #586

Open
iamthenuggetman wants to merge 1 commit into
TabularisDB:mainfrom
iamthenuggetman:fix/results-lost-on-connection-switch
Open

fix(editor): keep query results when switching between connections#586
iamthenuggetman wants to merge 1 commit into
TabularisDB:mainfrom
iamthenuggetman:fix/results-lost-on-connection-switch

Conversation

@iamthenuggetman

Copy link
Copy Markdown
Contributor

Summary

Closes #292

With two connections open, switching to another connection and back wiped the first connection's query results: the tab kept its SQL, but the result grid came back empty.

Root cause (as suspected in the issue): the tab-loading effect in EditorProvider re-runs on every activeConnectionId change and replaces the connection's live tabs with the storage copies — and tabs are persisted result-stripped (cleanTabForStorage removes result, error, executionTime, etc.). So switching back to an already-loaded connection clobbered live tabs holding results with result-less storage copies.

Fix

Skip the storage reload when the connection's tabs are already live in memory (EditorProvider.tsx). During a session the in-memory tab state is the source of truth — the continuous save effect (tabs/activeTabIds change → saveTabsToStorage) already keeps storage in sync for the next app start, so nothing is lost by not reloading.

This implements the issue's first suggested approach (guard on existing tabs). The merge-instead-of-reload alternative was unnecessary: the only reason to read storage is to restore tabs that aren't in memory, which by definition only happens on the first visit to a connection.

Side benefit: switching back to a loaded connection no longer flashes the loading state or re-runs the storage round-trip at all.

What doesn't change

  • First visit to a connection (including app start) still loads tabs from storage, including the legacy notebook-tab migration.
  • Closing all of a connection's tabs and revisiting still loads from storage (in-memory guard finds no tabs) and creates the initial tab.
  • Cross-connection notebook open (pendingNotebookRef) is unaffected: with the target connection already loaded, the deferred open resolves immediately instead of waiting out a redundant load.

Test plan

  • New regression test in tests/contexts/EditorProvider.test.tsx simulating the issue's exact repro: load conn-1's tab from storage → set a live result → switch to conn-2 (initial tab created) → switch back. Asserts the tab keeps its query and its result, and that load_editor_preferences ran only once for conn-1. Verified it fails without the fix and passes with it.
  • pnpm vitest run: full suite passes (3431 tests)
  • tsc -b: clean
  • eslint on changed source: clean
  • Manually verified with the demo/ Docker stack (MySQL + PostgreSQL connections): results survive switching away and back; tabs still restore correctly from storage after an app restart.

The tab-loading effect re-ran on every connection switch and replaced the
connection's live tabs with their storage copies. Since tabs are persisted
result-stripped, switching away and back wiped every tab's query results
while keeping the SQL (TabularisDB#292).

Skip the storage reload when the connection's tabs are already live in
memory — the in-memory state is the source of truth during a session, and
the continuous save effect keeps storage in sync for the next app start.

Closes TabularisDB#292
@kilo-code-bot

kilo-code-bot Bot commented Aug 1, 2026

Copy link
Copy Markdown
Contributor

Code Review Summary

Status: No Issues Found | Recommendation: Merge

Files Reviewed (2 files)
  • src/contexts/EditorProvider.tsx
  • tests/contexts/EditorProvider.test.tsx

Reviewed by ling-3.0-flash-free · Input: 72.5K · Output: 8.8K · Cached: 486K

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]: Query results disappear when switching away from and back to a connection

1 participant