Skip to content

createClient increases client-side bundle with server-only code #2768

@vintagesquid

Description

@vintagesquid

Describe the bug

All my pages are statically generated. I only run queries at build time. If I create my client with createClient from next-sanity there is a significant bundle increase in each of my pages where I'm using the client. On the other hand if I import it straight from the @sanity/client package the sanity client don't end up in my client bundle.
I also embed sanity studio in my NextJS application. If I remove it @sanity/next-loadergets into my bundle. (see screenshots)

To Reproduce

Steps to reproduce the behavior:

  1. Create sanity client with createClient from
  2. Fetch Sanity in NextJS App Router.
  3. Run build with @next/bundle-analyzer.

Expected behavior

To not increase my client-side bundle with unnecessary code.

Screenshots
I run next build with @next/bundle-analyzer.

With Sanity Studio:

Image

Without Sanity Studio:

Image

Which versions of Sanity are you using?

@sanity/cli (global) 4.6.1 (up to date)
@sanity/image-url 1.2.0 (up to date)
@sanity/locale-hu-hu 1.1.26 (up to date)
@sanity/vision 4.6.1 (up to date)
sanity 4.6.1 (up to date)

What operating system are you using?

macOs 15.6.1 (24G90)

Which versions of Node.js / npm are you running?
node: v22.17.0
pnpm: 10.15.1

Additional context

Sanity env (projectId, dataset....) is being shared between the studio and the client.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions