Skip to content

Commit 96c47cd

Browse files
MrLightfulHugoRCDautofix-ci[bot]
authored
feat: add react-router support (HugoRCD#212)
Co-authored-by: Hugo Richard <hugo.richard@vercel.com> Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent 31cb4ab commit 96c47cd

33 files changed

+1645
-61
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"evlog": minor
3+
---
4+
5+
Add React Router middleware integration (`evlog/react-router`) with automatic wide-event logging, drain, enrich, and tail sampling support

.github/pull_request_template.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ Here are the available types and scopes:
3434
- elysia (Elysia plugin)
3535
- fastify (Fastify plugin)
3636
- nestjs (NestJS middleware)
37+
- react-router (React Router integration)
3738
- sveltekit (SvelteKit integration)
3839
- workers (Cloudflare Workers adapter)
3940
- fs (File System adapter)

.github/workflows/semantic-pull-request.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ jobs:
3939
elysia
4040
fastify
4141
nestjs
42+
react-router
4243
sveltekit
4344
workers
4445
fs

apps/docs/app/components/features/FeatureFrameworks.vue

Lines changed: 17 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,16 @@ const frameworkRows = [
2323
{ name: 'SvelteKit', icon: 'i-simple-icons-svelte', tab: 2 },
2424
{ name: 'Nitro', icon: 'i-custom-nitro', tab: 3 },
2525
{ name: 'TanStack Start', icon: 'i-custom-tanstack', tab: 4 },
26-
{ name: 'NestJS', icon: 'i-simple-icons-nestjs', tab: 5 },
26+
{ name: 'React Router', icon: 'i-simple-icons-reactrouter', tab: 5 },
27+
{ name: 'NestJS', icon: 'i-simple-icons-nestjs', tab: 6 },
2728
],
2829
[
29-
{ name: 'Express', icon: 'i-simple-icons-express', tab: 6 },
30-
{ name: 'Hono', icon: 'i-simple-icons-hono', tab: 7 },
31-
{ name: 'Fastify', icon: 'i-simple-icons-fastify', tab: 8 },
32-
{ name: 'Elysia', icon: 'i-custom-elysia', tab: 9 },
33-
{ name: 'Cloudflare', icon: 'i-simple-icons-cloudflare', tab: 10 },
34-
{ name: 'Bun', icon: 'i-simple-icons-bun', tab: 11 },
30+
{ name: 'Express', icon: 'i-simple-icons-express', tab: 7 },
31+
{ name: 'Hono', icon: 'i-simple-icons-hono', tab: 8 },
32+
{ name: 'Fastify', icon: 'i-simple-icons-fastify', tab: 9 },
33+
{ name: 'Elysia', icon: 'i-custom-elysia', tab: 10 },
34+
{ name: 'Cloudflare', icon: 'i-simple-icons-cloudflare', tab: 11 },
35+
{ name: 'Bun', icon: 'i-simple-icons-bun', tab: 12 },
3536
{ name: 'Vite', icon: 'i-custom-vite', link: '/core-concepts/vite-plugin' },
3637
],
3738
]
@@ -129,24 +130,27 @@ const frameworkRows = [
129130
<slot name="tanstack-start" />
130131
</div>
131132
<div v-show="activeTab === 5" class="landing-code">
132-
<slot name="nestjs" />
133+
<slot name="react-router" />
133134
</div>
134135
<div v-show="activeTab === 6" class="landing-code">
135-
<slot name="express" />
136+
<slot name="nestjs" />
136137
</div>
137138
<div v-show="activeTab === 7" class="landing-code">
138-
<slot name="hono" />
139+
<slot name="express" />
139140
</div>
140141
<div v-show="activeTab === 8" class="landing-code">
141-
<slot name="fastify" />
142+
<slot name="hono" />
142143
</div>
143144
<div v-show="activeTab === 9" class="landing-code">
144-
<slot name="elysia" />
145+
<slot name="fastify" />
145146
</div>
146147
<div v-show="activeTab === 10" class="landing-code">
147-
<slot name="cloudflare" />
148+
<slot name="elysia" />
148149
</div>
149150
<div v-show="activeTab === 11" class="landing-code">
151+
<slot name="cloudflare" />
152+
</div>
153+
<div v-show="activeTab === 12" class="landing-code">
150154
<slot name="bun" />
151155
</div>
152156
</Motion>

apps/docs/content/0.landing.md

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -280,6 +280,34 @@ Wide events and structured errors for TypeScript. One log per request, full cont
280280
})
281281
```
282282

283+
#react-router
284+
```ts [app/routes/api.checkout.tsx]
285+
import { loggerContext } from 'evlog/react-router'
286+
import { createError } from 'evlog'
287+
288+
export async function action({ request, context }: Route.ActionArgs) {
289+
const log = context.get(loggerContext)
290+
const { cartId } = await request.json()
291+
292+
const cart = await db.findCart(cartId)
293+
log.set({ cart: { items: cart.items.length, total: cart.total } })
294+
295+
const charge = await stripe.charge(cart.total)
296+
log.set({ stripe: { chargeId: charge.id } })
297+
298+
if (!charge.success) {
299+
throw createError({
300+
status: 402,
301+
message: 'Payment failed',
302+
why: charge.decline_reason,
303+
fix: 'Try a different payment method',
304+
})
305+
}
306+
307+
return Response.json({ orderId: charge.id })
308+
}
309+
```
310+
283311
#nestjs
284312
```ts [app.module.ts]
285313
import { Module } from '@nestjs/common'

apps/docs/content/1.getting-started/2.installation.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,15 @@ After installing the package, follow the setup guide for your framework:
9393
:::
9494
:::card
9595
---
96+
icon: i-simple-icons-reactrouter
97+
title: React Router
98+
to: /frameworks/react-router
99+
color: neutral
100+
---
101+
Middleware with `context.get(loggerContext)`.
102+
:::
103+
:::card
104+
---
96105
icon: i-simple-icons-nestjs
97106
title: NestJS
98107
to: /frameworks/nestjs

apps/docs/content/2.frameworks/00.overview.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ evlog provides native integrations for every major TypeScript framework. The sam
1717
| [SvelteKit](/frameworks/sveltekit) | `evlog/sveltekit` | Hooks | `event.locals.log` / `useLogger()` | Stable |
1818
| [Nitro](/frameworks/nitro) | `evlog/nitro` | Module | `useLogger(event)` | Stable |
1919
| [TanStack Start](/frameworks/tanstack-start) | `evlog/nitro/v3` | Module | `useRequest().context.log` | Stable |
20+
| [React Router](/frameworks/react-router) | `evlog/react-router` | Middleware | `context.get(loggerContext)` / `useLogger()` | Stable |
2021
| [NestJS](/frameworks/nestjs) | `evlog/nestjs` | Module | `useLogger()` | Stable |
2122
| [Express](/frameworks/express) | `evlog/express` | Middleware | `req.log` / `useLogger()` | Stable |
2223
| [Hono](/frameworks/hono) | `evlog/hono` | Middleware | `c.get('log')` | Stable |
@@ -77,6 +78,15 @@ evlog provides native integrations for every major TypeScript framework. The sam
7778
:::
7879
:::card
7980
---
81+
icon: i-simple-icons-reactrouter
82+
title: React Router
83+
to: /frameworks/react-router
84+
color: neutral
85+
---
86+
Middleware with `context.get(loggerContext)` and `useLogger()` for loaders and services.
87+
:::
88+
:::card
89+
---
8090
icon: i-simple-icons-nestjs
8191
title: NestJS
8292
to: /frameworks/nestjs

0 commit comments

Comments
 (0)