-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: update extended client:visible to use an object instead of a st…
…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 <[email protected]> * test: add a test * nit: comment * test: write the test some other way to try to convince playwright --------- Co-authored-by: Nate Moore <[email protected]>
- Loading branch information
1 parent
da307e4
commit fbc2697
Showing
9 changed files
with
65 additions
and
22 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
--- | ||
"astro": minor | ||
--- | ||
|
||
Adds the ability to set a [`rootMargin`](https://developer.mozilla.org/en-US/docs/Web/API/IntersectionObserver/rootMargin) setting when using the `client:visible` directive. This allows a component to be hydrated when it is _near_ the viewport, rather than hydrated when it has _entered_ the viewport. | ||
|
||
```astro | ||
<!-- Load component when it's within 200px away from entering the viewport --> | ||
<Component client:visible={{ rootMargin: "200px" }} /> | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
packages/astro/e2e/fixtures/custom-client-directives/client-options.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
// Hydrate directly and write the passed options to the DOM | ||
export default async (load, options) => { | ||
const hydrate = await load(); | ||
|
||
const div = document.createElement('div'); | ||
div.id = 'options'; | ||
div.textContent = `Passed options are: ${JSON.stringify(options.value)}`; | ||
document.body.appendChild(div); | ||
await hydrate(); | ||
} |
5 changes: 3 additions & 2 deletions
5
packages/astro/e2e/fixtures/custom-client-directives/src/client-directives-types.d.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,10 @@ | ||
declare module 'astro' { | ||
interface AstroClientDirectives { | ||
'client:click'?: boolean | ||
'client:password'?: string | ||
'client:password'?: string | ||
'client:options'?: { message: string } | ||
} | ||
} | ||
|
||
// Make d.ts a module to similate common packaging setups where the entry `index.d.ts` would augment the types | ||
export {} | ||
export { } |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters