Skip to content

Releases: rphlmr/react-router-hono-server

v2.3.0

20 Dec 08:21
2e45d45
Compare
Choose a tag to compare

What's Changed

Pre-rendering

You should be able to use pre-rendering with this package.

Tip

Check this example to see how to use it.

Important

You need to add the serverBuildFile option to your react-router.config.ts file.

The file path is fixed to assets/server-build.js.

Add the prerender option to your react-router.config.ts

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

export default {
  serverBuildFile: "assets/server-build.js", // 🚨 Dont forget this
  prerender: ["/"],
} satisfies Config;

Full Changelog: v2.2.1...v2.3.0

v2.2.1

09 Dec 20:52
7998b7d
Compare
Choose a tag to compare

What's Changed

  • fix: listeningListener not called by @rphlmr in #31

Full Changelog: v2.2.0...v2.2.1

v2.2.0

08 Dec 15:57
aeebbb7
Compare
Choose a tag to compare

What's Changed

  • Extended API to support WebSocket by @rphlmr in #24

You can now enable WebSocket with the useWebSocket option.

It works for node and bun. Cloudflare requires a custom implementation.

Take a look at all the examples.

import type { WSContext } from "hono/ws";
import { createHonoServer } from "react-router-hono-server/node";

// Store connected clients
const clients = new Set<WSContext>();

export default await createHonoServer({
  useWebSocket: true,
  // 👆 Unlock this 👇 from @hono/node-ws
  configure: (app, { upgradeWebSocket }) => {
    app.get(
      "/ws",
      upgradeWebSocket((c) => ({
        // https://hono.dev/helpers/websocket
        onOpen(_, ws) {
          console.log("New connection ⬆️");
          clients.add(ws);
        },
        onMessage(event, ws) {
          console.log("Context", c.req.header("Cookie"));
          console.log("Event", event);
          console.log(`Message from client: ${event.data}`);
          // Broadcast to all clients except sender
          clients.forEach((client) => {
            if (client.readyState === 1) {
              client.send(`${event.data}`);
            }
          });
        },
        onClose(_, ws) {
          console.log("Connection closed");
          clients.delete(ws);
        },
      }))
    );
  },
});

Full Changelog: v2.1.2...v2.2.0

v2.1.2

28 Nov 11:20
7f57050
Compare
Choose a tag to compare

What's Changed

Breaking change for Cloudflare

You need to install these packages too:

npm install -D miniflare wrangler

2.1.0

Bun

Tip

Check this example to see how to use it.

// vite.config.ts
import { reactRouter } from "@react-router/dev/vite";
import { reactRouterHonoServer } from "react-router-hono-server/dev"; // add this
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";

export default defineConfig({
  plugins: [
    reactRouterHonoServer({ runtime: "bun"} ), // add this
    reactRouter(),
    tsconfigPaths()
  ],
});

More doc about Bun

Cloudflare Workers

Tip

Check this example to see how to use it.

Important

You need to add the cloudflareDevProxy plugin to use the Cloudflare Workers runtime on dev.

// vite.config.ts
import { reactRouter } from "@react-router/dev/vite";
import { cloudflareDevProxy } from "@react-router/dev/vite/cloudflare"; // add this
import { reactRouterHonoServer } from "react-router-hono-server/dev"; // add this
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";

export default defineConfig({
  plugins: [
    cloudflareDevProxy(),
    reactRouterHonoServer({ runtime: "cloudflare"} ), // add this
    reactRouter(),
    tsconfigPaths()
  ],
});

More doc about Cloudflare

Full Changelog: v2.1.0...v2.1.2

v2.1.0

28 Nov 09:41
bba9ec9
Compare
Choose a tag to compare

What's Changed

Bun

Tip

Check this example to see how to use it.

// vite.config.ts
import { reactRouter } from "@react-router/dev/vite";
import { reactRouterHonoServer } from "react-router-hono-server/dev"; // add this
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";

export default defineConfig({
  plugins: [
    reactRouterHonoServer({ runtime: "bun"} ), // add this
    reactRouter(),
    tsconfigPaths()
  ],
});

More doc about Bun

Cloudflare Workers

Tip

Check this example to see how to use it.

Important

You need to add the cloudflareDevProxy plugin to use the Cloudflare Workers runtime on dev.

// vite.config.ts
import { reactRouter } from "@react-router/dev/vite";
import { cloudflareDevProxy } from "@react-router/dev/vite/cloudflare"; // add this
import { reactRouterHonoServer } from "react-router-hono-server/dev"; // add this
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";

export default defineConfig({
  plugins: [
    cloudflareDevProxy(),
    reactRouterHonoServer({ runtime: "cloudflare"} ), // add this
    reactRouter(),
    tsconfigPaths()
  ],
});

More doc about Cloudflare

Full Changelog: v2.0.0...v2.1.0

v2.0.0

25 Nov 18:45
7a78e9c
Compare
Choose a tag to compare

What's Changed

Important

This new version is only compatible with React Router v7

You can still use the v1 with @remix-run. Previous docs

Migration guide from v1 here

It's now a Vite Plugin 🥳

Install the following npm package.

npm install react-router-hono-server@latest

Easy mode

In your vite.config.ts, add the reactRouterHonoServer plugin.

import { reactRouter } from "@react-router/dev/vite";
import { reactRouterHonoServer } from "react-router-hono-server/dev"; // add this
import { defineConfig } from "vite";
import tsconfigPaths from "vite-tsconfig-paths";

export default defineConfig({
  plugins: [
    reactRouterHonoServer(), // add this
    reactRouter(),
    tsconfigPaths()
  ],
});

That's all!

How it works

This helper works differently depending on the environment.

In development, it uses @hono/vite-dev-server and loads your server and React Router app with import('virtual:react-router/server-build').
It can be configured in vite.config.ts.

When building for production, the Hono server is compiled as build/server/index.js and imports your React Router app from assets/server-build-[hash].js.

New Contributors

Full Changelog: v1.2.0...v2.0.0

v1.2.0

14 Nov 09:03
90c294e
Compare
Choose a tag to compare

What's Changed

  • 🐛 FIX: entry now inherits from appDirectory by @rphlmr in #16

Full Changelog: v1.1.0...v1.2.0

v1.1.0

09 Nov 14:44
9703d55
Compare
Choose a tag to compare

What's Changed

  • make serverBuildFile option less restrictive by @rphlmr in #15

Full Changelog: v1.0.0...v1.1.0

v1.0.0

05 Nov 15:40
0ee11d2
Compare
Choose a tag to compare

v1.0.0 🥳

What's Changed

  • 📦 NEW: You can now use a custom node server by @rphlmr in #14

Next

v2.0.0 is planned with React Router v7

Full Changelog: v0.5.0...v1.0.0

v0.5.0

04 Nov 18:04
32c7cc0
Compare
Choose a tag to compare

What's Changed

  • 🐛 FIX: The buildDirectory option was not affecting the client base directory by @rphlmr in #13

Full Changelog: v0.4.0...v0.5.0