From 69e094c9c416f64000cebcab2cf0fde6ec3c44c4 Mon Sep 17 00:00:00 2001 From: lilnasy <69170106+lilnasy@users.noreply.github.com> Date: Fri, 9 Feb 2024 17:14:04 +0000 Subject: [PATCH 1/2] improve error messages for island hydration --- packages/astro/src/runtime/server/astro-island.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/packages/astro/src/runtime/server/astro-island.ts b/packages/astro/src/runtime/server/astro-island.ts index 58eb7f2e0af0..7741de25da1c 100644 --- a/packages/astro/src/runtime/server/astro-island.ts +++ b/packages/astro/src/runtime/server/astro-island.ts @@ -9,7 +9,7 @@ declare const Astro: { fn: () => Promise<() => void>, opts: Record, 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; 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 From 04115fd2ead4ed02c1b32079401c155c71155601 Mon Sep 17 00:00:00 2001 From: lilnasy <69170106+lilnasy@users.noreply.github.com> Date: Fri, 9 Feb 2024 17:14:15 +0000 Subject: [PATCH 2/2] add changeset --- .changeset/giant-zoos-fail.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/giant-zoos-fail.md diff --git a/.changeset/giant-zoos-fail.md b/.changeset/giant-zoos-fail.md new file mode 100644 index 000000000000..2c4188541843 --- /dev/null +++ b/.changeset/giant-zoos-fail.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Improves error messages for island hydration.