fix(editor): keep query results when switching between connections - #586
Open
iamthenuggetman wants to merge 1 commit into
Open
fix(editor): keep query results when switching between connections#586iamthenuggetman wants to merge 1 commit into
iamthenuggetman wants to merge 1 commit into
Conversation
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
Contributor
Code Review SummaryStatus: No Issues Found | Recommendation: Merge Files Reviewed (2 files)
Reviewed by ling-3.0-flash-free · Input: 72.5K · Output: 8.8K · Cached: 486K |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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
EditorProviderre-runs on everyactiveConnectionIdchange and replaces the connection's live tabs with the storage copies — and tabs are persisted result-stripped (cleanTabForStorageremovesresult,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/activeTabIdschange →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
pendingNotebookRef) is unaffected: with the target connection already loaded, the deferred open resolves immediately instead of waiting out a redundant load.Test plan
tests/contexts/EditorProvider.test.tsxsimulating 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 thatload_editor_preferencesran 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: cleaneslinton changed source: cleandemo/Docker stack (MySQL + PostgreSQL connections): results survive switching away and back; tabs still restore correctly from storage after an app restart.