-
-
Notifications
You must be signed in to change notification settings - Fork 10.5k
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: update thrown/returned Response handling in staticHandler #9465
Conversation
🦋 Changeset detectedLatest commit: 3516c17 The changes in this PR will be included in the next version bump. This PR includes changesets to release 5 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 |
@@ -10237,6 +10237,20 @@ describe("a router", () => { | |||
}; | |||
} | |||
|
|||
it("should match routes automatically if no routeId is provided", async () => { |
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.
@jacob-ebey This oughta allow us to simplify the resource route usage in RRR
} catch (data) { | ||
expect(data.status).toBe(201); | ||
expect(await data.text()).toBe("Created!"); | ||
} |
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.
any non-redirect thrown response will throw from queryRoute
expect(data instanceof Response).toBe(true); | ||
expect(data.status).toBe(404); | ||
expect(data.statusText).toBe("Not Found"); | ||
expect(data.headers.get("X-Remix-Router-Error")).toBe("yes"); |
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.
Router-generated errors (404 and 405) will now contain a custom header we can leverage in remix as needed
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.
This should cover our use-case :)
* redirect response is returned or thrown from any action/loader. We | ||
* propagate that out and return the raw Response so the HTTP server can | ||
* return it directly. | ||
*/ |
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.
@jacob-ebey Let me know if this and the comment above queryRoute
clarify the behavior (and match what we discussed yesterday).
The one thing that's slightly different I think is that while in the remix use-case, callRouteAction
for example will never throw a user-thrown error - this remix-agnostic code will still intend to throw user-thrown things inside of queryRoute
. We just shouldn't hit that path in the Remix usage of remix-run/router
let location = createLocation("", createPath(url), null, "default"); | ||
let matches = matchRoutes(dataRoutes, location); | ||
|
||
if (!matches) { |
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.
Lift 404 handling up to query
/queryRoute
to avoid branching inside queryImpl
status: error.status, | ||
statusText: error.statusText, | ||
}); | ||
} |
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.
Not a possible path anymore now that we throw 404/405 Response
's directly
status: value.status, | ||
statusText: value.statusText, | ||
}); | ||
} |
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.
Not a possible path either since all isRouteRequest
's throw inside callLoaderOrAction
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.
needs a changeset
Updates to
createStaticHandler
to better normalize the return values ofquery
/queryRoute
for use in Remix