Skip to content
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

Merged
merged 8 commits into from
Oct 18, 2022

Conversation

brophdawg11
Copy link
Contributor

Updates to createStaticHandler to better normalize the return values of query/queryRoute for use in Remix

@changeset-bot
Copy link

changeset-bot bot commented Oct 14, 2022

🦋 Changeset detected

Latest commit: 3516c17

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

This PR includes changesets to release 5 packages
Name Type
@remix-run/router Patch
react-router Patch
react-router-dom Patch
react-router-dom-v5-compat Patch
react-router-native 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

@@ -10237,6 +10237,20 @@ describe("a router", () => {
};
}

it("should match routes automatically if no routeId is provided", async () => {
Copy link
Contributor Author

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!");
}
Copy link
Contributor Author

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");
Copy link
Contributor Author

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

Copy link
Member

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.
*/
Copy link
Contributor Author

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) {
Copy link
Contributor Author

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,
});
}
Copy link
Contributor Author

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,
});
}
Copy link
Contributor Author

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

Copy link
Member

@jacob-ebey jacob-ebey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

needs a changeset

@brophdawg11 brophdawg11 merged commit ec9bacf into dev Oct 18, 2022
@brophdawg11 brophdawg11 deleted the brophdawg11/static-handler-updates branch October 18, 2022 13:32
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.

2 participants