Skip to content

Commit 30cf713

Browse files
gewenyu99claude
andcommitted
Reword serverless flush commandments and drop dashes
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 4b918d3 commit 30cf713

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

context/commandments.yaml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ commandments:
3434
# Server-side feature flags
3535
- Server Components and Route Handlers cannot use React hooks - use posthog-node SDK instead
3636
- Create a server-side PostHog client with posthog-node, call getAllFlags() or getFeatureFlag(), then await posthog.shutdown()
37-
- 'Route Handlers and Server Actions are short-lived per request — create the posthog-node client with flushAt 1 and flushInterval 0, and `await posthog.flush()` after capturing and before returning, or the function freezes before the event is sent and it is silently dropped'
37+
- 'Route Handlers and Server Actions are short-lived per request. Create the posthog-node client with flushAt 1 and flushInterval 0, and `await posthog.flush()` after capturing and before returning, or the function freezes before the event is sent and it is silently dropped'
3838
- Pass flag values from server to client components as props to avoid hydration mismatches
3939
# Avoiding flicker
4040
- For flags that affect initial render, evaluate server-side and pass as props to prevent UI flicker
@@ -57,8 +57,8 @@ commandments:
5757
- 'Include enableExceptionAutocapture: true in the PostHog constructor options'
5858
- Add posthog.capture() calls in route handlers for meaningful user actions – every route that creates, updates, or deletes data should track an event with contextual properties
5959
- Add posthog.captureException(err, distinctId) in the application's error handler (e.g., Express error middleware, Fastify setErrorHandler, Koa app.on('error'))
60-
- The SDK batches events and flushes asynchronously. Only rely on that default in a process you keep alive yourself — a standalone server you run, or a long-lived worker.
61-
- '`posthog.capture()` enqueues synchronously and returns; the batched HTTP send happens afterwards. Treat every per-request handler as short-lived even when the framework feels like a serverNext.js / Nuxt / SvelteKit / Remix route handlers, serverless and edge functions, and Lambda are torn down per invocation before the send runs. Create the client with flushAt 1 and flushInterval 0, then await the send before returning`await posthog.flush()` for a shared/singleton client, `await posthog.shutdown()` for a per-request client. Skip the awaited flush and the enqueued event is silently dropped.'
60+
- The SDK batches events and flushes asynchronously. await flush() or await shutdown() before letting that process exit. If unsure, set flushAt 1 and flushInterval 0.
61+
- '`posthog.capture()` enqueues synchronously and returns; the batched HTTP send happens afterwards. Treat every per-request handler as short-lived even when the framework feels like a server: Next.js / Nuxt / SvelteKit / Remix route handlers, serverless and edge functions, and Lambda are torn down per invocation before the send runs. Create the client with flushAt 1 and flushInterval 0, then await the send before returning. Always use `await posthog.flush()` for a shared/singleton client, `await posthog.shutdown()` for a per-request client. Never skip the awaited flush or risk the enqueued event being silently dropped.'
6262
- Reverse proxy is NOT needed for server-side Node.js – only client-side JavaScript needs a proxy to avoid ad blockers
6363

6464
python:
@@ -196,7 +196,7 @@ commandments:
196196
- Test queries in the PostHog SQL editor before using them in insights or the API
197197

198198
sveltekit:
199-
- 'For server-side capture (+server.ts endpoints, actions, hooks like handleError), the handler is short-lived per request — configure the posthog-node singleton with flushAt 1 and flushInterval 0, and `await posthog.flush()` after capturing and before returning, or the batched event is silently dropped when the request ends'
199+
- 'For server-side capture (+server.ts endpoints, actions, hooks like handleError), the handler is short-lived per request. Configure the posthog-node singleton with flushAt 1 and flushInterval 0, and `await posthog.flush()` after capturing and before returning, or the batched event is silently dropped when the request ends'
200200
- Set paths.relative to false in svelte.config.js — this is required for PostHog session replay to work correctly with SSR and is easy to miss
201201
- Use the Svelte MCP server tools to check Svelte documentation (list-sections, get-documentation) and validate components (svelte-autofixer) — always run svelte-autofixer on new or modified .svelte files before finishing
202202

@@ -256,13 +256,13 @@ commandments:
256256
astro-ssr:
257257
- Use posthog-node in API routes under src/pages/api/ for server-side event tracking
258258
- Store the posthog-node client instance in a singleton pattern (src/lib/posthog-server.ts) to avoid creating multiple clients
259-
- Configure the singleton with flushAt 1 and flushInterval 0, and `await posthog.flush()` in the API route after capturing and before returning the Response — an SSR endpoint is short-lived per request, so an unflushed batched event is silently dropped
259+
- 'Configure the singleton with flushAt 1 and flushInterval 0, and `await posthog.flush()` in the API route after capturing and before returning the Response. An SSR endpoint is short-lived per request, so an unflushed batched event is silently dropped'
260260
- Pass the client session ID to server via X-PostHog-Session-Id header for unified session tracking
261261

262262
astro-hybrid:
263263
- Use posthog-node in API routes under src/pages/api/ for server-side event tracking
264264
- Store the posthog-node client instance in a singleton pattern (src/lib/posthog-server.ts) to avoid creating multiple clients
265-
- Configure the singleton with flushAt 1 and flushInterval 0, and `await posthog.flush()` in the API route after capturing and before returning the Response — an SSR endpoint is short-lived per request, so an unflushed batched event is silently dropped
265+
- 'Configure the singleton with flushAt 1 and flushInterval 0, and `await posthog.flush()` in the API route after capturing and before returning the Response. An SSR endpoint is short-lived per request, so an unflushed batched event is silently dropped'
266266
- In Astro 5, use output static (the default) with an adapter - pages are prerendered by default
267267
- Use export const prerender = false to opt specific pages into SSR when they need server-side rendering
268268
- Only pages that need server-side PostHog tracking (like API-backed forms) should opt out of prerendering

0 commit comments

Comments
 (0)