-
Notifications
You must be signed in to change notification settings - Fork 405
refactor middleware #2047
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
base: main
Are you sure you want to change the base?
refactor middleware #2047
Conversation
🦋 Changeset detectedLatest commit: d815753 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
✅ Deploy Preview for solid-start-landing-page ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
commit: |
|
Imho the deprecation warnings should stay 🤔. Afaik the end goal is that users ideally will just use h3 middleware and we only keep |
| const mwResponse = await onBeforeResponse(fetchEvent, { | ||
| body: (resp as any)?.body, | ||
| }); | ||
| const mwResponse = await onBeforeResponse(fetchEvent, response.clone()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats the advantage of the response clone? Couldn't the enduser do it themselves? 🤔
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Whats the advantage of the response clone? Couldn't the enduser do it themselves? 🤔
they can do it themselves, but first they have to know why they should: they use response.text() then get shocked that it fails because the response body is already used by the framework
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cloning is fine, I also did it a lot of times in the seroval branch. It's a workaround for expected issues like what he mentioned
but how do they use h3 middleware? |
|
tip for users, when you do this: export default createMiddleware({
onBeforeResponse: async (e, r) => {
console.log(await r.text());
},
});and you're streaming, your stream will be deferred. export default createMiddleware({
onBeforeResponse: (e, r) => {
e.nativeEvent.waitUntil((async () => {
console.log(await r.text());
})());
},
}); |
|
it seems this crashes with |
i deleted some stuff like deprecation warnings please tell me if they should stay
currently in v2 when you do:
response.bodyis undefinedthat is fixed
also, there's a new breaking change (relative to start v1): response is now
Responseinstead of{ body: ReadableStream | string }(ReadableStreamifmodeis"stream",stringotherwise)