-
-
Notifications
You must be signed in to change notification settings - Fork 10.7k
fix(react-router/server-runtime): delay turbo-stream
serialization of .data
redirects
#14205
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(react-router/server-runtime): delay turbo-stream
serialization of .data
redirects
#14205
Conversation
🦋 Changeset detectedLatest commit: 71c1f8c The changes in this PR will be included in the next version bump. This PR includes changesets to release 11 packages
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 |
16f464f
to
71c1f8c
Compare
🤖 Hello there, We just published version Thanks! |
turbo-stream
serialization of .data
redirects
turbo-stream
serialization of .data
redirectsturbo-stream
serialization of .data
redirects
🤖 Hello there, We just published version Thanks! |
@brophdawg11, I think this change may have unintentionally had the opposite effect on our Playwright integration tests. We have route actions that throw redirects in specific cases. Until now, tests for those cases could just examine a response object's As of 7.8.2, it looks like those tests would instead "have to be aware of the implementation detail that is the turbo-stream encoding and the 202 response". I have no idea what to do with this finding, what do you think? Should I file a bug, a request for test tools, or something else entirely? |
@aaronadamsCA I think I would need to see an example. This shouldn't change anything about how redirects are returned on document or data requests:
What should change here is the point in time when redirects on Here's a quick example: https://stackblitz.com/edit/github-5cdfffvj?file=app%2Froutes%2Fredirect.tsx If you downgrade that to 7.8.1 you can see the old 202 behavior. |
Makes sense, @brophdawg11, and I see what's happening now. I think the only thing it revealed is that our testing approach was all wrong. Prior to 7.8.2 the 202 response had a test("redirects on POST request (old approach)", async ({ page }) => {
await page.goto("http://localhost:5173/");
const [request] = await Promise.all([
page.waitForRequest((request) => request.method() === "POST"),
page.getByRole("button").click(),
]);
const response = await request.response();
assert.ok(response != null);
const location = await response.headerValue("location");
expect(location).toStrictEqual(URL);
}); But examining a response like that is essentially examining a React Router internal. How you implement the redirect is none of our concern. What we probably should have done all along, and will do going forward, is to examine the actual redirect request: test("redirects on POST request (new approach)", async ({ page }) => {
await page.goto("http://localhost:5173/");
const [request] = await Promise.all([
page.waitForRequest((request) => request.resourceType() === "document"),
page.getByRole("button").click(),
]);
expect(request.url()).toStrictEqual(URL);
}); This works across versions, hydrated or not. |
ahh ok yeah that makes sense. Those 202 responses weren't supposed to have the Your new approach is the right way to validate - just check the result of the redirect in the browser 👍 |
This dedupes a good bit of code and keeps the middleware chain a bit more consistent between document/data requests since you can now inspect and "see" a redirect in both cases and you don't have to be aware of the implementation detail that is the turbo-stream encoding and the 202 response. We just wait until right before we send the response before we serialize it via turbo-stream.