Skip to content
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

event.persisted for pagereveal event #10311

Open
o-t-w opened this issue Apr 30, 2024 · 4 comments
Open

event.persisted for pagereveal event #10311

o-t-w opened this issue Apr 30, 2024 · 4 comments
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest

Comments

@o-t-w
Copy link

o-t-w commented Apr 30, 2024

What problem are you trying to solve?

Seeing as this event is fired even when the bfcache is used, doesn't it make sense for the event to have a .persisted property? Suggested here.
The spec and the Chrome implementation does not include this.

What solutions exist today?

No response

How would you solve it?

No response

Anything else?

No response

@o-t-w o-t-w added addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest labels Apr 30, 2024
@domenic
Copy link
Member

domenic commented May 1, 2024

What's wrong with using pageshow?

@o-t-w
Copy link
Author

o-t-w commented May 4, 2024

Apologies if this represents a lack of understanding on my part. I know this event is perhaps exclusively meant for use with view transitions.

Lets say somebody needs to inject some critical dynamic content at the top of the page, for example. They want to do that ASAP to avoid layout shift. They might purposefully use a blocking classic inline script, or maybe an inline <script type="module" async blocking="render"> but then they'd need to use DOMContentLoaded in order to avoid querySelector returning null, but DOMContentLoaded only fires after all deferred scripts. So for their JavaScript to run as early as possible the quicker option is actually to use a deferred script which won't need a DOMContentLoaded event listener. Is there a reason you shouldn't be able to use pagereveal for this sort of purpose? Wouldn't you want to do this sort of thing at the first render opportunity in conjunction with <link rel="expect" href="#visually-critical-thing" blocking="render">? Use-cases for render-blocking other than view transitions have been discussed.

If you added some dynamic content to the DOM inside of pagereveal, navigate to another page, and then press the back button and bfcache has cached the page, the dynamic content would be added to the cached page all over again. If you keep pressing the forward and back button the same DOM nodes get added nth number of times... Wouldn't checking for event.persisted be able to avoid that scenario?

@domenic
Copy link
Member

domenic commented May 4, 2024

Sorry, I can't quite understand how that answered my question... Can you show me what goes wrong with using pageshow to accomplish your use case?

@o-t-w
Copy link
Author

o-t-w commented May 4, 2024

For the use case I mentioned, on an initial page load pageshow fires too late to safely avoid layout shift or flashes of wrongly-styled content (it fires after the load event).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
addition/proposal New features or enhancements needs implementer interest Moving the issue forward requires implementers to express interest
Development

No branches or pull requests

3 participants
@domenic @o-t-w and others