fix(datagrid): isolate per-tab state in structure view#1142
Merged
Conversation
|
You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard. |
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.
Fixes #1110
Root cause
Two distinct bugs from the same architectural assumption: a single
DataGridViewinstance was being reused across the Columns / Indexes / Foreign Keys sub-tabs of the structure view, but state scoped to "this DataGridView" was bleeding between tabs.Bug 1: stale data on tab switch
DataGridCoordinator.displayCacheis keyed byRowIDKey(row.id).TableRows.from(queryRows:...)mints IDs as.existing(0),.existing(1), ... by array index, so row 0 of Columns and row 0 of Indexes share the same key. When SwiftUI re-renders to swap datasets between tabs,updateNSViewrebuiltidentitySchemaand reloaded the table, but never flusheddisplayCache. Each cell call hit the cache and rendered the previous tab's value.The DDL → back fix worked by accident: routing through a non-grid view forces SwiftUI to tear down the NSTableView, so
makeNSViewbuilt a fresh coordinator with an empty cache.applyFullReplace()already invalidates this cache, but it only fires on change-manager Delta events. Tab switches go through SwiftUI re-render and bypass that path entirely.Bug 2: badge counts disappear on refresh
onRefreshDataclearedloadedTabsthen only re-fetched columns and the active tab.tabLabel(for:)shows a count only when the tab is inloadedTabs, so the two non-active tabs lost their badges.loadInitialDataloads all three by contrast, which is why counts appear correct on first open.Cross-tab state pollution
While tracing the cache bug, the same single-instance assumption showed up in two more places:
selectedRows(@StateonTableStructureView) carried selection across tabs even though row N has no shared meaning between Columns and Indexes.structureColumnLayout(@State) was a singleColumnLayoutState, soDataGridColumnPool.reconcilesawwillRestoreWidths = truefor the new tab, looked up Indexes column names in the Columns widths dict, missed, and fell back to a hardcoded width of 100 instead of running the auto-fitwidthCalculator.Fixes
DataGridCoordinator.rebuildColumnMetadataCachenow returns whether the schema changed and invalidatesdisplayCachewhen it does.DataGridView.updateNSViewrolls a schema change intoneedsFullReload. This generalizes — query tabs that re-execute with a different schema benefit too.TableStructureView+DataLoading.onRefreshDatare-fetches columns + indexes + foreign keys (when supported), so badge counts persist across refresh just like initial load.onSelectedTabChangedresetsselectedRows = [].structureColumnLayoutbecomes[StructureTab: ColumnLayoutState]with a per-tabBinding, so each sub-tab keeps its own widths, order, and hidden columns without polluting siblings.Test plan