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

RFC: update the client visible directive to track actual visibility #212

Closed
wants to merge 1 commit into from

Conversation

okikio
Copy link
Member

@okikio okikio commented Jun 24, 2022

  • Start Date: 2022-06-24
  • Status: Draft

Summary

RFC that updates the client visible directive's default behavior to track actual visibility, while also leaving the option for devs to opt-out and return to the older intersection-only behavior.

This RFC ensures, that components with client:visible only hydrate when they are actually visible (in all the senses of the word), e.g. meaning if the component is obscured by another element then Astro won't load it, or if the component is made invisible via either opacity or visibility, then the component won't hydrate.

Links

…lity

RFC that updates the client visible directive's default behavior to track actual visibility, while also leaving the option for devs to opt-out and return to the older `intersection-only` behavior.
@okikio okikio changed the title docs(rfc): update the client visible directive to track actual visibility RFC: update the client visible directive to track actual visibility Jun 24, 2022
@okikio
Copy link
Member Author

okikio commented Aug 23, 2022

Maybe, rename client:visible="intersection-only" to client:in-view and rename this new behaviour to client:visible

@isaac-mcfadyen
Copy link

isaac-mcfadyen commented Jan 24, 2023

So one of the interesting things on the Chrome details page states this (emphasis theirs):

Visibility is much more expensive to compute than intersection. For that reason, Intersection Observer v2 is not intended to be used broadly in the way that Intersection Observer v1 is. Intersection Observer v2 is focused on combatting fraud and should be used only when the visibility information is needed and when Intersection Observer v1 functionality is therefore insufficient.

This suggests that it shouldn't be default (client:visible is often used as a quick optimization and users may use it without understanding any potential performance/battery impact). Perhaps, rather than opt-out, it should be opt-in with a flag such as client:accurate-visible or client-expensive-visible?

@steveninety
Copy link

This is great! I would mimic intersection observer V2 by placing a component 1px out of the viewport, then toggling a class to bring it back into the viewport when I wanted to hydrate it. Seems like that workaround is no longer needed :D

@natemoo-re
Copy link
Member

Thanks for the proposal, @okikio! Sorry we've taken such a long time to address this.

I'm going to close this as we're planning to move forward with Custom Client Directive in #529 which will address this use case.

@natemoo-re natemoo-re closed this Mar 23, 2023
@okikio
Copy link
Member Author

okikio commented Mar 23, 2023

Yes!!! Custom Client Directives would more than handle this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants