mirror of
https://github.com/HeyPuter/firefox.git
synced 2026-11-13 20:14:57 -10:00
Introduces a shared React hook for function-component newtab widgets so
they stop hand-building telemetry payloads. The hook covers all four
widget telemetry action types (WIDGETS_IMPRESSION, WIDGETS_USER_EVENT,
WIDGETS_ENABLED, WIDGETS_ERROR), reads widget_name from the widget's
WIDGET_REGISTRY entry, and tracks widget_size via a ref so dispatches
always reflect the latest value (with per-call override).
API:
- impressionRef: callback ref. Observes on assignment so widgets that
conditionally render the target still get observed.
- recordImpression({ size }): manual one-shot fire sharing the observer's
impressionFired guard.
- recordUserAction(action, { source, value, size, alsoToMain, legacy }):
alsoToMain switches routing from OnlyToMain to AlsoToMain (for the
Lists task-complete path); legacy co-dispatches a configured
legacyUserEventType with { userAction }.
- recordEnabled(enabled, { source, size })
- recordError(errorType, { size })
Constructor options legacyImpressionTypes (array) and legacyUserEventType
bridge the Bug 2012779 transition: while WIDGETS_TIMER_* / WIDGETS_LISTS_*
legacy events still exist alongside the unified events, FocusTimer and
Lists pass the matching legacy action types so the hook emits both.
Co-dispatches fire legacy first, unified second to match the pre-hook
dispatch order.
Scope: function-component widgets under content-src/components/Widgets/.
The class-based mini Weather at content-src/components/Weather/Weather.jsx
is intentionally out of scope - its legacy WEATHER_* actions with custom
payloads would require a non-hook payload helper.
No callers yet; webpack drops the hook from the bundle until a widget
imports it. Bundle is unchanged in this commit. Widget migrations follow
in separate commits.
Differential Revision: https://phabricator.services.mozilla.com/D300850