Comments (3)
@hindsc52
Is this the correct way to call these methods? The component this is in is called in the main layout container that is used to wrap each page.
I'm not super familiar with React hooks, but yes, I believe useEffect()
is the recommended way to prevent something from being executed on the server.
Another option would be to use dynamic import()
to load the web-vitals
library, which should also prevent that code from running when rendered on the server. Another advantage of using dynamic import()
is it'll keep all the web-vitals
code out of your app's main entry bundle.
I'm also curious about this. Does it make sense to wrap the calls in a
requestIdleCallback
?
You do not need to use requestIdleCallback()
with the web-vitals
library. The underlying APIs themselves already do their best to dispatch the PerformanceObserver
callbacks during idle periods, and in cases where that's not possible you need the callbacks to run right away (like if the page is unloading).
If you just use the callbacks as described in the docs, it shouldn't have any negative effects on performance.
from web-vitals.
I'm also curious about this. Does it make sense to wrap the calls in a requestIdleCallback
?
from web-vitals.
I'm not super familiar with React hooks, but yes, I believe useEffect() is the recommended way to prevent something from being executed on the server.
This is an old post, but in case anyone else stumbles across it, I think it's worth noting that if you put these in a useEffect
they should only be called ONCE on mount. See this discussion for more context:
from web-vitals.
Related Issues (20)
- can't find ReportCallback or ReportHandler type HOT 3
- Are there any updates for soft-navs? HOT 2
- LoAF missed for some INP events HOT 9
- Facing issue while exporting `web-vitals/attribution` using `browserify` HOT 2
- LoAF Performance entry script sourceFunctionName and sourceURL logged values HOT 4
- Using `performance.eventCounts` instead of `performance.interactionCount` HOT 2
- Heads Up on Changes to INP Measurement When Interfered with JS Modal Dialogs HOT 3
- TypeError: Cannot read properties of undefined (reading 'processingEnd') HOT 13
- TypeScript 5.5 compatibility
- Speculation rules can impact on increase values for INP ?
- Missing Cumulative Layout Shift (CLS) metric when batching multiple reports together in a single network request HOT 5
- Add clarification regarding event listener in event batching section
- LCP and CLS fired on interaction HOT 5
- Tgt
- Update LCP attribution to handle the first frames of animated content HOT 3
- INP attribution helper latestProcessingEnd never initialized HOT 1
- Missing LoAF attributions for INP due to violating internal invariants
- Any way to simulate clicks for INP testing? HOT 3
- Identical abstract selectors can be returned as distinct strings HOT 6
- onINP trigger always when browser tab change ? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from web-vitals.