Skip to content

Use one DocDetail type and stop casting fetch* query results - #361

Merged
byronwall merged 1 commit into
mainfrom
claude/doc-detail-one-type
Nov 28, 2026
Merged

byronwall merged 1 commit into
mainfrom
claude/doc-detail-one-type

Conversation

@byronwall

@byronwall byronwall commented Nov 28, 2026 •

Copy link
Copy Markdown
Owner

The note page, the note side panel and the editor now read the note type that fetchDoc returns, so a change to that type reaches all three. A new lint rule stops the old pattern from coming back.

User impact: None. Types and lint only.

Why

The note page and side panel each kept a hand-copied DocDetail, and the editor kept a DocData. Each read the query through fetchDoc(id) as Promise<…>. The cast hid the copies from tsc: a field added to or removed from the real type in services/docs.queries.ts would not reach those files, and nothing would fail. The side panel's copy had already drifted (optional dates, no archive).

This is the first probe of a cleanup loop where one batch moves every caller, deletes the old copy, and adds a check, all in one PR (planning TASK-0017, srcly-cleanup-loop.md). srcly's symbol index found the copies and their callers.

Proof

Callers found by srcly's symbol index before the change:

src/components/DocumentSidePanel.tsx#DocDetail  exported=False  <- fetchDocDetail, DocumentSidePanel
src/routes/docs/[id].tsx#DocDetail              exported=False  <- fetchDocDetail, DocView
src/services/docs.queries.ts#DocDetail          exported=True   <- loadDocDetail, fetchDocLatest
src/components/DocumentEditor.tsx#DocData       exported=False  <- fetchDocData, DocumentEditor.checkRemote

After the change, one declaration and no casts are left:

$ git grep -nP "(type|interface) (DocDetail|DocData)\b" -- app/src
app/src/services/docs.queries.ts:10:export type DocDetail = {
$ git grep -n "fetchDoc(id) as\|fetchDocLatest(.*) as" -- app/src
(no output)

The new rule fails on the old code. With routes/docs/[id].tsx put back from main:

src/routes/docs/[id].tsx:48:40: error vn(no-query-result-cast): Do not cast a fetch* query's result. …
src/routes/docs/[id].tsx:81:19: error vn(no-query-result-cast): Do not cast a fetch* query's result. …
lint exit with old file: 1
lint exit on branch: 0

Without its exceptions the rule finds exactly the 8 older casts that grep -rnE "\) as Promise<|\(await [^)]*\)\) as " finds (minus the .json() boundary casts), and no other hits.

Checks on this branch: pnpm type-check passed, pnpm lint passed (warnings only, all from before), and pnpm test passed (924 passed, 86 skipped). Against an isolated audit DB I ran the e2e specs that cover the note page, the side panel and live sync: live-note-updates, note-title-hydration, canvas-note-panel, late-note-share-responses, collection-peek-guard, note-session-recovery, inline-title-failed-save. On a warm server, 15 passed, 4 skipped and 2 failed when run in parallel. Those two passed 6 of 6 with --repeat-each 3 --workers 1. A run of main on the same server passed all 17.

Product scope: srcly's same-named-type scan over all of app/ dropped from 23 groups to 22. DocDetail is gone and no group was added.

Limits

  • Six files still cast a fetch* result: LLMSidebar.tsx, routes/embeddings/[id].tsx, routes/umap/[id]/index.tsx, routes/ai/prompts/[id].tsx, routes/ai/index.tsx, routes/ai/runs/[id].tsx. .oxlintrc.json lists them as exceptions. Remove a file from that list when its local copy goes.
  • The rule matches calls named fetch + an uppercase letter, which is the query naming here. A query with another name is not covered.
  • The first parallel e2e run on a cold server failed 12 specs, several on the sign-in page. The warm reruns above are the result that counts.

Stack: type cleanup

What splits: Removing hand-copied query types, in two batches: DocDetail here, then every other copy that srcly and lint found.
Why it splits: This layer can merge alone. It sets the pattern and the cast rule on one type.
Why this split: Each layer is one closed batch with its own callers, deletions and check. One PR per type was rejected, because the exceptions list would stay open across many PRs.

  1. Use one DocDetail type and stop casting fetch* query results #361: DocDetail and the vn/no-query-result-cast rule.
  2. Use query types everywhere and lint against copies #362: the remaining copies and casts, which empties this PR's exceptions list, and the vn/no-query-type-redeclare rule.

🤖 Generated with Claude Code

The note page and side panel each kept a hand-copied DocDetail, and the
editor a DocData, read through `fetchDoc(id) as Promise<...>`. The casts
hid the copies from tsc. All three now read the type that fetchDoc and
fetchDocLatest return. A new lint rule, vn/no-query-result-cast, fails
on a cast of a fetch* result; six files with older casts are listed as
exceptions until they are cleaned up.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@byronwall
byronwall force-pushed the claude/doc-detail-one-type branch from 3b320b5 to 028f585 Compare November 28, 2026 06:07
@byronwall

Copy link
Copy Markdown
Owner Author

Code review (medium, inline) before merge: nothing blocking.

🤖 Generated with Claude Code

@byronwall
byronwall merged commit f4448bf into main Nov 28, 2026
3 checks passed
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.

1 participant