hydrogen icon indicating copy to clipboard operation
hydrogen copied to clipboard

[BUG] `404` status not working with dynamic routes

Open ramiroazar opened this issue 3 years ago • 3 comments

Describe the bug

Routes that don't exist and are matched by a catch all route render the NotFound component but return a 200 status.

This happens even if the response status is modified within the actual route component before even rendering the NotFound component.

The responses look identical when logged, but the actual status is different in the console and browser.

Static route that returns a 404 status:

HydrogenResponse [Response] {
  size: 0,
  timeout: 0,
  wait: false,
  sent: false,
  cacheOptions: { mode: 'public', maxAge: 1, staleWhileRevalidate: 9 },
  status: 404,
  statusText: 'Not found',
  url: 'http://localhost:3001/404',
  [Symbol(Body internals)]: { body: null, disturbed: false, error: null },
  [Symbol(Response internals)]: {
    url: undefined,
    status: 200,
    statusText: 'OK',
    headers: Headers { [Symbol(map)]: [Object: null prototype] },
    counter: undefined
  }
}

Dynamic route that returns a 200 status:

HydrogenResponse [Response] {
  size: 0,
  timeout: 0,
  wait: false,
  sent: true,
  cacheOptions: { mode: 'public', maxAge: 1, staleWhileRevalidate: 9 },
  status: 404,
  statusText: 'Not found',
  url: 'http://localhost:3001/collections/freestyle-404',
  [Symbol(Body internals)]: { body: null, disturbed: false, error: null },
  [Symbol(Response internals)]: {
    url: undefined,
    status: 200,
    statusText: 'OK',
    headers: Headers { [Symbol(map)]: [Object: null prototype] },
    counter: undefined
  }
}

To Reproduce

  1. Navigate to https://www.hydrogen.shop/404
  2. Notice 404 status
  3. Navigate to https://www.hydrogen.shop/collections/freestyle-404
  4. Notice 200 status

Expected behaviour

Dynamic routes that don't exist should return a 404 status.

Screenshots

Screenshot from 2022-10-27 17-00-38

Additional context Add any other context about the problem here. eg.

  • Hydrogen version 1.5.0 and 1.6.0
  • Node version 16.18.0
  • Device details Linux Manjaro Sikaris 22.0.0

ramiroazar avatar Oct 27 '22 07:10 ramiroazar

I can also confirm on y side that there is a hydration error. Is there a fix?

h36ahmed avatar Jun 26 '24 20:06 h36ahmed

The error may be more related to the Script tag. I tried using another third-party script, which still gave me hydration errors. I also believe that hydration errors start to appear when you do dangerouslySetInnerHTML. I loaded a script with only src and there were no issues.

h36ahmed avatar Jun 26 '24 21:06 h36ahmed