fix(react): resolve fallow unused-export on SanityDocument - #1219
Conversation
The react barrel re-exports SanityDocument from @sanity/types in _exports/sdk-react.ts, and so does core's barrel, which _exports/index.ts picks up via `export * from '@sanity/sdk'`. fallow does not count the sdk-react.ts copy as reaching an entry and reports it as an unused type export. Adding SanityDocument to the existing shadow list on index.ts:4 makes the react-layer re-export the reachable one, clearing the finding with no change to the published type surface (104 exports before and after). Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QVzw8e5HYjpdkypCwpHvkw
Bundle Stats✅ No significant changes. All scenario measurements (8)🗺️
Significant means at least 1.0 KB and 1% gzip, or at least 5 ms and 10% import time. |
📚 TypeDoc Generation Result✅ TypeDoc generated successfully!
The package TypeDoc JSON files and combined HTML site have been generated successfully. |
Coverage Report
File CoverageNo changed files found. |
|
The red
It is not a required check, and it is unrelated to the contents of this diff — every required check on this head is green, The fix is adding Generated by Claude Code |
Requested by Josh Ellis
Description
Before:
packages/react/src/_exports/sdk-react.tsre-exportsSanityDocumentfrom@sanity/types, and core's barrel re-exports the same type from the same package, which_exports/index.tspicks up throughexport * from '@sanity/sdk'. fallow does not count thesdk-react.tscopy as reaching an entry point, so it reports it as an unused type export. The finding is old — it sits onmaintoday and has since PR #393 (April 2025) turned the react barrel into a star re-export of core — butfallow auditruns with thenew-onlygate, which attributes findings byfile:line. Any PR that inserts an export above that line shifts its line number and gets blamed for a finding it did not introduce. That is currently reddening thefallowcheck on #1216 (line 111 to 112) and #1213 (line 109 to 111).After:
SanityDocumentjoins the shadow list on_exports/index.ts:4, alongsideDocumentHandle,DocumentTypeHandleandResourceHandle— the list whose comment on the line above already says the react layer shadows core's equivalents. Thesdk-react.tsre-export becomes the reachable export, fallow reports nothing, and the published type surface is unchanged: 104 exports inpackages/react/dist/index.d.tsbefore and after, with nothing added or removed.One line, adding
SanityDocumentto an existing explicit re-export, so that every PR that adds an export to the react barrel stops inheriting the blame.How: the naive version of this fix — deleting
type SanityDocumentfromsdk-react.tsand letting core's re-export cover it — would have been a breaking change, which is worth recording.@sanity/pkg-utils/api-extractor flattens the declaration bundle into a single explicitexport { ... }list and does not emitexport * from '@sanity/sdk', so core's re-export never carries the type into the shipped.d.ts. Building that variant drops the react package from 104 to 103 exports, withSanityDocumentsurviving only inside TSDoc comment text. Pinning the react-layer re-export as the winner instead keeps the type where it is.What to review
The one-line diff in
packages/react/src/_exports/index.ts, and whether addingSanityDocumentto that shadow list reads as intended rather than incidental — the type comes from@sanity/typesand both the react and core barrels resolve to the identical@sanity/types@6.13.0declaration, so this is a plain pass-through, not a narrowed variant.Worth a second opinion on the follow-up this does not do: fallow attributing a line-shifted pre-existing finding as new is an upstream issue, and there may be other findings in the repo positioned to bite the same way.
Testing
Run locally against
origin/main:pnpm fallow audit --base origin/main— passes, no findings (caches cleared first).fallow dead-codereportsunused_types: [].pnpm build:packages— core and react build clean.main: 104 exports before, 104 after, no additions or removals.packages/react:tsc --noEmitclean,eslint .clean (2 pre-existing warnings),vitest run76 files, 400 passed / 3 skipped.No new test: the change adds nothing executable, and the property that matters — the package's exported type surface — is asserted by the build's declaration output, which is unchanged. Nothing in the monorepo imports
SanityDocumentfrom@sanity/sdk-react; the kitchensink takes it fromsanityand the e2e helpers useSanityDocumentStubfrom@sanity/client.Documentation
No docs change needed. The public TSDoc examples that reference the type —
useEditDocument.ts:194anduseDocument.ts:177, both showingimport {..., type SanityDocument} from '@sanity/sdk-react'— stay accurate, which is the point of keeping the export.Fun gif
🤖 Generated with Claude Code
https://claude.ai/code/session_01QVzw8e5HYjpdkypCwpHvkw
Generated by Claude Code