Return `ServerLoadEvent` from `getRequestEvent` when called from load function
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
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
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the getRequestEvent implementation and its type declarations, then trace how it is called from server load functions. Compare the available RequestEvent and ServerLoadEvent behavior, especially dependency tracking through event.url. Done means the chosen API and its TypeScript typing correctly expose the load event without breaking other callers.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, typescript
- Domain
- backend, web-dev
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100