Closed sabercoy closed 1 week ago
Hmm... that error is probably because the action function is getting called outside of any router context. When you put action
inside a server function it isn't in the same environment that did the calling. It is now on the server. So useAction
or the form in the browser can't see it.
action
doesn't make sense inside 'use server'
. When you put 'use server'
at the top of the file that means everything it exports is a server function. action
belongs outside of the server function. It runs on the client to manage cache invalidation.
Hmm... that error is probably because the action function is getting called outside of any router context. When you put
action
inside a server function it isn't in the same environment that did the calling. It is now on the server. SouseAction
or the form in the browser can't see it.
action
doesn't make sense inside'use server'
. When you put'use server'
at the top of the file that means everything it exports is a server function.action
belongs outside of the server function. It runs on the client to manage cache invalidation.
okay, I think my understanding is that when 'use server' is inside the anonymous function (inside of action) it will make the anonymous function run on the server, not the action and when 'use server' is at the top, it makes the action run on the server which is not the correct place
Hmm, I guess I thought that the compiling/bundling would automatically see the action and know to make its inner function server-only. If my understanding is correct, we can close this issue and I thank you for the clarification!
Yeah.. both features are developed independently with server functions being the more primary one. So the compiler is aware of them, but has no idea what action
is which comes from the router.
Describe the bug
this results in![image](https://github.com/solidjs/solid-router/assets/22666749/7b301f6e-3f4f-4d74-bd5c-c2d8deec48b6)
but doing 'use server' inside the function
works fine
Your Example Website or App
https://stackblitz.com/~/github.com/sabercoy/solid-useserver-action
Steps to Reproduce the Bug or Issue
copy the code into latest solid start
Expected behavior
'use server' being used in either case behaves the same
Screenshots or Videos
No response
Platform
Additional context
No response