-
Notifications
You must be signed in to change notification settings - Fork 375
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: middleware wrapper #1588
base: main
Are you sure you want to change the base?
fix: middleware wrapper #1588
Conversation
|
Run & review this pull request in StackBlitz Codeflow. commit: @solidjs/start
templates
|
I had a suspicion there was was some timing disconnect here but I hadn't gotten into it. Your explanation makes sense to me. Very much appreciate you looking into this. I guess with this we change it to how I'd expect it to work (and how it is documented). I'm just wondering if we should change |
+1 for making it as close to the Nitro/h3 design as possible. One additional thought that I wanna leave here is about h3 v2: the new way will be to return the value/Response/stream directly instead of using |
I don't have much of an opinion about returning a response. It's an additional option that h3 doesn't have. Maybe convenient to some and makes @katywings Unclear to me if this applies to event handler hooks in v2. They don't seem to have changed much and return value of |
PR Checklist
Please check if your PR fulfills the following requirements:
PR Type
What kind of change does this PR introduce?
What is the current behavior?
onRequest
Not awaiting sendWebResponse can cause
event.handled
to not be true by the time h3 checks it and the next hook/handler will potentially be called.https://github.com/unjs/h3/blob/6d1e48438bcbbecfaafa4b9fb800bfb1a03ee592/src/event/utils.ts#L76-L83
https://github.com/unjs/h3/blob/6d1e48438bcbbecfaafa4b9fb800bfb1a03ee592/src/utils/response.ts#L531
Reproduction:
Refresh enough times and you will get one of 3 results.
ERR_STREAM_WRITE_AFTER_END
onBeforeResponse
Calling sendWebResponse in here does not seem to be supported. There are no checks for
event.handled
by h3 unlike foronRequest
and the next hook will be called.https://github.com/unjs/h3/blob/6d1e48438bcbbecfaafa4b9fb800bfb1a03ee592/src/event/utils.ts#L84-L91
Reproduction:
Refresh enough times and you will get one of 3 results.
ERR_STREAM_WRITE_AFTER_END
What is the new behavior?
onRequest
Await sendWebResponse
onBeforeResponse
Assign return value to
response.body
instead of callingsendWebResponse
. With this the response value of handler or previous hook will be replaced.H3 will call sendWebResponse for Response objects.
https://github.com/unjs/h3/blob/6d1e48438bcbbecfaafa4b9fb800bfb1a03ee592/src/app.ts#L185
https://github.com/unjs/h3/blob/6d1e48438bcbbecfaafa4b9fb800bfb1a03ee592/src/app.ts#L277-L279
Other information
Related issues:
#1523
nksaraf/vinxi#292