The requestEvent in the middleware is different from requestEvent from getRequestEvent in the same
request cycle
This is leading to some weird bugs
3 Replies
Can you elaborate?
The middleware's FetchEvent is a SolidStart type that is handed to you as a parameter; so inside middleware exclusively use that.
If you check in
node_modules/solid-js/web/dist/web.js
you will find that getRequestEvent
is just:
I'm guessing that getRequestEvent
is part of the request specific store
parameter of the asyncLocalStorage.run(store, callback[, ...args])
call during one of the various stages of request processing on the server, so it's availability is highly dependent on the processing context.
So it's not too surprising that the event is "different" as it moves through the various stages of request processing.
The question is what differences are tripping you up?GitHub
solid-start/packages/start/src/server/types.ts at 771aedebb55bf4347...
SolidStart, the Solid app framework. Contribute to solidjs/solid-start development by creating an account on GitHub.
This definitely helps. Thanks for the clarification.
Since middleware and where I am doing another function call for getRequestEvent are two hops apart, I opted to do
getRequestEvent
instead of passing it around.
Btw, I don't have a "use server" in the file where I am making getRequestEvent(). If I add that, will it behave the way I am expecting it to behave?No.
1. Given that you are using the function from middleware you must pass the FetchEvent;
fn(event: FetchEvent)
2. If you are reusing that very same function in a "use server"
code block then you can simply go fn(getRequestEvent())
(but not in middleware).