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

feat(react-renderer): Support renderToReadableStream options for hydration #410

Merged
merged 3 commits into from
Mar 6, 2024

Conversation

yoshikouki
Copy link
Contributor

@yoshikouki yoshikouki commented Mar 5, 2024

Features

  • Adds support for renderToReadableStream options in (react-renderer)
  • Enables more flexible and performance-optimized hydration strategies

Benefits

Examples of use

https://github.com/yoshikouki/hono-spa-react-bun/blob/46208aa2ffa6c9375ccea14e9d724496850e336c/src/index.tsx#L29-L37

// src/index.tsx

app.get(
  "*",
  reactRenderer(Layout, {
    stream: true,
    readableStreamOptions: {
      bootstrapScripts: ["/src/client.tsx"],
    },
  })
);

app.get("/", (c) => {
  return c.render(<App />);
});
// src/client.tsx
import { hydrateRoot } from "react-dom/client";
import { App, Layout } from "./app";

hydrateRoot(
  document,
  <Layout>
    <App />
  </Layout>
);

Ref:

https://react.dev/reference/react-dom/server/renderToReadableStream#rendering-a-react-tree-as-html-to-a-readable-web-stream

Copy link

changeset-bot bot commented Mar 5, 2024

🦋 Changeset detected

Latest commit: 4b66f92

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@hono/react-renderer Minor

Not sure what this means? Click here to learn what changesets are.

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

@yusukebe
Copy link
Member

yusukebe commented Mar 6, 2024

Hi @yoshikouki !

This is a good feature! I've left one comment. Thanks!

Copy link
Member

@yusukebe yusukebe left a comment

Choose a reason for hiding this comment

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

LGTM!

@yusukebe
Copy link
Member

yusukebe commented Mar 6, 2024

@yoshikouki

Thank you for your quick response. I'll merge this now!

@yusukebe yusukebe merged commit bda918e into honojs:main Mar 6, 2024
1 check passed
@yoshikouki
Copy link
Contributor Author

Thanks for your review!

@github-actions github-actions bot mentioned this pull request Mar 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants