Skip to content

Conversation

brophdawg11
Copy link
Contributor

@brophdawg11 brophdawg11 commented Jul 30, 2025

This is a decent-sized internal refactor for middleware logic, aligning code for consistency across middleware and non-middleware flows as well as RSC and non-RSC flows.

We used to have an unstable_respond API on the static handler which was basically in charge of converting a StaticHandlerContext -> Response in the leaf next() so we could bubble a Response back up the middleware chain.

When RSC came around, we realized this was insufficient for server actions because we had no way to run middleware before the server action and then process the server action and the loaders for the revalidating RSC render as part of the leaf next(). To solve that we added an unstable_stream alternative alongside unstable_respond which allowed us to opt-0into this more advanced functionality in the RSC work without causing potential regressions in non-RSC middleware code flows using unstable_respond.

Now that RSC is out (unstable) and we're getting closer to stabilizing middleware, it's time to convert existing usages of unstable_respond over to the new API and get rid of it.

This PR also renames it to unstable_generateMiddlewareResponse for clarity and does a bunch of code cleanup for better sharing of code across middleware and non-middleware flows.

Copy link

changeset-bot bot commented Jul 30, 2025

🦋 Changeset detected

Latest commit: bc1f18b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 11 packages
Name Type
react-router Patch
@react-router/architect Patch
@react-router/cloudflare Patch
@react-router/dev Patch
react-router-dom Patch
@react-router/express Patch
@react-router/node Patch
@react-router/serve Patch
@react-router/fs-routes Patch
@react-router/remix-routes-option-adapter Patch
create-react-router Patch

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

@brophdawg11 brophdawg11 marked this pull request as ready for review July 30, 2025 19:59
@brophdawg11 brophdawg11 force-pushed the brophdawg11/adopt-middleware-stream-api branch from 48c8551 to 4931355 Compare July 30, 2025 20:16
@brophdawg11 brophdawg11 merged commit a6a8886 into dev Aug 1, 2025
8 checks passed
@brophdawg11 brophdawg11 deleted the brophdawg11/adopt-middleware-stream-api branch August 1, 2025 15:30
Copy link
Contributor

github-actions bot commented Aug 5, 2025

🤖 Hello there,

We just published version 7.8.0-pre.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Copy link
Contributor

github-actions bot commented Aug 7, 2025

🤖 Hello there,

We just published version 7.8.0 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

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

Successfully merging this pull request may close these issues.

1 participant