polyfill usage with /base is counterintuitive
See original GitHub issueHi there. The how the polyfill works section states:
The “standard” version of the web-vitals library includes some of the same logic found in
polyfill.js
This means that you must include the polyfill, even on browsers (ie chrome) that natively support First Input Delay. Omitting the polyfill will break FID on chrome. (Cannot read property 'firstHiddenTime' of undefined
)
This is rather counterintuitive: it means the polyfill is doing more than just polyfilling. It’s bundling some application logic in with the polyfill. I’ve never seen another polyfill on the web that acts this way - a reasonable developer expectation is that polyfills replace missing browser functionality, and no more.
Can we make the polyfill pure, and leave application logic inside the app? Alternately, calling this something other than a “polyfill” since it’s really a polyfill + helper script. Thanks.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
I think it can be clarified. We ran into the same issue where we operated under the faulty assumption that in the worst case, a missing polyfill would just mean no data. I assumed I would still be able to call getFID, and that the onReport callback would just never be triggered if it wasn’t supported. Instead, without the polyfill, getFID raises an uncaught exception.
It’d be valuable to update the documentation to call out that without the polyfill, use of the web vitals base script may produce undefined behaviour, and not just “missing data”. Alternatively, in my opinion it’s more intuitive to have the various getMetric functions just become no-ops if there is not sufficient information to trigger the onReport handler.
Thanks for the response. I will be on hiatus for the next week and can reply next Monday. Hope you and everyone else reading this has a happy and safe holiday.