Skip to content

fix: lazy-load Sanity preview deps to reduce bundle size - #36

Merged
petercr merged 4 commits into
mainfrom
fix/sanity-bundle-optimization
Mar 24, 2026
Merged

fix: lazy-load Sanity preview deps to reduce bundle size#36
petercr merged 4 commits into
mainfrom
fix/sanity-bundle-optimization

Conversation

@petercr

@petercr petercr commented Mar 24, 2026

Copy link
Copy Markdown
Owner

Summary

  • Lazy-load @sanity/react-loader by moving preview data fetching into a new PreviewWrapper component loaded via React.lazy()
  • Delete unused SanityLiveMode.tsx
  • Remove withPreviewData HOC from withDocument.tsx, keeping only withPublishedData

Reduces eagerly-loaded Sanity JS from ~73 kB to ~17 kB for non-preview users (~55 kB savings).

Closes #35

Test plan

  • npm run type-check passes
  • npm run build succeeds with no errors
  • Verify production pages load without regressions
  • Verify preview mode still works in Sanity Studio presentation tool

🤖 Generated with Claude Code

Move @sanity/react-loader out of the eagerly-loaded client bundle by
lazy-loading preview data fetching. Removes ~55 kB from the initial JS
payload for non-preview users.

- Delete unused SanityLiveMode.tsx
- Create PreviewWrapper component (lazy-loaded) for preview data fetching
- Remove withPreviewData HOC from withDocument.tsx
- Update Document and Home pages to use lazy PreviewWrapper
@vercel

vercel Bot commented Mar 24, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
ccw Ready Ready Preview, Comment Mar 24, 2026 6:41pm

…ompatibility

Also add dedicated vitest.config.ts to prevent test runner from loading
TanStack Start/Nitro plugins, which caused tests to hang.
@petercr
petercr merged commit 01a2303 into main Mar 24, 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.

Looks like parts of Sanity are still getting shipped to the frontend

1 participant