Skip to content

React Developer Tools doesn't work on first render #25

@ruigouveiamaciel

Description

@ruigouveiamaciel

Issue description

Whenever you try to render a page for the first time (in development mode), the React Developer Tools will timeout and error.

Screenshot from 2023-10-03 11-16-24

Other behaviors

  1. Some components, for some odd reason, never timeout and actually work, such as the Logo component. However, in the /examples/ssr-spa, the Link component seems to always timeout of the first render.

  2. Sometimes React Developer Tools will straight up just refuse to even load the DOM

    image

  3. Because this example is using client routing, whenever you switch to another page and then page to the same page React Developer Tools will not timeout anymore and work as expected.

    Screencast.from.03-10-2023.11.38.08.webm

Fix suggestion

I believe the root of the issue is because the first render is handled by onRenderHtml, which handles the creation of the page. The client, on the first render, only hydrates the page and therefore is lacking some information required by React Developer Tools.

After the first render, client routing takes control and therefore there's no longer the issue of the client missing any information required by the React Developer Tools.

I found out that by adding '$$typeof' to passToClient fixes this issue.

// /vike-react/renderer/+config.ts

export default {
  // ...
  passToClient: ['pageProps', 'title', '$$typeof']
  // ...
} satisfies Config

I was going to make a pull request for this, however this seems like a very small change and I don't know if it's the best approach to fixing it.

It would also be useful to extend the documentation with this information for people that are trying to build their own renderers/frameworks.

If you're happy with my proposed fix, I could go ahead and create a pull request for both the issue and the documentation. However I don't know what's the most appropriate place to document this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug 💥Something isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions