npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

vitest-react-profiler

v1.9.0

Published

Performance testing utilities for React components and hooks with sync/async update tracking in Vitest

Downloads

516

Readme

vitest-react-profiler

npm version npm downloads CI

React React Testing Library Vitest

Enterprise Grade Testing Coverage Status Mutation testing badge Quality Gate Status Property-Based Testing

TypeScript Built with tsup ESLint Code Style: Prettier

License: MIT PRs Welcome Engineered with Claude Code

React component render tracking and performance testing utilities for Vitest

📖 Documentation🚀 Quick Start📚 API Reference💬 Discussions


Features

  • 🔍 Precise Render Tracking - Count exact number of renders with zero guesswork
  • Performance Monitoring - Detect unnecessary re-renders and track component behavior
  • 🎯 Phase Detection - Distinguish between mount, update, and nested update phases
  • 🪝 Hook Profiling - Profile custom hooks with full Context support via wrapper option
  • ⏱️ Async Testing - Subscribe to renders with onRender() and wait with waitForNextRender()
  • 🔔 Real-Time Notifications - React to renders immediately with event-based subscriptions
  • ⚛️ React 18+ Concurrent Ready - Full support for useTransition and useDeferredValue
  • 🧹 True Automatic Cleanup - Zero boilerplate! Components auto-clear between tests
  • 🚀 Zero Config - Works out of the box with Vitest and React Testing Library
  • 🛡️ Built-in Safety Mechanisms - Automatic detection of infinite render loops and memory leaks
  • 💪 Full TypeScript Support - Complete type safety with custom Vitest matchers
  • 🧬 Battle-Tested Quality - 100% mutation score, property-based testing, stress tests, SonarCloud verified
  • 🔬 Mathematically Verified - 244 property tests with 130,000+ randomized scenarios per run
  • 🏋️ Stress-Tested - 21 stress tests validate performance on 10,000-render histories
  • 📊 Performance Baselines - 46 benchmarks establish regression detection metrics

👥 Who Is This For?

🎨 UI-Kit and Design System Developers

Building a UI-kit for your project or company? You need to track, measure, and improve component performance. This tool helps you:

  • Catch unnecessary re-renders during development
  • Set performance budgets for components
  • Document performance characteristics in tests

📦 Open Source React Library Maintainers

Publishing React components? It's critical to prove your solution is optimized and won't degrade performance in user projects. With this tool, you can:

  • Add performance tests to CI/CD pipelines
  • Showcase performance metrics in documentation
  • Track performance regressions between releases

🎯 Tech Leads and Staff Engineers

Making architectural decisions requires data, not assumptions. Use the tool to:

  • Compare different state management approaches
  • Evaluate architectural changes' performance impact
  • Create performance guidelines for your team

📊 Teams with Strict Performance SLAs

Have strict performance requirements (fintech, healthcare, real-time systems)? The tool allows you to:

  • Set thresholds for render counts
  • Automatically verify SLA compliance in tests
  • Track asynchronous state updates

Quick Start

Installation

npm install --save-dev vitest-react-profiler
# or
yarn add -D vitest-react-profiler
# or
pnpm add -D vitest-react-profiler

Setup

// vitest-setup.ts
import "vitest-react-profiler";

Configure Vitest:

// vitest.config.ts
import { defineConfig } from "vitest/config";

export default defineConfig({
  test: {
    environment: "jsdom",
    setupFiles: ["./vitest-setup.ts"],
  },
});

Your First Test

import { render } from '@testing-library/react';
import { withProfiler } from 'vitest-react-profiler';
import { MyComponent } from './MyComponent';

it('should render only once on mount', () => {
  const ProfiledComponent = withProfiler(MyComponent);
  render(<ProfiledComponent />);

  expect(ProfiledComponent).toHaveRenderedTimes(1);
  expect(ProfiledComponent).toHaveMountedOnce();
});

⚛️ React 18+ Concurrent Features

Full support for React 18+ Concurrent rendering features - no special configuration needed!

The library automatically tracks renders from:

useTransition / startTransition

Test components using transitions for non-urgent updates

useDeferredValue

Test components using deferred values for performance optimization

How It Works

The library uses React's built-in <Profiler> API, which automatically handles Concurrent mode:

  • ✅ Transitions are tracked as regular renders
  • ✅ Deferred values trigger additional renders (as expected)
  • ✅ Interrupted renders are handled correctly by React
  • ✅ No special configuration or setup required

Note: The library tracks renders, not React's internal scheduling. Concurrent Features work transparently - your tests verify component behavior, not React internals.

📚 Read the complete guide →


Documentation

📖 Full documentation is available in the Wiki

Quick Links


Contributing

We welcome contributions! Please read our Contributing Guide and Code of Conduct.

# Run tests
npm test                    # Unit/integration tests (736 tests)
npm run test:properties     # Property-based tests (244 tests, 130k+ checks)
npm run test:stress         # Stress tests (21 tests, large histories)
npm run test:bench          # Performance benchmarks (46 benchmarks)
npm run test:mutation       # Mutation testing (100% score)

# Build
npm run build

License

MIT © Oleg Ivanov


Made with ❤️ by the community

Report BugRequest FeatureDiscussions