mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-29 19:36:20 -05:00
deps: cachetools 7 and the current web-vitals API (#771)
cachetools 6 removed cachetools.func.mru_cache; the Zim search estimate cache was its only user, so it becomes an lru_cache and the pin moves to 7.2.0 with the Dependabot ignore removed. reportWebVitals still destructured the web-vitals 2.x names (getCLS, getFID, ...) which no longer exist, so it silently did nothing. Use the on* names, replace FID with INP, return the import promise, and accept any callable rather than instanceof Function. Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
parent
c28a9e0078
commit
1c8bbf1f10
6 changed files with 50 additions and 12 deletions
|
|
@ -1,11 +1,12 @@
|
|||
const reportWebVitals = onPerfEntry => {
|
||||
if (onPerfEntry && onPerfEntry instanceof Function) {
|
||||
import('web-vitals').then(({getCLS, getFID, getFCP, getLCP, getTTFB}) => {
|
||||
getCLS(onPerfEntry);
|
||||
getFID(onPerfEntry);
|
||||
getFCP(onPerfEntry);
|
||||
getLCP(onPerfEntry);
|
||||
getTTFB(onPerfEntry);
|
||||
if (typeof onPerfEntry === 'function') {
|
||||
// web-vitals 3+ renamed get* to on*; 5+ replaced FID with INP.
|
||||
return import('web-vitals').then(({onCLS, onINP, onFCP, onLCP, onTTFB}) => {
|
||||
onCLS(onPerfEntry);
|
||||
onINP(onPerfEntry);
|
||||
onFCP(onPerfEntry);
|
||||
onLCP(onPerfEntry);
|
||||
onTTFB(onPerfEntry);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
|
|
|||
28
app/src/reportWebVitals.test.js
Normal file
28
app/src/reportWebVitals.test.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
jest.mock('web-vitals', () => ({
|
||||
onCLS: jest.fn(),
|
||||
onINP: jest.fn(),
|
||||
onFCP: jest.fn(),
|
||||
onLCP: jest.fn(),
|
||||
onTTFB: jest.fn(),
|
||||
}));
|
||||
|
||||
import reportWebVitals from './reportWebVitals';
|
||||
import * as webVitals from 'web-vitals';
|
||||
|
||||
describe('reportWebVitals', () => {
|
||||
test('subscribes the callback to every current web-vitals metric', async () => {
|
||||
const callback = jest.fn();
|
||||
const pending = reportWebVitals(callback);
|
||||
expect(pending).toBeDefined();
|
||||
await pending;
|
||||
for (const name of ['onCLS', 'onINP', 'onFCP', 'onLCP', 'onTTFB']) {
|
||||
expect(webVitals[name]).toHaveBeenCalledWith(callback);
|
||||
}
|
||||
});
|
||||
|
||||
test('does nothing without a function', async () => {
|
||||
jest.clearAllMocks();
|
||||
expect(reportWebVitals(undefined)).toBeUndefined();
|
||||
expect(webVitals.onCLS).not.toHaveBeenCalled();
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue