Skip to content

Commit

Permalink
qol(islands): improve hydration errors (#10075)
Browse files Browse the repository at this point in the history
* improve error messages for island hydration

* add changeset

---------

Co-authored-by: Nate Moore <natemoo-re@users.noreply.github.com>
  • Loading branch information
lilnasy and natemoo-re authored Feb 13, 2024
1 parent 73bd900 commit 71273ed
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/giant-zoos-fail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"astro": patch
---

Improves error messages for island hydration.
12 changes: 8 additions & 4 deletions packages/astro/src/runtime/server/astro-island.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ declare const Astro: {
fn: () => Promise<() => void>,
opts: Record<string, any>,
root: HTMLElement
) => void;
) => unknown;
};

{
Expand Down Expand Up @@ -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([
Expand 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
Expand Down

0 comments on commit 71273ed

Please sign in to comment.