-
Notifications
You must be signed in to change notification settings - Fork 18
Only register exported functions as server references #39
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
Conversation
|
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
f166389 to
76cd4a6
Compare
|
|
||
| if ( | ||
| t.isIdentifier(id) && | ||
| (t.isArrowFunctionExpression(init) || t.isFunctionExpression(init)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will this catch
'use server'
async function foo() { ... };
export const bar = foo;?
FWIW i think next just does
if (typeof NAME === 'function') {
registerServerReference(NAME, 'NAME' ...);
} else {
errorBadExport('NAME');
}for all exports because it's hard to analyze this statically
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No, this does not cover all possible scenarios. It's pretty opinionated regarding what code style it supports, e.g. I also don't want to support default exports.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
...or inline 'use server' directives
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (typeof NAME === 'function') {
registerServerReference(NAME, 'NAME' ...);
} else {
errorBadExport('NAME');
}Hmm, I am considering this now...
Thanks for bringing this to my attention.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
But why would you error in the else case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
i think it's because the expectation is that a "use server" module exports server references, and importing other things from it might act weird, because they won't get tranformed. like export const foo = 1 would work, but arbitrary non-function exports might not -- what if someone does export const dbClient = myDb.connect()? so easier to just blanket-ban than let the user run into puzzling errors i think
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, makes sense.
No description provided.