Skip to content

feat: support server-only and client-only modules (#2162)#2167

Open
YanAnghelp wants to merge 5 commits into
solidjs:mainfrom
YanAnghelp:feat/boundary-modules
Open

feat: support server-only and client-only modules (#2162)#2167
YanAnghelp wants to merge 5 commits into
solidjs:mainfrom
YanAnghelp:feat/boundary-modules

Conversation

@YanAnghelp

Copy link
Copy Markdown

Closes #2162

@netlify

netlify Bot commented Jun 26, 2026

Copy link
Copy Markdown

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

Name Link
🔨 Latest commit e2ccf48
🔍 Latest deploy log https://app.netlify.com/projects/solid-start-landing-page/deploys/6a5956841ca0cd0008851e28
😎 Deploy Preview https://deploy-preview-2167--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 26, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: e2ccf48

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 Minor

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 26, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/@solidjs/start@2167

commit: e2ccf48

Comment thread packages/start/src/config/index.ts

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds first-class support in SolidStart’s Vite configuration for the conventional server-only and client-only modules, enabling build-time enforcement of server/client module boundaries (as requested in #2162).

Changes:

  • Add a Vite pre-enforced plugin that errors when server-only is imported in non-SSR builds or client-only is imported in SSR builds.
  • Add TypeScript module declarations for server-only and client-only to avoid TS resolution errors for side-effect imports.
  • Add a changeset to ship the feature as a minor bump for @solidjs/start.

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated 3 comments.

File Description
packages/start/src/config/index.ts Introduces the boundary-enforcement Vite plugin for server-only / client-only.
packages/start/env.d.ts Declares server-only and client-only modules for TypeScript consumers.
.changeset/support-server-client-only.md Publishes the feature as a minor release change.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +229 to +233
return "\0solid-start:boundary-modules:id";
},
load(id) {
if (id === "\0solid-start:boundary-modules:id") return "export {}";
},

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because the returned value is just the fixed "export {}", this will not cause any actual bugs. This can be regarded as a style suggestion.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Starting from Vite 6, Each environment has an isolated module graph. However, here it is specifically bound to the environment, so server-only and client-only actually point to different modules.

Comment on lines +218 to +220
this.error(
`Attempt to import 'server-only' in a client module: ${importer}`,
);
Comment on lines +223 to +225
this.error(
`Attempt to import 'client-only' in a server module: ${importer}`,
);
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

3 participants