kit
kit copied to clipboard
Return `ServerLoadEvent` from `getRequestEvent` when called from load function
Describe the problem
getRequestEvent is great! It simplified my trpc package greatly by allowing library functions to access event.locals without passing it in all the time. However, because it returns the raw RequestEvent rather than the augmented ServerLoadEvent that includes dependency tracking on event.url, I was unable to fully replace the pattern of passing event into library functions.
This was a nightmare to track down because RequestEvent is so similar to ServerLoadEvent that it was hard to tell the difference.
Describe the proposed solution
Either:
- When called from within a server load function,
getRequestEventshould return the augmentedServerLoadEvent(would cause typescript issues, however) - or, a 2nd function called
getLoadEventthat only works within server load functions (confusing to users)
Typescript could be something like
function getRequestEvent(): RequestEvent | ServerLoadEvent;
which forces the user to check something like 'depends' in event, but is strictly correct
Importance
would make my life easier
This would be incredibly useful for things like clients that can be used in universal load functions. I am trying to use a TRPC client in the universal load function, in which case it needs to do some cookie magic if executed on the server. But it is very hard to do this with passed events. And if I forget to pass the event to the client in any load function everything breaks. Please implement this!!!
I also used getRequestEvent to avoid needing to pass the event down a long chain of function calls.
My app has a page with paginated data whose page is controlled by some query parameters. When using getRequestEvent the dependency tracking does not work correctly and thus clicks on links to switch the page are not (pre)loading.
Just happened to have the same issue. Any updates ? 👀