Solid-Start vinxi/http issue with useWebRequest
Hey, when using
getWebRequest from vinxi/http inside a Context I get the error,
Here's the exact code that errors, I know it's getWebRequest as the error goes away after this.
8 Replies
Put
use server inside the function
Also i'd recommend moving fetchUser outside of UserProviderInteresting, I figured "use server" applied to the thing below it, thanks.
Creates a new issue as it complains fetchUser now doesn't exist as it's only server-sided code but that makes sense, but I think I can just solve it by doing what you recommend by moving it outside the UserProvider component into the main app and just passing in my user via props instead to the context
Actually same issue persists, what's the correct way to handle this? I know it's from the use server part but how do I get the user using SSR along side a createResource, unless I should be using a different SSR fetching method?
ReferenceError: Cannot access 'fetchUser' before initialization
Move
fetchUser outside App
Server functions definitions get hoisted up to the top of the moduleThat did fix it, do functions not hoist to the top?
If it was hoisted wouldn't it be in context still then or no?
The
createServerReference that is codegened gets put to the top but the function implementation may not, which probably leads to that errorAh
I think there's been talk of requiring all
use server functions to be top level else just hard erroring to avoid situations like thisYeah it would avoid confusion in cases like this, but it makes sense now that you explained why.
Thanks for the help by the way, much appreciated