From 3d7cee234d9328c5abd6de738c6d699c037613fb Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Sat, 18 Jul 2026 16:21:25 +0300 Subject: [PATCH] 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 --- src/analytics/index.tsx | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/analytics/index.tsx b/src/analytics/index.tsx index 51438c2d7b..56932ea8c1 100644 --- a/src/analytics/index.tsx +++ b/src/analytics/index.tsx @@ -84,6 +84,15 @@ function createLogger( warn: logger.warn.bind(logger), error: logger.error.bind(logger), useChild: (context: Exclude) => { + /* + * `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]) },