Skip to content

Releases: rphlmr/react-router-hono-server

v2.9.0

19 Feb 18:04
9dfdc31
Compare
Choose a tag to compare

What's Changed

  • 🚨 breaking changes: support react-router 7.2.0 by @rphlmr in #84

Starting from this version, React Router 7.2.0 is required

Full Changelog: v2.8.5...v2.9.0

v2.8.5

09 Feb 15:21
31b2d49
Compare
Choose a tag to compare

What's Changed

Full Changelog: v2.8.4...v2.8.5

v2.8.4

06 Feb 17:32
25ba052
Compare
Choose a tag to compare

What's Changed

New Contributors

Full Changelog: v2.8.2...v2.8.3

v2.8.2

27 Jan 08:33
5064961
Compare
Choose a tag to compare

What's Changed

  • make getLoadContext Context generic by @rphlmr in #71

Full Changelog: v2.8.1...v2.8.2

v2.8.1

26 Jan 13:14
a61e01e
Compare
Choose a tag to compare

What's Changed

Full Changelog: v2.8.0...v2.8.1

v2.8.0

24 Jan 17:31
af96951
Compare
Choose a tag to compare

What's Changed

Full Changelog: v2.7.1...v2.8.0

v2.7.1

14 Jan 20:13
89bc37c
Compare
Choose a tag to compare

What's Changed

  • refactor: deprecate reactRouterRedirect in favor of redirect helper. … by @rphlmr in #62

Check: https://github.com/rphlmr/react-router-hono-server?tab=readme-ov-file#middleware

import { redirect } from "react-router-hono-server/http";

Full Changelog: v2.6.4...v2.7.0

v2.6.4

05 Jan 12:02
21a930c
Compare
Choose a tag to compare

What's Changed

Full Changelog: v2.5.0...v2.6.0

Fixes #49 #44 #47

  • Add Vite 6 as a peer dependency (keeping Vite 5 too).
  • Fix build loader for cloudflare
  • Fix missing AppLoadContext in dev (dev server issue)
  • Add support for React Router basename
  • Handle React Router app as a Hono sub app
  • [Cloudflare]: setting experimental_serve_directly in wrangler config will now use your Hono server to serve assets
  • Remove deprecated honoOptions in favor of app option (createHonoServer)
  • Temporary handle React Router issue (remix-run/react-router#12295)

Basename and Hono sub apps

Note

By default, the React Router app is mounted at / (default basename value).

You may not need to use this option. It's for advanced use cases.

Tip

Check this example to see how to use it.

You can use the basename option in your React Router config (react-router.config.ts) to mount your React Router app on a subpath.

It will automatically mount the app on the subpath.

// react-router.config.ts
import type { Config } from "@react-router/dev/config";

export default {
  basename: "/app", // Now the React Router app will be mounted on /app
} satisfies Config;

Then, you can use the app option in createHonoServer to pass your "root" Hono app. This will be used to mount the React Router app on the basename path.

import { Hono } from "hono";
import { createHonoServer } from "react-router-hono-server/node";
import { API_BASENAME, api } from "./api";
import { getLoadContext } from "./context";

// Create a root Hono app
const app = new Hono();

// Mount the API app at /api
app.route(API_BASENAME, api);

export default await createHonoServer({
  // Pass the root Hono app to the server.
  // It will be used to mount the React Router app on the `basename` defined in react-router.config.ts
  app,
  getLoadContext,
});

Note

You now have two entry points!

  • /api - for your API
  • /app - for your React Router app

Cloudflare custom assets serving

You can set Cloudflare experimental_serve_directly and delegate assets serving to Hono, like for Node and Bun.

Tip

Check this example to see how to use it.

[assets]
directory = "./build/client/"
binding = "ASSETS"
experimental_serve_directly = false

v2.5.0

03 Jan 17:12
170396d
Compare
Choose a tag to compare

New

new helper: reactRouterRedirect

Redirect to a new location in a way that React Router can handle (Single fetch protocol).

🚨 Redirecting from a middleware

Important

You have to use the reactRouterRedirect helper to redirect from a middleware.

It returns a single-fetch-like response.

If you use c.redirect, it will not work as expected and you will get a Unable to decode turbo-stream response error.

import { reactRouterRedirect } from "react-router-hono-server/http";

new createHonoServer option: beforeAll

You can use the beforeAll option to add middleware that runs before any built-in middleware, including assets serving.

You can use it to add protection middleware, for example.

Tip

When you check the path to protect, don't forget to use c.req.path.includes("") to handle .data requests (loader)!

import { reactRouterRedirect } from "react-router-hono-server/http";
import { createHonoServer } from "react-router-hono-server/node";

export default await createHonoServer({
  beforeAll(app) {
    app.use(async (c, next) => {
      if (c.req.path.includes("/protected") && !c.req.header("Authorization")) {
        return reactRouterRedirect("/login");
      }

      return next();
    });
  },
});

new createHonoServer option: overrideGlobalObjects

https://github.com/honojs/node-server?tab=readme-ov-file#overrideglobalobjects

It is now set to false by default to prevent some issues with 3rd party libs like remix-hook-form.

Enabling this makes request.clone() not an instanceof Request.

export default await createHonoServer({
  overrideGlobalObjects: true,
});

Fixes

What's Changed

New Contributors

Full Changelog: v2.4.0...v2.5.0

v2.4.0

29 Dec 12:37
6c5dcdc
Compare
Choose a tag to compare

What's Changed

Full Changelog: v2.3.0...v2.4.0