feat: support setting rootMargin for client:visible#9363
feat: support setting rootMargin for client:visible#9363ematipico merged 8 commits intowithastro:mainfrom
client:visible#9363Conversation
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. |
matthewp
left a comment
There was a problem hiding this comment.
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 🎈 |
sarah11918
left a comment
There was a problem hiding this comment.
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>
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
rootMarginto theIntersectionObserveroptions.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
useEffectchanging DOM structure, to avoid CLS.Testing
Tested by scrolling and seeing the hydration starts
200pxbefore the island appears inscreen.Docs