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

tachyon-latency-tracker

v32.0.0

Published

tracks latency in react apps

Downloads

4

Readme

Latency Tracker

  • Provides SSR compatible Benchmark Tracking for React Applications
  • Optional Transition Abandonment Reporting

Installation

$ yarn add tachyon-latency-tracker

This package provides components to handle interactivity tracking for an SSR Relay/React app. It uses the Performance and UserTiming APIs to generate timestamps for events relevant to the "time to interactivity" / "customer wait time" for loading pages.

Enabling Latency Tracking

Use the LatencyTrackerRoot to consume reported latency events in your application. The following events will be reported by doing so (listed in order of appearance):

  1. benchmark_fetch_start
  2. benchmark_app_booted
  3. benchmark_complete_transition
import { LatencyTrackerRoot, LatencyTrackerRootProps } from 'tachyon-latency-tracker';

const appData: LatencyTrackerRootProps['appData'] = { ... };

const root = (
  <LatencyTrackerRoot
    appData={appData}
    currentLocation={...}
    currentPath={window.location.pathname}
    interstitialLocations={[
      // If the app has entry points that serve as non-destinations, like a
      // redirecting location for a PWA, add this optional prop to prevent these
      // locations (based on route/data-science names) from being counted in
      // transition logic
      'app-shell'
    ]}
    onEvent={...}
  >
    <AppComponents />
  </LatencyTrackerRoot/>
);

To disable latency tracking in an app without having to alter the component tree, use the disableLatencyTracking prop on LatencyTrackerRoot.

Transition Complete tracking

There are two ways to signal that a route/location has finished rendering its baseline interactive experience.

<LatencyTransitionComplete />

Render this component when a route has completed rendering. This is meant to be placed in the opposite branch from a loading UI:

if (loading) {
  return <LoadingPage />;
} else {
  return (
    <>
      <LatencyTransitionComplete />
      <ActualPage />
    </>
  );
}

This declarative approach is the recommended usage.

useLatencyTransitionComplete()

This is a hook that can be used more imperatively to signal that a route has completed rendering.

const reportTransitionComplete = useLatencyTransitionComplete();

useEffect(() => {
  if (!loading) {
    reportTransitionComplete();
  }
});

This must be run in an effect to ensure that the DOM has been updated before reporting transition complete. This exact structure is used inside <LatencyTransitionComplete />.

For pages that don't require JS for interactivity

In an SSR application, many pages can be considered interactive before JavaScript boots if they are the initial page loaded by the user. This means an app could consider interactivity to happen when domInteractive happens in those situations. Since this requires more attention and decision-making, the latency framework by default waits until JS boots to report transition complete, but it is capable of "backdating" the interactivity time to the domInteractive mark. To opt into this behavior, use the requiresJsForInteractivity parameter:

<LatencyTransitionComplete requiresJsForInteractivity={false} />

or

useEffect(() => {
  if (!loading) {
    reportTransitionComplete({ requiresJsForInteractivity });
  }
});

This only affects the initial page in a navigation session. For subsequent in-app navigations, normal marking and measuring is used.

Overriding the reported location

For most use-cases, the current location is passed into the LatencyTrackerRoot at the top of the app. For apps where this is not possible, the transition complete functionality takes an additional location parameter for overriding the root location value at the call site.

Visualizing

Using the UserTiming API, the framework generates marks and measures relevant to the timing of page transitions. These can be seen in the performance monitoring tab of browser developer tools to get a better sense of how pages are performing.