Skip to content

feat: add React Profiler integration and performance monitoring#520

Merged
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
Akanimoh12:feat/react-profiler-performance-monitoring
May 31, 2026
Merged

feat: add React Profiler integration and performance monitoring#520
RUKAYAT-CODER merged 1 commit into
rinafcode:mainfrom
Akanimoh12:feat/react-profiler-performance-monitoring

Conversation

@Akanimoh12
Copy link
Copy Markdown
Contributor

Summary

This PR implements comprehensive performance monitoring for the TeachLink Mobile app, addressing all acceptance criteria in issue #246.

What was added

  • useReactProfiler hook — wraps React's built-in Profiler API to capture actualDuration on every render and forward it to mobileAnalyticsService.trackPerformance. Renders exceeding slowRenderThresholdMs (default 16 ms / 1 frame at 60 fps) additionally emit a PERFORMANCE_METRIC analytics event with is_slow: true and a Metro console warning for immediate developer visibility.

  • ProfiledScreen component — a thin wrapper that composes useReactProfiler with <Profiler> so any screen can opt into render-time tracking with a single JSX element:

    <ProfiledScreen name="HomeScreen">
      <HomeContent />
    </ProfiledScreen>
  • Web Vitals auto-initwebVitalsService.init() is now called inside AnalyticsProvider on mount, so LCP, FID, CLS, FCP and TTFB collection starts automatically alongside the rest of the analytics stack. Regression detection (>20% worse than the first reading) emits a WEB_VITALS_REGRESSION event.

  • Tracking event extensionsPerformanceMetric gains RENDER_DURATION and NAVIGATION_LATENCY; AnalyticsEvent gains REACT_PROFILER_RENDER and REACT_PROFILER_SLOW_RENDER for consistent naming across the codebase.

  • docs/PERFORMANCE_MONITORING.md — documents all metric definitions, Google's Core Web Vitals thresholds, usage examples, baseline management, and alert behaviour.

Tests

  • tests/hooks/useReactProfiler.test.ts — covers render count accumulation, slow-render detection, custom threshold, high-frequency event-category bypass for analytics sampling.
  • tests/components/ProfiledScreen.test.tsx — covers child rendering, analytics forwarding, screen name propagation, and options prop.

Acceptance Criteria Coverage

Criterion Addressed by
Implement React Profiler integration useReactProfiler hook + ProfiledScreen component
Track FCP, LCP, TTI metrics webVitalsService.init() wired into AnalyticsProvider
Send performance metrics to analytics mobileAnalyticsService.trackPerformance called on every render; web vitals forwarded via trackEvent
Create alerts for performance regressions Slow-render console warning + PERFORMANCE_METRIC event; 20%-regression gate in webVitalsService
Document performance metrics definitions docs/PERFORMANCE_MONITORING.md
Establish performance baselines Existing performance-baseline.json + first-reading baseline in webVitalsService
Monitor in staging and production AnalyticsProvider initialises monitoring on every app mount regardless of environment

Test plan

  • Run npm test -- tests/hooks/useReactProfiler.test.ts — all assertions pass
  • Run npm test -- tests/components/ProfiledScreen.test.tsx — all assertions pass
  • Wrap a screen with <ProfiledScreen name="…"> and confirm Metro logs show render timing on each navigation
  • Confirm WEB_VITALS_REGRESSION event fires when a simulated metric reading exceeds 120% of the baseline

Closes #246

…fcode#246)

- Add `useReactProfiler` hook wrapping React's built-in Profiler API to
  capture per-component render times and forward them to analytics; slow
  renders (>16 ms) emit a PERFORMANCE_METRIC event with is_slow: true.

- Add `ProfiledScreen` wrapper component composing useReactProfiler with
  React's Profiler so screens opt in with a single JSX element.

- Initialise `webVitalsService` inside AnalyticsProvider so LCP, FID,
  CLS, FCP and TTFB collection starts automatically on app mount.

- Extend PerformanceMetric with RENDER_DURATION and NAVIGATION_LATENCY;
  extend AnalyticsEvent with REACT_PROFILER_RENDER and
  REACT_PROFILER_SLOW_RENDER for consistent event naming.

- Add unit tests for useReactProfiler and ProfiledScreen.

- Add docs/PERFORMANCE_MONITORING.md documenting metric definitions,
  baselines, usage examples, and regression-alert behaviour.

Closes rinafcode#246
@drips-wave
Copy link
Copy Markdown

drips-wave Bot commented May 30, 2026

@Akanimoh12 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@RUKAYAT-CODER RUKAYAT-CODER merged commit ba9b704 into rinafcode:main May 31, 2026
0 of 7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add performance monitoring with React Profiler and analytics

2 participants