-
Notifications
You must be signed in to change notification settings - Fork 422
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Save a reference to the LCP and CLS targets in case they are removed from the DOM #562
base: v5
Are you sure you want to change the base?
Conversation
Test here: https://disappearing-cwv-node.glitch.me/index.html Maybe we should add this to the test suite? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe we should add this to the test suite?
Yes, I think we want a test for this behavior. It should be possible to test.
Added tests for LCP, CLS and even the INP scenario added in #477 |
Can you add the same logic for metric -> lcpEntry -> element? |
I've added it as a new |
Co-authored-by: Philip Walton <[email protected]>
@dmitiiv there's a request not to save the full element (see #580) but instead just the target due to the amount of memory that can be taken up. This makes reporting the element back kinda pointless (since it can be got from the lcp entry). Would the selector be sufficient for you without the element? |
@tunetheweb Yes, I've seen the issue. Removing the element (without saving) makes the fix almost useless for the purpose of obtaining information about the target element in a Single Page Application (SPA). It is critical to keep statistics without losing the details of the problem. However, if we still have an element selector, it could allow us to safely retain the necessary information. |
Yes we would still look to save the element selector (and in fact this would be the better selector since it would be calculated while the element is still part of the DOM, rather than once it's been removed). |
There are a number of tradeoffs being made here, balancing different needs from various users of this library. I think the root of all these issues is that currently the library has its own internal I wonder if instead of the library making decisions about these tradeoffs, it would be better to give users full control, in the form of letting them customize the target selector generation logic. Perhaps something like an option to pass their own onLCP(metricCallback, {
getTargetSelector: (element) => {
// Users can add whatever logic they want to generate a selector,
// some other identifier, or even just return the element itself.
return myCustomStringifyLogic(element);
}
}); This option would be available for all metric functions in the attribution build. Regarding whether to run the While we could make this change and always calculate at entry-dispatch time, any users who need this behavior can already get it by using the To be clear, I'm not necessarily opposed to this change, I just want to make sure we're thinking about all of the trade offs before making a decision that impacts all users of the library. |
Fixes #561
Note this also corrects an inconsistency where lcp selector in the attribution object was labeled
element
rather thantarget
(like CLS and INP).