Skip to content

Reduce App.tsx god-component state#127

Open
nkcoder wants to merge 2 commits into
mainfrom
enhancement/116-reduce-app-god-state
Open

Reduce App.tsx god-component state#127
nkcoder wants to merge 2 commits into
mainfrom
enhancement/116-reduce-app-god-state

Conversation

@nkcoder

@nkcoder nkcoder commented Jul 3, 2026

Copy link
Copy Markdown
Owner

Closes #116.

What changed

App.tsx owned ~20 useState hooks spanning routing, config, dialogs, history, metadata cache, panel visibility, and connection warnings. Extracted the two biggest async-stateful clusters into cohesive hooks under hooks/ (matching the existing useTabManager / useQueryExecution / usePanelResize convention):

useDatasourceSession — the connection + metadata lifecycle the issue explicitly named:

  • Owns activeDatasourceId, savedQueries, completions, metadataByDs (exposed as a derived metadata), and connectionWarning.
  • Provides connect / disconnect / refreshMetadata.
  • App keeps the tab/results/view orchestration around connect/disconnect — the hook only owns session data, so the cross-cutting concerns stay where they belong.

useQueryHistory — the history drawer's open / entries / loading state + 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

  • Related state grouped / lifecycle extracted into a hook
  • Data flow easier to follow; re-render scope not widened — both hooks run inside App's fiber, so their state lives exactly where it did; no new context providers wrapping subtrees
  • No behavior change; existing suites pass

Testing

  • Pure internal refactor — child components and their props are untouched.
  • npm run test448 vitest tests pass unchanged (App.test.tsx + App.handlers.test.tsx drive connect/disconnect/history/metadata-warning through the real App with stubbed children).
  • +10 new hook unit tests (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).
  • Affected e2e specs (history, connection-browse, sidebar) — 20 pass.
  • npm run build (tsc + Vite) clean; biome clean.

nkcoder added 2 commits July 3, 2026 20:34
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.
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.

Reduce App.tsx god-component state

1 participant