feat(core): add X-Correlation-ID header, cache guest queries separately#2910
feat(core): add X-Correlation-ID header, cache guest queries separately#2910
Conversation
🦋 Changeset detectedLatest commit: cd035fa The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
4daa258 to
b4cfed3
Compare
Bundle Size ReportComparing against baseline from No bundle size changes detected. |
b4cfed3 to
ac729db
Compare
ac729db to
827eb1e
Compare
9af30f0 to
d9c2fd4
Compare
d9c2fd4 to
40ee9ce
Compare
40ee9ce to
bdb6aec
Compare
Unlighthouse Performance Comparison — VercelComparing PR preview deployment Unlighthouse scores vs production Unlighthouse scores. Summary ScoreAggregate score across all categories as reported by Unlighthouse.
Category Scores
Core Web Vitals
|
bdb6aec to
173377f
Compare
173377f to
cd035fa
Compare
41fbf12 to
cd035fa
Compare
|
@jorgemoya I hate to ask this as you've already done the work, but is there any way to separate out caching the guest queries into smaller PRs then when that is all done, add the correlation id header? |
|
@chanceaclark no problem! 👍 |
|
Closing this to split into multiple PRs |
What/Why?
All GraphQL requests now include an
X-Correlation-IDheader containing a UUID that is stable for the duration of a single page render (viaReact.cache), making it easier to trace and correlate all requests made during a single render in server logs.Guest (unauthenticated) queries are now cached using
unstable_cachewith the configured revalidation interval, while authenticated requests continue to usecache: 'no-store'. This separates cacheable public data from session-specific data, improving performance for unauthenticated visitors. TheX-Forwarded-ForandTrue-Client-IPheaders are only forwarded on uncached (no-store) requests since they are unavailable insideunstable_cache.Testing
Locally + E2E
Migration
Step 1: Add the correlation ID helper
Create
core/client/correlation-id.ts:Step 2: Update
core/client/index.tsUpdate the
beforeRequesthook to add theX-Correlation-IDheader to all requests and to only forwardX-Forwarded-For/True-Client-IPon uncached requests:Step 3: Wrap guest queries with
unstable_cacheFor each page data file, wrap the guest (unauthenticated) fetch in
unstable_cacheand branch on whether acustomerAccessTokenis present. Example pattern:Future path with Next 16
We will eventually migrate to use
cacheComponents, so this migration tounstable_cachewill provide as the foundation of caching request functions in Catalyst going forward. In a future scenario, it will be as simple as replacingunstable_cachefor theuse cachedirective.