Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

qol(islands): improve hydration errors #10075

Merged
merged 3 commits into from
Feb 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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]!(
ematipico marked this conversation as resolved.
Show resolved Hide resolved
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
Loading