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(remix-server-runtime): fix false-positive resource route identification on doc requests #7155

Merged
merged 2 commits into from
Aug 14, 2023

Conversation

brophdawg11
Copy link
Contributor

This adds the corresponding logic from #6125 (closing #6106) for document requests. A resource route should be a route that exports no UI components, not just one that doesn't export a happy path UI component.

This way it's possible to do a self-contained splat route 404 page. Previously, the below would be interpreted as a resource route and just return the raw text as a response and ignore the ErrorBoundary.

// $.jsx
import { useRouteError } from "react-router-dom";

export async function loader({ request }) {
  throw new Response(`${new URL(request.url).pathname} not found`, {
    status: 404,
    statusText: "Not Found",
  });
}

export function ErrorBoundary() {
  let error = useRouteError();
  return (
    <>
      <h1>
        {error.status} {error.statusText}
      </h1>
      <p>{error.data}</p>
    </>
  );
}

@changeset-bot
Copy link

changeset-bot bot commented Aug 14, 2023

🦋 Changeset detected

Latest commit: 96245e1

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

This PR includes changesets to release 16 packages
Name Type
@remix-run/server-runtime Patch
@remix-run/cloudflare Patch
@remix-run/deno Patch
@remix-run/dev Patch
@remix-run/node Patch
@remix-run/react Patch
@remix-run/cloudflare-pages Patch
@remix-run/cloudflare-workers Patch
@remix-run/architect Patch
@remix-run/express Patch
@remix-run/serve Patch
@remix-run/testing Patch
create-remix Patch
remix Patch
@remix-run/css-bundle Patch
@remix-run/eslint-config 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

@ryanflorence
Copy link
Member

What if the loader doesn't throw though?

@ryanflorence ryanflorence merged commit c00cd0e into dev Aug 14, 2023
9 checks passed
@ryanflorence ryanflorence deleted the brophdawg11/resource-route-boundary-only branch August 14, 2023 18:05
@brophdawg11
Copy link
Contributor Author

If an ErrorBoundary is specified and a default export is not, then it defaults the route's happy path UI component to Outlet - just like <Route path="something"> would - https://github.com/remix-run/remix/blob/main/packages/remix-react/components.tsx#L132

@github-actions github-actions bot added the awaiting release This issue has been fixed and will be released soon label Aug 14, 2023
@MichaelDeBoey MichaelDeBoey changed the title Fix false-positive resource route identification on doc requests fix(remix-server-runtime): fix false-positive resource route identification on doc requests Aug 14, 2023
@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version v0.0.0-nightly-65fdbcd-20230815 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
Labels
awaiting release This issue has been fixed and will be released soon CLA Signed package:server-runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants