-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
feat: support setting rootMargin for client:visible
#9363
Conversation
This support adding optional `rootMargin` to the `IntersectionObserver` options. This gives the developer the optional choice to hydrate a bit before the astro-island enters the viewport.
🦋 Changeset detectedLatest commit: afd5eb3 The changes in this PR will be included in the next version bump. Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Heres a suggestion for documentation of this feature:
|
I think the action fails because of it's missing a GH token when running from a fork |
Would it be possible to implement this as a custom client directive? https://docs.astro.build/en/reference/directives-reference/#custom-client-directives |
Absolutely. It's just that this is going to be useful for everyone using this directive. Some/most of the time it's better to have done the loading/hydration before the component comes into view. |
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.
I like this change! A small quality of life improvement that doesn't impact maintainability, I think we should do it.
We also need to update the docs at https://docs.astro.build/en/reference/directives-reference/#clientvisible |
Documentation for optional root margin on client visible. This documents this pr withastro/astro#9363
I have opened a PR for the docs now 🎈 |
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.
Thanks for this lovely addition to the client directive, @forberg ! I think people will really like this!
I've just left some thoughts on the changeset message. See what you think!
Co-authored-by: Sarah Rainsberger <sarah@rainsberger.ca>
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.
Docs is happy!
This reverts commit 769826e.
…ring (#9596) * Revert "feat: support setting rootMargin for `client:visible` (#9363)" This reverts commit 769826e. * feat: update extended `client:visible` to use an object instead of a string * Apply suggestions from code review Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com> * test: add a test * nit: comment * test: write the test some other way to try to convince playwright --------- Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
Changes
This support adding optional
rootMargin
to theIntersectionObserver
options.This gives the developer the optional choice to hydrate a bit before the astro-island enters the viewport.
<Component client:visible="200px" />
This is very useful for devices on slower connections, components with some
useEffect
changing DOM structure, to avoid CLS.Testing
Tested by scrolling and seeing the hydration starts
200px
before the island appears inscreen.Docs