feat: add logging for when hydrate's JSON parse fails (#7887)
Co-authored-by: Emanuele Stoppa <my.burning@gmail.com> Co-authored-by: Bjorn Lu <bjornlu.dev@gmail.com>
This commit is contained in:
parent
fb833214e4
commit
5c5da8d2fb
2 changed files with 28 additions and 3 deletions
5
.changeset/gorgeous-starfishes-serve.md
Normal file
5
.changeset/gorgeous-starfishes-serve.md
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
'astro': patch
|
||||||
|
---
|
||||||
|
|
||||||
|
Add logging for when JSON.parse fails within hydrate func
|
|
@ -127,9 +127,29 @@ declare const Astro: {
|
||||||
if (!closest?.isSameNode(this)) continue;
|
if (!closest?.isSameNode(this)) continue;
|
||||||
slots[slot.getAttribute('name') || 'default'] = slot.innerHTML;
|
slots[slot.getAttribute('name') || 'default'] = slot.innerHTML;
|
||||||
}
|
}
|
||||||
const props = this.hasAttribute('props')
|
|
||||||
? JSON.parse(this.getAttribute('props')!, reviver)
|
let props: Record<string, unknown>;
|
||||||
: {};
|
|
||||||
|
try {
|
||||||
|
props = this.hasAttribute('props')
|
||||||
|
? JSON.parse(this.getAttribute('props')!, reviver)
|
||||||
|
: {};
|
||||||
|
} catch (e) {
|
||||||
|
let componentName: string = this.getAttribute('component-url') || '<unknown>';
|
||||||
|
const componentExport = this.getAttribute('component-export');
|
||||||
|
|
||||||
|
if (componentExport) {
|
||||||
|
componentName += ` (export ${componentExport})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-console
|
||||||
|
console.error(
|
||||||
|
`[hydrate] Error parsing props for component ${componentName}`,
|
||||||
|
this.getAttribute('props'),
|
||||||
|
e
|
||||||
|
);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
await this.hydrator(this)(this.Component, props, slots, {
|
await this.hydrator(this)(this.Component, props, slots, {
|
||||||
client: this.getAttribute('client'),
|
client: this.getAttribute('client'),
|
||||||
});
|
});
|
||||||
|
|
Loading…
Reference in a new issue