Only register exported functions as server references#39
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.
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.
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.
...or inline 'use server' directives
There was a problem hiding this comment.
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.
But why would you error in the else case?
There was a problem hiding this comment.
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
No description provided.