-
Notifications
You must be signed in to change notification settings - Fork 56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Outer variables referenced inside "use server" get treeshaken away. #296
Comments
Though the error reporting could be improved, I think this is intended behaviour. Functions with |
🤔 For NextJS’s server actions implementation as an example, the “use server” directive can only be used in server-side files though (whether or not the directive is declared at the top of a module or function). Implicitly, this would mean files with “use server” declared anywhere should be excluded from the client bundle (well, included in the client bundle with a shim based on createServerReference). I noticed that for Vinxi’s server functions that “use server” can technically be declared in functions in client-side code as well (causing client-side and server-side code to mix). It’s not that trivial to resolve which imports or functions inside of mixed client/server code should be included solely in the client bundle or server bundle in that case though. Is this intended behavior? |
I think it is intended behaviour yeah, since Vinxi doesn't have a separation between client and server files like React.
I think something that would help here is for server functions to only be valid at the top-level of a module, such that the code you provided doesn't compile successfully. That way it wouldn't be possible for the server function to close over |
Reproduction: https://stackblitz.com/edit/github-hvdm3o?file=app%2Fserver-functions.ts
The reproduction is a fork of examples/vanilla/spa.
Error:
The function
world
shown below is the server function. TheupdatedSchema
variable declared insidevalidated
gets treeshaken away even though it is used inside of the "use server" closure.The
client.tsx
is modified as shown below:The text was updated successfully, but these errors were encountered: