From e68464b9462e8c724e09db70a6d041556784a53c Mon Sep 17 00:00:00 2001 From: vklimontovich Date: Fri, 5 Jun 2026 11:31:31 -0400 Subject: [PATCH] fix: await delivery in analytics().sendEvent() MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit sendEvent dispatched the event but only awaited the dispatch kickoff, not the `completion` promise, so backend writes were effectively fire-and-forget. In a serverless function the process can freeze right after the response, dropping the in-flight writes — so `await sendEvent()` did not actually guarantee delivery. Await `completion` instead. The middleware page-view path is unaffected: it still defers completion with `after()` and never calls sendEvent. --- packages/core/src/server.tsx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/core/src/server.tsx b/packages/core/src/server.tsx index e664848..e8299ed 100644 --- a/packages/core/src/server.tsx +++ b/packages/core/src/server.tsx @@ -335,7 +335,13 @@ export function Nextlytics(userConfig: NextlyticsConfig): NextlyticsResult { userContext, properties: { ...propsFromCallback, ...opts?.props }, }; - await dispatchEventInternal(event, ctx); + // Await full delivery, not just dispatch kickoff. Unlike the middleware + // page-view path (which defers `completion` with `after()`), an explicit + // sendEvent has no response to ride on — in a serverless function the + // process can freeze right after this returns, dropping in-flight backend + // writes. Awaiting `completion` makes `await sendEvent()` mean "delivered". + const { completion } = dispatchEventInternal(event, ctx); + await completion; return { ok: true }; },