WICG / soft-navigations

Heuristics to detect Single Page Apps soft navigations
https://wicg.github.io/soft-navigations/
Other
46 stars 6 forks source link

Correlating LCP with navigations #5

Closed mmocny closed 1 year ago

mmocny commented 1 year ago

The current example for LCP I think does not work well when there are multiple LCP candidates per navigation. While it is probably outside the goal of this document to correctly implement vitals (theres a lot more to it...), I do think that this one may be specifically worth addressing: to make sure there's one final LCP per navigation. Perhaps the simplest option is to change:

for (entry of lcp_entries)

To something like:

final_lcp = lcp_entries.filter((candidate, index) => index == lcp_entries.findLastIndex(entry => candidate.navigationId == entry.navigationId));
for (entry of final_lcp))
yoavweiss commented 1 year ago

Those examples are trying to do different things: You're trying to get the LCP value, while my example find the entry for all LCP entries (which may or may not be the final ones). I'll add comments to clarify my example

yoavweiss commented 1 year ago

Let me know if https://github.com/yoavweiss/soft-navigations/blob/main/README.md#correlating-performance-entries-with-a-soft-navigation still needs work in your opinion

mmocny commented 1 year ago

Ah, thanks for the clarification. That makes sense (maybe it always did and I misread)