You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
fix: deliver client-side templates to Pages Router clients (#37)
* fix: deliver client-side templates to Pages Router clients
Pages Router's getNextlyticsProps runs in getInitialProps without access
to config, so it can't collect client-side templates the way App Router's
NextlyticsServer does. Include templates in the /api/event response and
merge them on the client from whichever source supplies them, so script
insertions compile on both routers.
Also stop getNextlyticsProps from throwing on client-side navigations,
where _app's getInitialProps re-runs with no req.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* perf: only return templates the client is missing
The client now sends the template ids it already holds in a header, and
the server diffs against the templates resolved for the request, returning
only the new ones. App Router clients hold the full set from the ctx prop,
so they get an empty response; a Pages Router client receives each template
once instead of on every event. The diff is per-request, so it stays correct
when backend resolution (and thus the template set) varies by request.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* test(e2e): cover Pages Router script delivery, simplify _app example
getNextlyticsProps now tolerates a missing req, so the _app example no
longer needs to guard ctx.req itself — call it directly, which doubles as
the documented usage.
Add an initial-load test (both routers) asserting the client-side script
templates compile and run. On Pages Router this only works once templates
arrive via /api/event, so it guards the fix; the prior script test was
App-Router-only.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
* style: apply prettier formatting
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
0 commit comments