Upgrade web-vitals to 6.2.3

What does this MR do and why?

Upgrades web-vitals from 0.2.4 (July 2020) to 6.2.3. Its only user is the performance bar's console log in app/assets/javascripts/performance_bar/performance_bar_log.js.

  • INP replaces FID. FID is no longer a Core Web Vital, and v5 removed onFID. CLS now uses the session-window definition that Chrome and CrUX use, so its values are lower than before on long-lived pages.
  • webpack 4 needs Babel for it. v6 ships untranspiled class fields, ?. and ??. GDK's webpack mode still uses webpack 4, and without a rule the performance_bar bundle fails with Module parse failed: Unexpected token (1:168) and the bar doesn't render. web-vitals joins the existing @github/arianotify-polyfill rule. Production builds (yarn build) use Rspack, which has its own loader rules and doesn't use this one. Vite and Jest need no change.
  • Metrics log live. reportAllChanges logs each metric whenever it changes, so values show up without switching tabs. CLS is the exception: it changes on every layout shift, so it still logs once when the tab is hidden. FCP and TTFB are logged too, since the library already provides them.
  • yarn.lock changes only the web-vitals entry. Danger's duplicate-dependency warning lists duplicates that are already on master. Don't run the dedupe it suggests: it removes the browserslist 4.28.5 pin from c086cc49, and Rspack then fails with unknown version '157' of browser 'chrome'.
Why each part is needed
  • 0.2.4 → 6.2.3 breaking changes that touch this file: getXXX() renamed to onXXX() (v3, old names removed in v4), onFID() removed (v5). The metric object lost isFinal (v1) and gained rating and navigationType. The log prints the whole object, so nothing reads those fields.
  • webpack resolves the package's module field to dist/web-vitals.js. Parsing it with webpack 4's acorn 6.4.2 at ecmaVersion: 11 fails at 1:168 (the ?? in (o??0)). After the project's babel.config.js it parses with no ?. or ?? left. I confirmed the failure and the fix with GDK switched to webpack.
  • The merged rule still matches node_modules/@github/arianotify-polyfill/arianotify-polyfill.js, with the same loader and options. I checked the polyfill still installs and announces into its live regions after removing Chrome's native ariaNotify.
  • Jest resolves the package's require export, dist/web-vitals.umd.cjs, which Node runs natively. yjs, zod, marked and graphql-ws already load as .cjs the same way.
  • The bundle grows by about 2 KB gzipped, only in the performance_bar entry, which loads only when the performance bar is on.
  • No changelog trailer: this only changes the performance bar's console output.

References

Screenshots or screen recordings

Before After
Not captured. 0.2.4 logged only CLS, FID and LCP. FID and LCP waited for the first input, and CLS waited for a tab switch. web-vitals-6-console

The console panel in the screenshot is the page's console.log output from one load in GDK, rendered on the page so it fits in one image. FCP, LCP and TTFB logged on load, and INP after one key press. CLS logged after a tab hide, which I had to simulate with a visibilitychange event because the test browser can't hide a tab.

How to set up and validate locally

  1. On any page in GDK, press p then b to turn on the performance bar.

  2. Open the browser console and reload. FCP, LCP and TTFB log on load. Press a key or click to log INP, then switch to another tab and back to log CLS.

  3. To check webpack 4, switch GDK from Vite to webpack, disabling Vite first, then repeat step 2:

    gdk config set vite.enabled false
    gdk config set webpack.enabled true
    gdk reconfigure
    gdk restart

    To switch back, run gdk config set webpack.enabled false, then gdk config set vite.enabled true, gdk reconfigure and gdk restart.

  4. Optional: to check @github/arianotify-polyfill, open a page in a browser without native ariaNotify (for example Firefox), run document.body.ariaNotify('hello') in the console, and check that a polite-live-region-… element appears at the end of <body>.

MR acceptance checklist

Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Jacques Erasmus

Merge request reports

Loading
Loading