0
Fork 0
mirror of https://github.com/withastro/astro.git synced 2025-02-17 22:44:24 -05:00

qol(islands): improve hydration errors (#10075)

* improve error messages for island hydration

* add changeset

---------

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
This commit is contained in:
Arsh 2024-02-13 10:28:28 -07:00 committed by GitHub
parent 73bd900754
commit 71273edbb4
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 13 additions and 4 deletions

View file

@ -0,0 +1,5 @@
---
"astro": patch
---
Improves error messages for island hydration.

View file

@ -9,7 +9,7 @@ declare const Astro: {
fn: () => Promise<() => void>,
opts: Record<string, any>,
root: HTMLElement
) => void;
) => unknown;
};
{
@ -93,14 +93,15 @@ declare const Astro: {
}
this.start();
}
start() {
async start() {
const opts = JSON.parse(this.getAttribute('opts')!) as Record<string, any>;
const directive = this.getAttribute('client') as directiveAstroKeys;
if (Astro[directive] === undefined) {
window.addEventListener(`astro:${directive}`, () => this.start(), { once: true });
return;
}
Astro[directive]!(
try {
await Astro[directive]!(
async () => {
const rendererUrl = this.getAttribute('renderer-url');
const [componentModule, { default: hydrator }] = await Promise.all([
@ -121,7 +122,10 @@ declare const Astro: {
},
opts,
this
);
)
} catch (e) {
console.error(`[astro-island] Error hydrating ${this.getAttribute('component-url')}`, e);
}
}
hydrate = async () => {
// The client directive needs to load the hydrator code before it can hydrate