Keep track of error so we can rethrow later

This commit is contained in:
Matthew Phillips 2022-10-07 16:09:53 -04:00
parent f67f18af7a
commit 410cfe306c

View file

@ -15,7 +15,7 @@ import type { ComponentIterable } from './render/component';
const ClientOnlyPlaceholder = 'astro-client-only'; const ClientOnlyPlaceholder = 'astro-client-only';
const skipAstroJSXCheck = new WeakSet(); const skipAstroJSXCheck = new WeakMap<() => any, null | Error>();
let originalConsoleError: any; let originalConsoleError: any;
let consoleFilterRefs = 0; let consoleFilterRefs = 0;
@ -68,13 +68,19 @@ Did you forget to import the component or is it possible there is a typo?`);
if (vnode.type) { if (vnode.type) {
if (typeof vnode.type === 'function' && (vnode.type as any)['astro:renderer']) { if (typeof vnode.type === 'function' && (vnode.type as any)['astro:renderer']) {
skipAstroJSXCheck.add(vnode.type); skipAstroJSXCheck.set(vnode.type, null);
} }
if (typeof vnode.type === 'function' && vnode.props['server:root']) { if (typeof vnode.type === 'function' && vnode.props['server:root']) {
const output = await vnode.type(vnode.props ?? {}); const output = await vnode.type(vnode.props ?? {});
return await renderJSX(result, output); return await renderJSX(result, output);
} }
if (typeof vnode.type === 'function' && !skipAstroJSXCheck.has(vnode.type)) { if (typeof vnode.type === 'function') {
if(skipAstroJSXCheck.has(vnode.type)) {
const error = skipAstroJSXCheck.get(vnode.type);
if(error) {
throw error;
}
} else {
useConsoleFilter(); useConsoleFilter();
try { try {
const output = await vnode.type(vnode.props ?? {}); const output = await vnode.type(vnode.props ?? {});
@ -83,13 +89,13 @@ Did you forget to import the component or is it possible there is a typo?`);
} else if (!output) { } else if (!output) {
return await renderJSX(result, output); return await renderJSX(result, output);
} }
} catch (e) { } catch (e: any) {
skipAstroJSXCheck.add(vnode.type); skipAstroJSXCheck.set(vnode.type, e);
throw e;
} finally { } finally {
finishUsingConsoleFilter(); finishUsingConsoleFilter();
} }
} }
}
const { children = null, ...props } = vnode.props ?? {}; const { children = null, ...props } = vnode.props ?? {};
const _slots: Record<string, any> = { const _slots: Record<string, any> = {