From 410cfe306c9ba97027eadb765e240b8953a87132 Mon Sep 17 00:00:00 2001 From: Matthew Phillips Date: Fri, 7 Oct 2022 16:09:53 -0400 Subject: [PATCH] Keep track of error so we can rethrow later --- packages/astro/src/runtime/server/jsx.ts | 36 ++++++++++++++---------- 1 file changed, 21 insertions(+), 15 deletions(-) diff --git a/packages/astro/src/runtime/server/jsx.ts b/packages/astro/src/runtime/server/jsx.ts index 19c6b898e..5ae731a2b 100644 --- a/packages/astro/src/runtime/server/jsx.ts +++ b/packages/astro/src/runtime/server/jsx.ts @@ -15,7 +15,7 @@ import type { ComponentIterable } from './render/component'; const ClientOnlyPlaceholder = 'astro-client-only'; -const skipAstroJSXCheck = new WeakSet(); +const skipAstroJSXCheck = new WeakMap<() => any, null | Error>(); let originalConsoleError: any; let consoleFilterRefs = 0; @@ -68,26 +68,32 @@ Did you forget to import the component or is it possible there is a typo?`); if (vnode.type) { 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']) { const output = await vnode.type(vnode.props ?? {}); return await renderJSX(result, output); } - if (typeof vnode.type === 'function' && !skipAstroJSXCheck.has(vnode.type)) { - useConsoleFilter(); - try { - const output = await vnode.type(vnode.props ?? {}); - if (output && output[AstroJSX]) { - return await renderJSX(result, output); - } else if (!output) { - return await renderJSX(result, output); + if (typeof vnode.type === 'function') { + if(skipAstroJSXCheck.has(vnode.type)) { + const error = skipAstroJSXCheck.get(vnode.type); + if(error) { + throw error; + } + } else { + useConsoleFilter(); + try { + const output = await vnode.type(vnode.props ?? {}); + if (output && output[AstroJSX]) { + return await renderJSX(result, output); + } else if (!output) { + return await renderJSX(result, output); + } + } catch (e: any) { + skipAstroJSXCheck.set(vnode.type, e); + } finally { + finishUsingConsoleFilter(); } - } catch (e) { - skipAstroJSXCheck.add(vnode.type); - throw e; - } finally { - finishUsingConsoleFilter(); } }