Fix spurious CLS report of 0 after bfcache restore - #786
Merged
tunetheweb merged 1 commit intoAug 24, 2026
Merged
Conversation
Restore the zero-arg wrapper inside doubleRAF() so its callback is always invoked without arguments. Without it the rAF DOMHighResTimeStamp was passed to bindReporter's forceReport parameter, forcing a CLS report of 0 on every bfcache restore even when reportAllChanges was false. Adds e2e coverage for both reportAllChanges values, and a missing beaconCountIs() wait in an unrelated pre-existing racy test. Fixes GoogleChrome#785
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #785.
Restores the zero-arg wrapper inside
doubleRAF()so its callback is always invoked with no arguments:Per @Mimori256's suggestion in #785 I've taken the
doubleRAF()hardening as the primary fix rather than reverting theonCLS()call site, since it re-establishes the invariant for every call site.src/onCLS.tsis unchanged.Tests
Added e2e coverage for both
reportAllChangesvalues, as @tunetheweb requested:does not report a spurious zero value after bfcache restore (reportAllChanges === false)— the regression test. Fails onmain(through both retries), passes with the fix.reports the initial zero value after bfcache restore (reportAllChanges === true)— guards against over-correcting, so the zero-value report is still emitted whenreportAllChangesis true. Passes with and without the fix.Drive-by
Also adds a missing
await beaconCountIs(1)toreports zero if no layout shifts occurred on first visibility hidden (reportAllChanges === false). That test reads the beacon file without waiting for the beacon to arrive, unlike itsreportAllChanges === truesibling which has exactly that wait — an unrelated pre-existing race (those lines date to 2020/2022) that I hit locally. Happy to split it out if you'd prefer.Verification
npm run test:e2e -- --browsers=chrome: 5/5 spec files, 153 passing, 4 skipped. Build, lint, format:check and unit tests all green. Reverting only thedoubleRAFchange leaves the newreportAllChanges === falsetest failing and everything else green.