[Lint Rule] Warn on files that export server-actions mixed with non server-actions #3199
Tbhesswebber
started this conversation in
Ideas
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Basic Request
Add a rule that checks to see if a file exports a variable defined with
createServerFn
and, if so, warn on any exports that aren't defined withcreateServerFn
Why
This rule attempts to mitigate (some of?) the issues about server dependencies being loaded in the browser. I don't know all of the edge cases for when this bundle bleed-through happens vs not, but even just a primitive rule that doesn't address the edge cases would be pretty helpful.
Additional Context
I got lost for quite a while the other day digging into why my database driver was being loaded into the browser. I only noticed that that was happening at all because some of the Clerk components stopped rendering (silent failures are fun!) and I opened the console to see what was going on. After a ton of searching the internet (especially looking at GitHub issues), I performed a git bisect to identify when the issue was created and finally identified the culprit by reverting that commit and slowly checking out files from the commit to see when things start to break. With this rule, I would have saved ~6 hours.
Examples
Note: I don't know for certain that all of these are actually passes and failures. Once this bit me, I only write actions in a files named actions.ts with no other exports just in case.
No error - exporting only server functions is fine
Warn - mixing exports of server functions and with non-server functions can cause bugs
Warn - mixing exports of server functions and variables can cause bugs
No error(?) - server functions defined next to the components that use them are fine (I think?)
No error(?) - server functions defined next abstractions around them are fine (I think?)
Beta Was this translation helpful? Give feedback.
All reactions