Skip to content

[BUG] Fix SSR hydration errors #920

@jplhomer

Description

@jplhomer

Describe the bug
In the current release branch, pretty much every page has this issue:

Screen Shot 2022-03-15 at 2 15 46 PM

I've been able to eliminate this hydration error by wrapping any...

  1. server components
  2. ...that suspend
  3. ...which are passed as children to client components

... with a <Suspense> boundary.

This might be a bug in Hydrogen. This might be a bug in React.

However, I have confirmed with the React team that this behavior is not intended (e.g. you should be able to pass server components to client components as children which suspend without needing a boundary inside the bounds of the client component).

It is very difficult to tell, because we are many experimental releases behind, and a lot of work has gone into how Suspense & Hydration works.

I've attempted to fix this in #907 but I've failed, because something is messing with the E2E tests locally. This fix is not correct, either, because it suspends at the router level with a fallback of null. This causes the page to flash from rendered (SSR) to fallback (RSC) to rendered (RSC). This is not good.

One might impose a rule on Hydrogen developers that they should NOT use useShopQuery or anything that suspends at the top level page server component, but rather provide a Suspense boundary with a fallback which matches their page design and render another component in the same file that does suspend. However, this feels like a weird rule to impose if it's not an actual restriction and just a bug with our implementation.

To Reproduce

  • Visit a page in the main branch

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions