Skip to content

Commit

Permalink
Revert "feat: support setting rootMargin for client:visible (#9363)"
Browse files Browse the repository at this point in the history
This reverts commit 769826e.
  • Loading branch information
Princesseuh committed Jan 3, 2024
1 parent da307e4 commit e828cd0
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 19 deletions.
10 changes: 0 additions & 10 deletions .changeset/stupid-peas-juggle.md

This file was deleted.

6 changes: 3 additions & 3 deletions packages/astro/src/@types/astro.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,16 @@ export type {
export type { RemotePattern } from '../assets/utils/remotePattern.js';
export type { SSRManifest } from '../core/app/types.js';
export type {
AstroCookies,
AstroCookieSetOptions,
AstroCookieGetOptions,
AstroCookieSetOptions,
AstroCookies,
} from '../core/cookies/index.js';

export interface AstroBuiltinProps {
'client:load'?: boolean;
'client:idle'?: boolean;
'client:media'?: string;
'client:visible'?: string | boolean;
'client:visible'?: boolean;
'client:only'?: boolean | string;
}

Expand Down
8 changes: 2 additions & 6 deletions packages/astro/src/runtime/client/visible.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ import type { ClientDirective } from '../../@types/astro.js';
* We target the children because `astro-island` is set to `display: contents`
* which doesn't work with IntersectionObserver
*/
const visibleDirective: ClientDirective = (load, options, el) => {
const visibleDirective: ClientDirective = (load, _options, el) => {
const cb = async () => {
const hydrate = await load();
await hydrate();
};

const ioOptions = {
rootMargin: typeof options.value === 'string' ? options.value : undefined,
};

const io = new IntersectionObserver((entries) => {
for (const entry of entries) {
if (!entry.isIntersecting) continue;
Expand All @@ -23,7 +19,7 @@ const visibleDirective: ClientDirective = (load, options, el) => {
cb();
break; // break loop on first match
}
}, ioOptions);
});

for (const child of el.children) {
io.observe(child);
Expand Down

0 comments on commit e828cd0

Please sign in to comment.