-
Notifications
You must be signed in to change notification settings - Fork 2
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
fix storeTabData caching wrong frame target values during prerendering #242
Conversation
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.
What happens if both calls to storeTabData are made while the tab is prerendering? The content script will be in a broken state: no tab data will ever be requested again, but this data is a hard requirement in the content script.
The only advised change here would look like this instead:
async function storeTabData() {
if (document.prerendering) {
await pEvent(document, 'prerenderingchange')
}
//continue
I'm not sure I understand. What two calls are you referring to? It seems to me that with this change we will make sure to refetch the tab data if/when it's needed again after the prerendered tab is activated. |
It should just wait until the document explicitly exits the prerendering stage instead. |
@fregante's suggested solution is simpler and also works, so I'll go with this approach!
|
@@ -65,6 +66,11 @@ const storeTabData = once(async () => { | |||
return; | |||
} | |||
|
|||
// If the page is prerendering, wait for the change to be able to get the tab data so the frameId is correct | |||
if ("prerendering" in document && Boolean(document.prerendering)) { | |||
await pEvent(document, 'prerenderingchange') |
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.
@fungairino you might not need the if
statement. The docs say that it might fire immediately if the document is already rendered: https://developer.mozilla.org/en-US/docs/Web/API/Document/prerenderingchange_event#examples
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.
prerendering isnt a widely supported browser feature yet, so I'm leaning towards keeping the check to be more explicit. Especially since the linked example also still checks for the prerendering attribute.
Fixes pixiebrix/pixiebrix-extension#8283
The
storeTabData
was caching the wrong frame value with itsonce
usage when the browser prerenders the page (ex. the user starts typing the url in the search bar and the page is loaded (i.e. prerendered) in the background.This change fixes the issue by waiting for the
prerenderingchange
event if the document is currently in prerendering state.I tested these changes by running
npm link
and then in pixiebrix-extension rannpm link webext-messenger
. I built the extension and tested the above-linked bug with a mod that reproduces the error. With this new change, the issue no longer is present.Reviewer: @twschiller
Tag: @fregante
New dependency,
p-event
. MIT Licensehttps://www.npmjs.com/package/p-event