Skip to content
This repository was archived by the owner on Oct 22, 2025. It is now read-only.

Commit 812453a

Browse files
committed
feat(next-js): add support for next.js (#1152)
Closes KIT-178, KIT-115 ### TL;DR Add Next.js framework support with a working example and update documentation links. ### What changed? - Added a new `@rivetkit/next-js` package with Next.js integration - Created a complete Next.js example application in `examples/next-js` - Updated the GitHub workflow to include templates from examples directory - Fixed the basePath handling in the core router to support custom API paths - Updated documentation links throughout the README to point to rivet.gg domain - Added a pkg.pr.new badge to the README for easy testing ### How to test? 1. Run the Next.js example: ```bash cd examples/next-js pnpm install pnpm dev ``` 2. Open http://localhost:3000 to see the counter example 3. Try incrementing the counter and changing the counter name 4. Verify the API routes work correctly at `/api/registry` ### Why make this change? Next.js is one of the most popular React frameworks, and this integration allows RivetKit to be easily used in Next.js applications. The example demonstrates how to set up actors, create API routes, and use the React hooks in a Next.js environment. This expands RivetKit's framework support and makes it more accessible to developers using Next.js.
1 parent e914115 commit 812453a

File tree

29 files changed

+1055
-31
lines changed

29 files changed

+1055
-31
lines changed

.github/workflows/pkg-pr-new.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,4 @@ jobs:
1010
- uses: actions/setup-node@v4
1111
- run: pnpm install
1212
- run: pnpm build
13-
- run: pnpm dlx pkg-pr-new publish 'packages/*' 'packages/**/platforms/*' 'packages/frameworks/*' 'packages/drivers/*' --packageManager pnpm
13+
- run: pnpm dlx pkg-pr-new publish 'packages/*' 'packages/**/platforms/*' 'packages/frameworks/*' 'packages/drivers/*' --packageManager pnpm --template './examples/*'

README.md

Lines changed: 31 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,15 @@ Generated from: github.com/rivet-gg/rivet/site/scripts/generateReadme.mjs
2828
</p>
2929
<p>
3030
<i>
31-
Supports <a href="https://rivetkit.org/actors/quickstart-backend">Node.js</a>, <a href="https://rivetkit.org/actors/quickstart-backend">Bun</a>, <a href="https://rivetkit.org/drivers/redis">Redis</a>, <a href="https://rivetkit.org/drivers/cloudflare-workers">Cloudflare</a>,<br/>
32-
<a href="https://rivetkit.org/clients/react">React</a>, <a href="https://rivetkit.org/clients/rust">Rust</a>, <a href="https://rivetkit.org/integrations/hono">Hono</a>, <a href="https://rivetkit.org/integrations/express">Express</a>, <a href="https://rivetkit.org/integrations/trpc">tRPC</a>, and <a href="https://rivetkit.org/integrations/better-auth">Better Auth</a>.
31+
Supports <a href="https://rivet.gg/docs/actors/quickstart/backend/">Node.js</a>, <a href="https://rivet.gg/docs/actors/quickstart/backend/">Bun</a>, <a href="https://rivet.gg/docs/drivers/redis/">Redis</a>, <a href="https://rivet.gg/docs/hosting-providers/cloudflare-workers/">Cloudflare</a>,<br/>
32+
<a href="https://rivet.gg/docs/clients/react/">React</a>, <a href="https://rivet.gg/docs/clients/rust/">Rust</a>, <a href="https://rivet.gg/docs/integrations/hono/">Hono</a>, <a href="https://rivet.gg/docs/integrations/express/">Express</a>, <a href="https://rivet.gg/docs/integrations/trpc/">tRPC</a>, and <a href="https://rivet.gg/docs/integrations/better-auth/">Better Auth</a>.
3333
</i>
3434
</p>
35+
<p>
36+
<a href="https://pkg.pr.new/~/rivet-gg/rivetkit">
37+
<img src="https://pkg.pr.new/badge/rivet-gg/rivetkit" alt="RivetKit on pkg.pr.new" />
38+
</a>
39+
</p>
3540
</div>
3641

3742
## Projects
@@ -87,11 +92,11 @@ export const registry = setup({
8792
});
8893
```
8994

90-
Read more about [state](https://www.rivet.gg/docs/actors/state/), [actions](https://www.rivet.gg/docs/actors/actions/), and [events](https://www.rivet.gg/docs/actors/events/).
95+
Read more about [state](https://rivet.gg/docs/actors/state/), [actions](https://rivet.gg/docs/actors/actions/), and [events](https://rivet.gg/docs/actors/events/).
9196

9297
**Step 2**: Setup server
9398

94-
_Alternatively, see the [React](https://www.rivet.gg/docs/actors/quickstart/react/) guide which does not require a server._
99+
_Alternatively, see the [React](https://rivet.gg/docs/actors/quickstart/react/) guide which does not require a server._
95100

96101
```typescript
97102
// server.ts
@@ -110,7 +115,7 @@ app.post("/increment/:name", async (c) => {
110115
// Get or create actor with key `name`
111116
const counter = client.counter.getOrCreate(name);
112117

113-
// Call an action
118+
// Call an action (with full type safety)
114119
const newCount = await counter.increment(1);
115120

116121
return c.json({ count: newCount });
@@ -128,7 +133,7 @@ npx tsx server.ts
128133
bun server.ts
129134
```
130135

131-
Read more about [clients](https://www.rivet.gg/docs/actors/clients/).
136+
Read more about [clients](https://rivet.gg/docs/actors/clients/).
132137

133138
You can connect to your server with:
134139

@@ -143,8 +148,8 @@ console.log("Count:", result.count); // 1
143148

144149
To scale Rivet in production, follow a guide to deploy to a hosting provider or integrate a driver:
145150

146-
- [Redis](https://www.rivet.gg/docs/drivers/redis/)
147-
- [Cloudflare Workers](https://www.rivet.gg/docs/hosting-providers/cloudflare-workers/)
151+
- [Redis](https://rivet.gg/docs/drivers/redis/)
152+
- [Cloudflare Workers](https://rivet.gg/docs/hosting-providers/cloudflare-workers/)
148153

149154
## Features
150155

@@ -171,63 +176,61 @@ RivetKit provides everything you need to build fast, scalable, and real-time app
171176

172177
## Runs Anywhere
173178

174-
Deploy RivetKit anywhere - from serverless platforms to your own infrastructure with RivetKit's flexible runtime options. Don't see the runtime you want? [Add your own](https://rivetkit.org/drivers/build).
179+
Deploy RivetKit anywhere - from serverless platforms to your own infrastructure with RivetKit's flexible runtime options. Don't see the runtime you want? [Add your own](https://rivet.gg/docs/drivers/build-your-own/).
175180

176181
### All-In-One
177-
- <img src=".github/media/platforms/rivet-white.svg" height="16" alt="Rivet" />&nbsp;&nbsp;[Rivet](https://rivetkit.org/drivers/rivet)
178-
- <img src=".github/media/platforms/cloudflare-workers.svg" height="16" alt="Cloudflare Workers" />&nbsp;&nbsp;[Cloudflare Workers](https://rivetkit.org/drivers/cloudflare-workers)
182+
- <img src=".github/media/platforms/rivet-white.svg" height="16" alt="Rivet" />&nbsp;&nbsp;[Rivet](https://rivet.gg/docs/hosting-providers/rivet-cloud/)
183+
- <img src=".github/media/platforms/cloudflare-workers.svg" height="16" alt="Cloudflare Workers" />&nbsp;&nbsp;[Cloudflare Workers](https://rivet.gg/docs/hosting-providers/cloudflare-workers/)
179184

180185
### Compute
181186
- <img src=".github/media/platforms/vercel.svg" height="16" alt="Vercel" />&nbsp;&nbsp;[Vercel](https://github.com/rivet-gg/rivetkit/issues/897) *(On The Roadmap)*
182187
- <img src=".github/media/platforms/aws-lambda.svg" height="16" alt="AWS Lambda" />&nbsp;&nbsp;[AWS Lambda](https://github.com/rivet-gg/rivetkit/issues/898) *(On The Roadmap)*
183188
- <img src=".github/media/platforms/supabase.svg" height="16" alt="Supabase" />&nbsp;&nbsp;[Supabase](https://github.com/rivet-gg/rivetkit/issues/905) *(Help Wanted)*
184-
- <img src=".github/media/platforms/bun.svg" height="16" alt="Bun" />&nbsp;&nbsp;[Bun](https://rivetkit.org/actors/quickstart-backend)
185-
- <img src=".github/media/platforms/nodejs.svg" height="16" alt="Node.js" />&nbsp;&nbsp;[Node.js](https://rivetkit.org/actors/quickstart-backend)
189+
- <img src=".github/media/platforms/bun.svg" height="16" alt="Bun" />&nbsp;&nbsp;[Bun](https://rivet.gg/docs/actors/quickstart/backend/)
190+
- <img src=".github/media/platforms/nodejs.svg" height="16" alt="Node.js" />&nbsp;&nbsp;[Node.js](https://rivet.gg/docs/actors/quickstart/backend/)
186191

187192
### Storage
188-
- <img src=".github/media/platforms/redis.svg" height="16" alt="Redis" />&nbsp;&nbsp;[Redis](https://rivetkit.org/drivers/redis)
193+
- <img src=".github/media/platforms/redis.svg" height="16" alt="Redis" />&nbsp;&nbsp;[Redis](https://rivet.gg/docs/drivers/redis/)
189194
- <img src=".github/media/platforms/postgres.svg" height="16" alt="Postgres" />&nbsp;&nbsp;[Postgres](https://github.com/rivet-gg/rivetkit/issues/899) *(Help Wanted)*
190-
- <img src=".github/media/platforms/file-system.svg" height="16" alt="File System" />&nbsp;&nbsp;[File System](https://rivetkit.org/drivers/file-system)
191-
- <img src=".github/media/platforms/memory.svg" height="16" alt="Memory" />&nbsp;&nbsp;[Memory](https://rivetkit.org/drivers/memory)
195+
- <img src=".github/media/platforms/file-system.svg" height="16" alt="File System" />&nbsp;&nbsp;[File System](https://rivet.gg/docs/drivers/file-system/)
196+
- <img src=".github/media/platforms/memory.svg" height="16" alt="Memory" />&nbsp;&nbsp;[Memory](https://rivet.gg/docs/drivers/memory/)
192197

193198
## Works With Your Tools
194199

195200
Seamlessly integrate RivetKit with your favorite frameworks, languages, and tools. Don't see what you need? [Request an integration](https://github.com/rivet-gg/rivetkit/issues/new).
196201

197202
### Frameworks
198-
- <img src=".github/media/clients/react.svg" height="16" alt="React" />&nbsp;&nbsp;[React](https://rivetkit.org/clients/react)
199-
- <img src=".github/media/clients/nextjs.svg" height="16" alt="Next.js" />&nbsp;&nbsp;[Next.js](https://github.com/rivet-gg/rivetkit/issues/904) *(Help Wanted)*
203+
- <img src=".github/media/clients/react.svg" height="16" alt="React" />&nbsp;&nbsp;[React](https://rivet.gg/docs/clients/react/)
204+
- <img src=".github/media/clients/nextjs.svg" height="16" alt="Next.js" />&nbsp;&nbsp;[Next.js](https://rivet.gg/docs/clients/nextjs/)
200205
- <img src=".github/media/clients/vue.svg" height="16" alt="Vue" />&nbsp;&nbsp;[Vue](https://github.com/rivet-gg/rivetkit/issues/903) *(Help Wanted)*
201206

202207
### Clients
203-
- <img src=".github/media/clients/javascript.svg" height="16" alt="JavaScript" />&nbsp;&nbsp;[JavaScript](https://rivetkit.org/clients/javascript)
204-
- <img src=".github/media/clients/typescript.svg" height="16" alt="TypeScript" />&nbsp;&nbsp;[TypeScript](https://rivetkit.org/clients/javascript)
208+
- <img src=".github/media/clients/javascript.svg" height="16" alt="JavaScript" />&nbsp;&nbsp;[JavaScript](https://rivet.gg/docs/clients/javascript/)
209+
- <img src=".github/media/clients/typescript.svg" height="16" alt="TypeScript" />&nbsp;&nbsp;[TypeScript](https://rivet.gg/docs/clients/javascript/)
205210
- <img src=".github/media/clients/python.svg" height="16" alt="Python" />&nbsp;&nbsp;[Python](https://github.com/rivet-gg/rivetkit/issues/902) *(Help Wanted)*
206-
- <img src=".github/media/clients/rust.svg" height="16" alt="Rust" />&nbsp;&nbsp;[Rust](https://github.com/rivet-gg/rivetkit/issues/901) *(Help Wanted)*
211+
- <img src=".github/media/clients/rust.svg" height="16" alt="Rust" />&nbsp;&nbsp;[Rust](https://rivet.gg/docs/clients/rust/)
207212

208213
### Integrations
209-
- <img src=".github/media/integrations/hono.svg" height="16" alt="Hono" />&nbsp;&nbsp;[Hono](https://rivetkit.org/integrations/hono)
210-
- <img src=".github/media/integrations/vitest.svg" height="16" alt="Vitest" />&nbsp;&nbsp;[Vitest](https://rivetkit.org/general/testing)
211-
- <img src=".github/media/integrations/better-auth.svg" height="16" alt="Better Auth" />&nbsp;&nbsp;[Better Auth](https://rivetkit.org/integrations/better-auth)
214+
- <img src=".github/media/integrations/hono.svg" height="16" alt="Hono" />&nbsp;&nbsp;[Hono](https://rivet.gg/docs/integrations/hono/)
215+
- <img src=".github/media/integrations/vitest.svg" height="16" alt="Vitest" />&nbsp;&nbsp;[Vitest](https://rivet.gg/docs/integrations/vitest/)
216+
- <img src=".github/media/integrations/better-auth.svg" height="16" alt="Better Auth" />&nbsp;&nbsp;[Better Auth](https://rivet.gg/docs/integrations/better-auth/)
212217
- <img src=".github/media/platforms/vercel.svg" height="16" alt="AI SDK" />&nbsp;&nbsp;[AI SDK](https://github.com/rivet-gg/rivetkit/issues/907) *(On The Roadmap)*
213218

214219
### Local-First Sync
215-
- <img src=".github/media/integrations/livestore.svg" height="16" alt="LiveStore" />&nbsp;&nbsp;[LiveStore](https://github.com/rivet-gg/rivetkit/issues/908) *(Available In July)*
220+
- <img src=".github/media/integrations/livestore.svg" height="16" alt="LiveStore" />&nbsp;&nbsp;[LiveStore](https://github.com/rivet-gg/rivetkit/issues/908) *(Available In August)*
216221
- <img src=".github/media/integrations/zerosync.svg" height="16" alt="ZeroSync" />&nbsp;&nbsp;[ZeroSync](https://github.com/rivet-gg/rivetkit/issues/909) *(Help Wanted)*
217222
- <img src=".github/media/integrations/tinybase.svg" height="16" alt="TinyBase" />&nbsp;&nbsp;[TinyBase](https://github.com/rivet-gg/rivetkit/issues/910) *(Help Wanted)*
218223
- <img src=".github/media/integrations/yjs.svg" height="16" alt="Yjs" />&nbsp;&nbsp;[Yjs](https://github.com/rivet-gg/rivetkit/issues/911) *(Help Wanted)*
219224

220225
## Local Development with the Studio
221226

222-
Rivet Studio is like like Postman, but for all of your stateful serverless needs:
227+
Rivet Studio is like like Postman, but for all of your stateful serverless needs. [Visit the Studio →](https://studio.rivet.gg)
223228

224229
- **Live State Inspection**: View and edit your actor state in real-time as messages are sent and processed
225230
- **REPL**: Debug your actor in real-time - call actions, subscribe to events, and interact directly with your code
226231
- **Connection Inspection**: Monitor active connections with state and parameters for each client
227232
- **Hot Reload Code Changes**: See code changes instantly without restarting - modify and test on the fly
228233

229-
[Visit the Studio →](https://studio.rivet.gg)
230-
231234
![Rivet Studio](.github/media/screenshots/studio/simple.png)
232235

233236
## Community & Support

examples/next-js/.gitignore

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.
2+
3+
# dependencies
4+
/node_modules
5+
/.pnp
6+
.pnp.*
7+
.yarn/*
8+
!.yarn/patches
9+
!.yarn/plugins
10+
!.yarn/releases
11+
!.yarn/versions
12+
13+
# testing
14+
/coverage
15+
16+
# next.js
17+
/.next/
18+
/out/
19+
20+
# production
21+
/build
22+
23+
# misc
24+
.DS_Store
25+
*.pem
26+
27+
# debug
28+
npm-debug.log*
29+
yarn-debug.log*
30+
yarn-error.log*
31+
.pnpm-debug.log*
32+
33+
# env files (can opt-in for committing if needed)
34+
.env*
35+
36+
# vercel
37+
.vercel
38+
39+
# typescript
40+
*.tsbuildinfo
41+
next-env.d.ts

examples/next-js/README.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
This is a [Next.js](https://nextjs.org) project bootstrapped with [`create-next-app`](https://nextjs.org/docs/app/api-reference/cli/create-next-app).
2+
3+
## Getting Started
4+
5+
First, run the development server:
6+
7+
```bash
8+
npm run dev
9+
# or
10+
yarn dev
11+
# or
12+
pnpm dev
13+
# or
14+
bun dev
15+
```
16+
17+
Open [http://localhost:3000](http://localhost:3000) with your browser to see the result.
18+
19+
You can start editing the page by modifying `app/page.tsx`. The page auto-updates as you edit the file.
20+
21+
This project uses [`next/font`](https://nextjs.org/docs/app/building-your-application/optimizing/fonts) to automatically optimize and load [Geist](https://vercel.com/font), a new font family for Vercel.
22+
23+
## Learn More
24+
25+
To learn more about Next.js, take a look at the following resources:
26+
27+
- [Next.js Documentation](https://nextjs.org/docs) - learn about Next.js features and API.
28+
- [Learn Next.js](https://nextjs.org/learn) - an interactive Next.js tutorial.
29+
30+
You can check out [the Next.js GitHub repository](https://github.com/vercel/next.js) - your feedback and contributions are welcome!
31+
32+
## Deploy on Vercel
33+
34+
The easiest way to deploy your Next.js app is to use the [Vercel Platform](https://vercel.com/new?utm_medium=default-template&filter=next.js&utm_source=create-next-app&utm_campaign=create-next-app-readme) from the creators of Next.js.
35+
36+
Check out our [Next.js deployment documentation](https://nextjs.org/docs/app/building-your-application/deploying) for more details.

examples/next-js/next.config.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import type { NextConfig } from "next";
2+
3+
const nextConfig: NextConfig = {
4+
/* config options here */
5+
};
6+
7+
export default nextConfig;

examples/next-js/package.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"name": "example-next-js",
3+
"version": "0.1.0",
4+
"private": true,
5+
"scripts": {
6+
"dev": "next dev",
7+
"start": "next start",
8+
"lint": "next lint"
9+
},
10+
"dependencies": {
11+
"react": "19.1.0",
12+
"react-dom": "19.1.0",
13+
"next": "15.4.5",
14+
"@rivetkit/next-js": "workspace:*",
15+
"@rivetkit/actor": "workspace:*"
16+
},
17+
"devDependencies": {
18+
"typescript": "^5",
19+
"@types/node": "^20",
20+
"@types/react": "^19",
21+
"@types/react-dom": "^19"
22+
}
23+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import { toNextHandler } from "@rivetkit/next-js";
2+
import { registry } from "@/rivet/registry";
3+
4+
const server = registry.createServer({
5+
// This is important for Next.js to route the API calls correctly
6+
// It should match the path in your Next.js API route
7+
// For example, if your API route is at /api/registry/[...all], this should be "/api/registry"
8+
basePath: "/api/registry",
9+
studio: {
10+
// Tell RivetKit Studio where to find RivetKit Registry
11+
defaultEndpoint: "http://localhost:3000/api/registry",
12+
},
13+
});
14+
15+
export const { GET, POST, HEAD, PATCH, OPTIONS } = toNextHandler(server);
25.3 KB
Binary file not shown.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
:root {
2+
--background: #ffffff;
3+
--foreground: #171717;
4+
}
5+
6+
@media (prefers-color-scheme: dark) {
7+
:root {
8+
--background: #0a0a0a;
9+
--foreground: #ededed;
10+
}
11+
}
12+
13+
html,
14+
body {
15+
max-width: 100vw;
16+
overflow-x: hidden;
17+
}
18+
19+
body {
20+
color: var(--foreground);
21+
background: var(--background);
22+
font-family: Arial, Helvetica, sans-serif;
23+
-webkit-font-smoothing: antialiased;
24+
-moz-osx-font-smoothing: grayscale;
25+
}
26+
27+
* {
28+
box-sizing: border-box;
29+
padding: 0;
30+
margin: 0;
31+
}
32+
33+
a {
34+
color: inherit;
35+
text-decoration: none;
36+
}
37+
38+
@media (prefers-color-scheme: dark) {
39+
html {
40+
color-scheme: dark;
41+
}
42+
}
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
import type { Metadata } from "next";
2+
import { Geist, Geist_Mono } from "next/font/google";
3+
import "./globals.css";
4+
5+
const geistSans = Geist({
6+
variable: "--font-geist-sans",
7+
subsets: ["latin"],
8+
});
9+
10+
const geistMono = Geist_Mono({
11+
variable: "--font-geist-mono",
12+
subsets: ["latin"],
13+
});
14+
15+
export const metadata: Metadata = {
16+
title: "Create Next App",
17+
description: "Generated by create next app",
18+
};
19+
20+
export default function RootLayout({
21+
children,
22+
}: Readonly<{
23+
children: React.ReactNode;
24+
}>) {
25+
return (
26+
<html lang="en">
27+
<body className={`${geistSans.variable} ${geistMono.variable}`}>
28+
{children}
29+
</body>
30+
</html>
31+
);
32+
}

0 commit comments

Comments
 (0)