Skip to content

Conversation

@huseeiin
Copy link
Contributor

i deleted some stuff like deprecation warnings please tell me if they should stay
currently in v2 when you do:

import { createMiddleware } from "@solidjs/start/middleware";

export default createMiddleware({
    onBeforeResponse: (e, response) => {
        console.log(response);
    },
});

response.body is undefined
that is fixed
also, there's a new breaking change (relative to start v1): response is now Response instead of { body: ReadableStream | string } (ReadableStream if mode is "stream", string otherwise)

@changeset-bot
Copy link

changeset-bot bot commented Jan 12, 2026

🦋 Changeset detected

Latest 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

@netlify
Copy link

netlify bot commented Jan 12, 2026

Deploy Preview for solid-start-landing-page ready!

Name Link
🔨 Latest commit d815753
🔍 Latest deploy log https://app.netlify.com/projects/solid-start-landing-page/deploys/69651ddf2bad1b00089eb5de
😎 Deploy Preview https://deploy-preview-2047--solid-start-landing-page.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 12, 2026

Open in StackBlitz

npm i https://pkg.pr.new/solidjs/solid-start/@solidjs/start@2047
npm i https://pkg.pr.new/solidjs/solid-start/@solidjs/vite-plugin-nitro-2@2047

commit: d815753

@katywings
Copy link
Contributor

katywings commented Jan 12, 2026

Imho the deprecation warnings should stay 🤔. Afaik the end goal is that users ideally will just use h3 middleware and we only keep createMiddleware for backwards compatibility.

const mwResponse = await onBeforeResponse(fetchEvent, {
body: (resp as any)?.body,
});
const mwResponse = await onBeforeResponse(fetchEvent, response.clone());
Copy link
Contributor

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? 🤔

Copy link
Contributor Author

@huseeiin huseeiin Jan 12, 2026

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

Copy link
Member

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

@huseeiin
Copy link
Contributor Author

Imho the deprecation warnings should stay 🤔. Afaik the end goal is that users ideally will just use h3 middleware and we only keep createMiddleware for backwards compatibility.

but how do they use h3 middleware?

@huseeiin
Copy link
Contributor Author

huseeiin commented Jan 12, 2026

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.
to avoid that, you can use h3's waitUntil but by then you've left the request and can't respond with your modified response.

export default createMiddleware({
    onBeforeResponse: (e, r) => {
        e.nativeEvent.waitUntil((async () => {
            console.log(await r.text());
        })());
    },
});

@huseeiin huseeiin marked this pull request as draft January 12, 2026 20:11
@huseeiin
Copy link
Contributor Author

it seems this crashes with ERROR Worker error: Invalid state: ReadableStream is locked when i refresh many times. converting to draft

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants