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 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-pinpoint

v1.0.6

Published

React Pinpoint is an open source utility library for measuring React component render times.

Downloads

17

Readme

React Pinpoint

An open source utility library for measuring React component render times.

Build Status

Table of Contents

Prerequisites

Browser context

React pinpoint must run inside a browser context to observe the React fiber tree. We recommended using automation software such as puppeteer to achieve this.

Production build with a twist

React optimises your development code base when you build for production, which decreases component render times. Users should therefore run react pinpoint against their production code

However, tweaks need to be made to the build process to preserve component names and enable render time profiling. Steps for doing so can be found here.

APIs

record(page, url, rootId)

  • page <Page> Puppeteeer page instance
  • url <string> address React page is hosted at
  • rootId <string> id of dom element that React is mounted to
  • returns: <Page> Puppeteeer page instance with a listener attached to React components

This function attaches a listener to the Puppeteer page's react root for recording changes

report(page, threshold)

  • page <Page> Puppeteeer page instance with record listener attached
  • threshold <Number> cutoff for acceptable component render time (in ms)
    • default time is 16ms
  • returns: Node[] An array of nodes belonging to each react component that exceeded the given render time threshold

Will report all component render times that exceed the given threshold in ms

If no threshold is given, the default threshold of 16ms is used (please see FAQ “Why is the default render threshold 16ms?”)

Examples

Using with Puppeteer

const puppeteer = require('puppeteer');
const reactPinpoint = require('react-pinpoint');

(async () => {
  const browser = await puppeteer.launch({});
  const page = await browser.newPage();

  // Pass information to
  const url = 'http://localhost:3000/calculator';
  const rootId = '#root';
  await reactPinpoint.record(page, url, rootId);

  // Perform browser actions
  await page.click('#yeah1');
  await page.click('#yeah2');
  await page.click('#yeah3');

  // Get all components that took longer than 16ms to render during browser actions
  const threshold = 16;
  const slowRenders = await reactPinpoint.reportTestResults(page, threshold);

  await browser.close();
})();

Getting Started

  1. Head over to the React Pinpoint website.
  2. Register for an account.
  3. Add a project and fill in the details.
  4. Copy the project ID provided.

Installation

Using npm:

npm install -D react-pinpoint

Using yarn:

yarn add react-pinpoint -D
  • Invoke mountToReactRoot and paste the project ID you received from the website as the second argument in your React project’s entry file:
mountToReactRoot(rootDom, projectID);
  • Interact with your app and data will be sent to React Pinpoint website.
  • Refresh the page and see your data displayed!

Docker

React pinpoint was designed with the goal of regression testing component render times within a CICD, we therefore offer several preconfigured docker containers to assist with using React pinpoint within a CICD as well as with examples for doing so.

FAQs

Why does React Pinpoint only measure individual component render times?

Since React has moved to using a React Fiber infrastructure, different component types are assumed to generate different trees.

Why is the default render threshold 16ms?

The recommended render time is 60 FPS.

Does React pinpoint work in a headless browser?

Yes! Due to the component render times being driven by component logic, a GUI is not needed to capture them.