restore metadata dep in analytics useChild memo

The phase-2 session rework dropped `metadata` from the child logger's
useMemo deps to satisfy exhaustive-deps (which misclassifies the
closure-captured value as outer-scope because createLogger is defined
outside a component - lint-staged's --fix strips the dep on commit).
But AnalyticsContext explicitly re-renders (not remounts) on account
change with a new did, producing a fresh createLogger closure with new
metadata; a mounted consumer's memoized child logger kept the previous
account's metadata, misattributing telemetry across session switches.
Suppress the rule with the why and keep the dep.

Found by a full-diff roast pass.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Samuel Newman
2026-07-18 16:21:25 +03:00
parent 1ea30c64f0
commit 3d7cee234d
+9
View File
@@ -84,6 +84,15 @@ function createLogger(
warn: logger.warn.bind(logger),
error: logger.error.bind(logger),
useChild: (context: Exclude<Logger['context'], undefined>) => {
/*
* `metadata` is a real dependency: each parent re-render (e.g. an
* account switch, which re-renders AnalyticsContext without remounting
* consumers) creates a fresh `createLogger` closure with new metadata,
* and without the dep the memoized child would keep logging with the
* previous account's metadata. The exhaustive-deps rule misclassifies
* it as an outer-scope value (the closure is defined outside a
* component) and `--fix` would silently strip it.
*/
// oxlint-disable-next-line react-hooks/exhaustive-deps
return useMemo(() => createLogger(context, metadata), [context, metadata])
},