feat: support server-only and client-only modules (#2162)#2167
feat: support server-only and client-only modules (#2162)#2167YanAnghelp wants to merge 5 commits into
server-only and client-only modules (#2162)#2167Conversation
✅ Deploy Preview for solid-start-landing-page ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
🦋 Changeset detectedLatest commit: e2ccf48 The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
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 |
commit: |
There was a problem hiding this comment.
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-onlyis imported in non-SSR builds orclient-onlyis imported in SSR builds. - Add TypeScript module declarations for
server-onlyandclient-onlyto 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.
| return "\0solid-start:boundary-modules:id"; | ||
| }, | ||
| load(id) { | ||
| if (id === "\0solid-start:boundary-modules:id") return "export {}"; | ||
| }, |
There was a problem hiding this comment.
Because the returned value is just the fixed "export {}", this will not cause any actual bugs. This can be regarded as a style suggestion.
There was a problem hiding this comment.
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.
| this.error( | ||
| `Attempt to import 'server-only' in a client module: ${importer}`, | ||
| ); |
| this.error( | ||
| `Attempt to import 'client-only' in a server module: ${importer}`, | ||
| ); |
Closes #2162