feat(config): add server-only and client-only virtual module plugin#2165
Closed
tsushanth wants to merge 3 commits into
Closed
feat(config): add server-only and client-only virtual module plugin#2165tsushanth wants to merge 3 commits into
tsushanth wants to merge 3 commits into
Conversation
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
✅ Deploy Preview for solid-start-landing-page ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
🦋 Changeset detectedLatest commit: 7f63ec4 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: |
Contributor
|
This has 3 fixes all mixed together so I am going to close |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 runtimeimport.meta.env.SSRcheck that only fires in the browser, too late to be caught in CI.This PR adds a
solid-start:boundary-modulesVite plugin to the array returned bysolidStart(). It resolves two bare specifiers:server-only— callingthis.error()duringresolveIdwhenssris 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 buildor 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-onlyandclient-onlypackages, with no new dependencies.