Skip to content

Make analytics track route resilient to non-request runtimes (after() fallback) - #14

Draft
hiabhee with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-152391363-1181858013-e13a282f-93fe-443c-8b4b-8ed286b5bc01
Draft

Make analytics track route resilient to non-request runtimes (after() fallback)#14
hiabhee with Copilot wants to merge 2 commits into
mainfrom
copilot/fix-152391363-1181858013-e13a282f-93fe-443c-8b4b-8ed286b5bc01

Conversation

Copilot AI commented Aug 6, 2026

Copy link
Copy Markdown

The quality Actions job failed because analytics integration tests invoke POST /api/track outside a Next.js request scope, where after() throws (next-dynamic-api-wrong-context). This change keeps deferred writes in real request contexts while preserving route behavior in test/non-request execution.

  • Root cause

    • frontend/app/api/track/route.ts unconditionally called after(async () => ...).
    • In Vitest route invocation, this raised and failed analytics contract tests.
  • Route hardening

    • Extracted persistence logic into a single persistAnalytics function.
    • Wrapped scheduling in try/catch:
      • request scope: after(persistAnalytics) (existing latency behavior preserved)
      • non-request scope: await persistAnalytics() fallback
  • Behavioral impact

    • No schema/contract changes to analytics payload validation.
    • No changes to tracking response shape ({ ok: true, recorded: events.length }).
const persistAnalytics = async () => {
  // visitor/session/event writes
};

try {
  after(persistAnalytics);
} catch {
  await persistAnalytics();
}

@vercel

vercel Bot commented Aug 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
arch-draw Ready Ready Preview Aug 6, 2026 10:04am

Co-authored-by: hiabhee <152391363+hiabhee@users.noreply.github.com>
Copilot AI changed the title [WIP] Copilot Request Make analytics track route resilient to non-request runtimes (after() fallback) Aug 6, 2026
Copilot AI requested a review from hiabhee August 6, 2026 10:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants