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

initial work on clientLoader & clientAction #5543

Closed
wants to merge 2 commits into from
Closed

Conversation

jacob-ebey
Copy link
Member

@jacob-ebey jacob-ebey commented Feb 23, 2023

Closes: #5070

  • Docs
  • Tests

Testing Strategy:

  • new integration tests

@changeset-bot
Copy link

changeset-bot bot commented Feb 23, 2023

⚠️ No Changeset found

Latest commit: ba3a350

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

Copy link
Contributor

@brophdawg11 brophdawg11 left a comment

Choose a reason for hiding this comment

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

So pumped for this 🤩

@@ -29,7 +29,8 @@ export function isErrorResponse(response: any): boolean {
export function isRedirectResponse(response: any): boolean {
return (
response instanceof Response &&
response.headers.get("X-Remix-Redirect") != null
(response.headers.get("X-Remix-Redirect") != null ||
(response.status >= 300 && response.status < 400))
Copy link
Contributor

Choose a reason for hiding this comment

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

We can steal this util from RR (or even export it as UNSAFE_ and use it directly:

const redirectStatusCodes = new Set([301, 302, 303, 307, 308]);

export function isRedirectStatusCode(statusCode: number): boolean {
  return redirectStatusCodes.has(statusCode);
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Is the reason we need this because clientLoader doesn't run through the internal checking? Maybe we can get rid of the need for this an put less in the doFetch...

Copy link
Member Author

Choose a reason for hiding this comment

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

The reason we need this is because Remix is expecting a 204 response to represent redirects and we don't currently handle real redirect responses.

export interface ClientDataFunctionArgs {
request: Request;
params: Params;
next: () => Promise<Response | DeferredData | null>;
Copy link
Contributor

Choose a reason for hiding this comment

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

We can bikeshed this as we go - I like serverFetch at the moment

Comment on lines +182 to +193
let doFetch = async (request: Request) => {
if (isAction && !route.hasAction) {
let msg =
`Route "${route.id}" does not have an action, but you are trying ` +
`to submit to it. To fix this, please add an \`action\` function to the route`;
console.error(msg);
throw new Error(msg);
} else if (!isAction && !route.hasLoader) {
return null;
}

let result = await fetchData(request, route.id);
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder if doFetch could stop here so we get all the same error/redirect/catch handling whether they hit the server or not?

packages/remix-react/routes.tsx Outdated Show resolved Hide resolved
@github-actions github-actions bot added the needs-response We need a response from the original author about this issue/PR label Apr 28, 2023
@remix-run remix-run deleted a comment from github-actions bot Apr 30, 2023
@machour machour removed the needs-response We need a response from the original author about this issue/PR label Apr 30, 2023
@brophdawg11
Copy link
Contributor

I'm gonna close this out for now - we can re-open if needed once we start on v3 features

@brophdawg11 brophdawg11 closed this Aug 2, 2023
@MichaelDeBoey MichaelDeBoey deleted the client-loader branch August 3, 2023 00:55
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.

3 participants