Skip to content

fix(react): resolve fallow unused-export on SanityDocument - #1219

Merged
joshuaellis merged 1 commit into
mainfrom
fix/fallow-unused-sanity-document-reexport
Sep 11, 2026
Merged

joshuaellis merged 1 commit into
mainfrom
fix/fallow-unused-sanity-document-reexport

Conversation

@claude

@claude claude Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Requested by Josh Ellis

Description

Before: packages/react/src/_exports/sdk-react.ts re-exports SanityDocument from @sanity/types, and core's barrel re-exports the same type from the same package, which _exports/index.ts picks up through export * from '@sanity/sdk'. fallow does not count the sdk-react.ts copy as reaching an entry point, so it reports it as an unused type export. The finding is old — it sits on main today and has since PR #393 (April 2025) turned the react barrel into a star re-export of core — but fallow audit runs with the new-only gate, which attributes findings by file: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 the fallow check on #1216 (line 111 to 112) and #1213 (line 109 to 111).

After: SanityDocument joins the shadow list on _exports/index.ts:4, alongside DocumentHandle, DocumentTypeHandle and ResourceHandle — the list whose comment on the line above already says the react layer shadows core's equivalents. The sdk-react.ts re-export becomes the reachable export, fallow reports nothing, and the published type surface is unchanged: 104 exports in packages/react/dist/index.d.ts before and after, with nothing added or removed.

One line, adding SanityDocument to 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 SanityDocument from sdk-react.ts and 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 explicit export { ... } list and does not emit export * 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, with SanityDocument surviving 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 adding SanityDocument to that shadow list reads as intended rather than incidental — the type comes from @sanity/types and both the react and core barrels resolve to the identical @sanity/types@6.13.0 declaration, 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-code reports unused_types: [].
  • pnpm build:packages — core and react build clean.
  • Published type surface diffed against main: 104 exports before, 104 after, no additions or removals.
  • packages/react: tsc --noEmit clean, eslint . clean (2 pre-existing warnings), vitest run 76 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 SanityDocument from @sanity/sdk-react; the kitchensink takes it from sanity and the e2e helpers use SanityDocumentStub from @sanity/client.

Documentation

No docs change needed. The public TSDoc examples that reference the type — useEditDocument.ts:194 and useDocument.ts:177, both showing import {..., 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

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
@github-actions

github-actions Bot commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

Bundle Stats

✅ No significant changes.

All scenario measurements (8)

🗺️ @sanity/sdk / @sanity/sdk · @sanity/sdk / @sanity/sdk/_internal · @sanity/sdk / @sanity/sdk/agent · @sanity/sdk / @sanity/sdk/comlink · @sanity/sdk / @sanity/sdk/dashboard · @sanity/sdk-react / @sanity/sdk-react · @sanity/sdk-react / @sanity/sdk-react/dashboard · @sanity/sdk-react / @sanity/sdk-react/dashboard/_internal · Artifacts

Scenario Kind Bundle (raw / gzip) Gzip change Import time Import change
⚪ @sanity/sdk / @sanity/sdk export 1.13 MB / 258.3 KB None 138 ms -1 ms, -0.4%
⚪ @sanity/sdk / @sanity/sdk/_internal export 587.6 KB / 133.9 KB None 108 ms +5 ms, +5.3%
⚪ @sanity/sdk / @sanity/sdk/agent export 414.5 KB / 90.9 KB None 96 ms +1 ms, +1.2%
⚪ @sanity/sdk / @sanity/sdk/comlink export 257.3 KB / 59.8 KB None 105 ms -1 ms, -1.1%
⚪ @sanity/sdk / @sanity/sdk/dashboard export 45.8 KB / 10.7 KB None 35 ms -2 ms, -6.4%
⚪ @sanity/sdk-react / @sanity/sdk-react export 1.41 MB / 328.6 KB None 169 ms +8 ms, +5.2%
⚪ @sanity/sdk-react / @sanity/sdk-react/dashboard export 651.6 KB / 148.8 KB None 147 ms -0 ms, -0.0%
⚪ @sanity/sdk-react / @sanity/sdk-react/dashboard/_internal export 50.5 KB / 11.0 KB None 101 ms -2 ms, -1.5%

Significant means at least 1.0 KB and 1% gzip, or at least 5 ms and 10% import time.

@github-actions

Copy link
Copy Markdown
Contributor

📚 TypeDoc Generation Result

✅ TypeDoc generated successfully!

  • JSON file size: 2.8M
  • Total exports: 401
  • Artifact: typedoc-html-pr-1219
  • HTML docs preview: Download artifact

The package TypeDoc JSON files and combined HTML site have been generated successfully.

@claude
claude Bot marked this pull request as ready for review September 11, 2026 13:03
@claude
claude Bot requested a review from a team as a code owner September 11, 2026 13:03
@claude
claude Bot requested a review from mariuslundgard September 11, 2026 13:03
@github-actions

Copy link
Copy Markdown
Contributor

Coverage Report

Status Category Percentage Covered / Total
🟢 Lines 97.13% (🎯 94%) 5593 / 5758
🟢 Statements 95.81% (🎯 93%) 6072 / 6337
🟢 Functions 97.15% (🎯 94%) 1637 / 1685
🟢 Branches 89.68% (🎯 86%) 3279 / 3656
File CoverageNo changed files found.
Generated in workflow #5950 for commit 8e85a65 by the Vitest Coverage Report Action

@claude

claude Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

The red claude-review check is a bot-actor guard, not a finding against this diff.

.github/workflows/claude-code-review.yml sets allowed_bots: 'cursor,renovate' (lines 65 and 104), and this PR is authored by claude[bot], so the action bails before it reads a single line of the change. The failing step is "Run Claude Code Review", and its annotation is:

Action failed with error: Workflow initiated by non-human actor: claude (type: Bot). Add bot to allowed_bots list or use '*' to allow all bots.

It is not a required check, and it is unrelated to the contents of this diff — every required check on this head is green, fallow included.

The fix is adding claude to that allowed_bots list. That belongs in a separate workflow PR rather than widening this one, which is deliberately a single line in the react barrel.


Generated by Claude Code

@joshuaellis
joshuaellis merged commit 1db8f9a into main Sep 11, 2026
24 of 25 checks passed
@joshuaellis
joshuaellis deleted the fix/fallow-unused-sanity-document-reexport branch September 11, 2026 13:09
@squiggler-app squiggler-app Bot mentioned this pull request Sep 10, 2026
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.

2 participants