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:
parent
73bd900754
commit
71273edbb4
2 changed files with 13 additions and 4 deletions
5
.changeset/giant-zoos-fail.md
Normal file
5
.changeset/giant-zoos-fail.md
Normal file
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
"astro": patch
|
||||
---
|
||||
|
||||
Improves error messages for island hydration.
|
|
@ -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
|
||||
|
|
Loading…
Add table
Reference in a new issue