Reduce App.tsx god-component state#127
Open
nkcoder wants to merge 2 commits into
Open
Conversation
App.tsx owned ~20 useState hooks mixing routing, config, dialogs, history, metadata, panels, and connection warnings. Extract the two biggest async-stateful clusters into cohesive hooks: - useDatasourceSession: activeDatasourceId, savedQueries, completions, metadata cache, connectionWarning + connect/disconnect/refreshMetadata. App keeps tab/results/view orchestration; the hook owns session data. - useQueryHistory: history drawer open/entries/loading + openHistory. Pure internal refactor — no behavior change. Hooks live in App's fiber so render scope is unchanged. Adds hook unit tests (10). Full vitest suite (448) and affected e2e specs (20) pass unchanged. Closes #116
connect() fires GetCachedMetadata and refreshMetadata concurrently; if the live refresh resolved first, the later-arriving cache overwrote the fresh metadata. Guard the cache write to only fill in when nothing has landed yet, so the live refresh is always the last word. Adds a regression test covering the live-before-cache ordering.
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.
Closes #116.
What changed
App.tsxowned ~20useStatehooks spanning routing, config, dialogs, history, metadata cache, panel visibility, and connection warnings. Extracted the two biggest async-stateful clusters into cohesive hooks underhooks/(matching the existinguseTabManager/useQueryExecution/usePanelResizeconvention):useDatasourceSession— the connection + metadata lifecycle the issue explicitly named:activeDatasourceId,savedQueries,completions,metadataByDs(exposed as a derivedmetadata), andconnectionWarning.connect/disconnect/refreshMetadata.useQueryHistory— the history drawer'sopen/entries/loadingstate +openHistory. Selecting an entry stays in App (it touches tab state).Routing/dialog/panel booleans were deliberately left in
App— they're synchronous and self-contained; wrapping them would add indirection without clarity gain (Simplicity First).Acceptance criteria
App's fiber, so their state lives exactly where it did; no new context providers wrapping subtreesTesting
npm run test— 448 vitest tests pass unchanged (App.test.tsx + App.handlers.test.tsx drive connect/disconnect/history/metadata-warning through the realAppwith stubbed children).useDatasourceSession.test.ts,useQueryHistory.test.ts) covering connect data-load, cached-then-live metadata, connection-failure warning, disconnect, and the history open/error/close paths — also helps the App-branch coverage gap (chore: enforce 95% unit test coverage + 80% E2E flow coverage #51).history,connection-browse,sidebar) — 20 pass.npm run build(tsc + Vite) clean; biome clean.