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

Remove status setters, and use a new response.notFound() method. #1496

Closed
wants to merge 1 commit into from

Conversation

jplhomer
Copy link
Contributor

@jplhomer jplhomer commented Jun 8, 2022

Description

Fixes #1488

We originally replaced HydrogenResponse.writeHead() with set status(value() in #1433. However, we can't reliably override the status and statusText properties of the Response class we're extending, because the implementation on some hosting runtimes like Cloudflare explicitly forbids it.

This PR adds a new HydrogenResponse.notFound() method which developers can use to declare a 404 when inside an server component.

Additional context

I don't anticipate developers needing to set custom response codes inside server components, so I think the removal of a custom status setter is an acceptable tradeoff.

Note that it is still possible to return a completely custom Response from API functions, where a custom status can be provided in the initial options:

export async function api() {
  return new Response('foo', { status: 201 });
}

Before submitting the PR, please make sure you do the following:

  • Read the Contributing Guidelines
  • Provide a description in this PR that addresses what the PR is solving, or reference the issue that it solves (e.g. fixes #123)
  • Update docs in this repository according to your change
  • Run yarn changeset add if this PR cause a version bump based on Keep a Changelog and adheres to Semantic Versioning

@jplhomer jplhomer requested a review from a team June 8, 2022 20:46
@frandiox
Copy link
Contributor

Alternative to writable status in CFW here: Shopify/hydrogen#1504

@jplhomer
Copy link
Contributor Author

Gonna close in favor of that one!

@jplhomer jplhomer closed this Jun 13, 2022
@jplhomer jplhomer deleted the jl-no-response-status-setter branch June 13, 2022 15:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants