Skip to content

feat(config): add server-only and client-only virtual module plugin#2165

Closed
tsushanth wants to merge 3 commits into
solidjs:mainfrom
tsushanth:feat/server-only-client-only-virtual-modules
Closed

feat(config): add server-only and client-only virtual module plugin#2165
tsushanth wants to merge 3 commits into
solidjs:mainfrom
tsushanth:feat/server-only-client-only-virtual-modules

Conversation

@tsushanth

Copy link
Copy Markdown

Closes #2162

SolidStart has no build-time mechanism to prevent a module from being bundled on the wrong side. "use server" marks functions as RPCs but does not stop a module containing DB credentials or Node-only APIs from leaking into the client bundle. The only workaround today is a runtime import.meta.env.SSR check that only fires in the browser, too late to be caught in CI.

This PR adds a solid-start:boundary-modules Vite plugin to the array returned by solidStart(). It resolves two bare specifiers:

  • server-only — calling this.error() during resolveId when ssr is false turns the import into a hard build error pointing at the importing file. In the SSR environment the specifier resolves to a virtual empty module.
  • client-only — the mirror: errors in the SSR environment, resolves to an empty module on the client.

Both produce zero runtime overhead (empty export). The build error surfaces the violating file path, so the mistake is caught at pnpm build or in CI rather than at runtime in the browser.

The implementation follows the shape suggested in the issue and mirrors what Next.js ships in its server-only and client-only packages, with no new dependencies.

Adds a solid-start:boundary-modules Vite plugin to solidStart() that
resolves the server-only and client-only bare specifiers at build time.

Importing server-only in a client-environment module raises a Vite build
error pointing at the importing file. Importing client-only in an SSR
module does the same. In the correct environment both resolve to an empty
module so they carry zero runtime overhead.

This gives SolidStart the same build-time safety guarantee that Next.js
provides through its own server-only/client-only packages, without
requiring users to wire up the plugin themselves.

Closes solidjs#2162
@netlify

netlify Bot commented Jun 25, 2026

Copy link
Copy Markdown

Deploy Preview for solid-start-landing-page ready!

Name Link
🔨 Latest commit 7f63ec4
🔍 Latest deploy log https://app.netlify.com/projects/solid-start-landing-page/deploys/6a3c7bf437238a0008a388ae
😎 Deploy Preview https://deploy-preview-2165--solid-start-landing-page.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
🤖 Make changes Run an agent on this branch

To edit notification comments on pull requests, go to your Netlify project configuration.

@changeset-bot

changeset-bot Bot commented Jun 25, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: 7f63ec4

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@solidjs/start Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new

pkg-pr-new Bot commented Jun 25, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/solidjs/solid-start/@solidjs/start@2165
npm i https://pkg.pr.new/solidjs/solid-start/@solidjs/vite-plugin-nitro-2@2165

commit: 7f63ec4

@brenelz

brenelz commented Jun 25, 2026

Copy link
Copy Markdown
Contributor

This has 3 fixes all mixed together so I am going to close

@brenelz brenelz closed this Jun 25, 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.

[Feature?]: Built-in server-only & client-only virtual module

2 participants