Repository navigation
Wait for prerendered pages to be activated before running Optimization Detective - #2708
Draft
sarthak-19 wants to merge 2 commits into
Draft
sarthak-19 wants to merge 2 commits into
sarthak-19 wants to merge 2 commits into
Conversation
…n Detective Add an explicit document.prerendering check in detect.js so that URL Metric detection and extension loading/initialization wait for the page to be shown (plus an idle callback) before proceeding, instead of relying on the incidental timing of the intersection observer and onLCP callbacks.
Replace Array<any>, ...*, and Record<string, any> JSDoc types with Array<unknown>, ...unknown, and a localized Record<string, unknown> cast inside recursiveFreeze(), satisfying the jsdoc/reject-any-type lint rule without changing behavior.
This branch has not been deployed
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.
Summary
Fixes #1915.
detect.jsdid not explicitly account for the document being in a prerendered state (e.g. via Speculative Loading). In practice, detection mostly happened to wait anyway, since the intersection-observer callback andonLCPboth tend not to fire until the page is shown, and extension loading/initialization currently runs after those waits. But that guarantee was incidental, not an intentional one, and depended ondetect.jsstaying ordered a particular way.This adds an explicit
document.prerenderingcheck via awaitForPrerenderingToEnd()helper, awaited early indetect()right after the existing cheap synchronous abort checks and before the resize-listener setup, the web-vitals import, and extension loading. If the document is not prerendering, it resolves immediately with no behavior change. If it is prerendering, it waits for theprerenderingchangeevent (added viadocument.addEventListener, since the event is dispatched on the document rather than the window) and, if available, a subsequent idle callback, before detection proceeds.Test plan
npm run tscpasses.npm run lint-js/npm run format-jspass on the changed file (via lint-staged on commit).chrome://net-internalsor a speculation-rules prerendered link that detection now explicitly waits onprerenderingchangerather than only incidentally viaonLCP/intersection timing.