From 7af4f77182b3838fac07acc994ec3f846570a02d Mon Sep 17 00:00:00 2001 From: Matt Garrett Date: Mon, 19 Aug 2024 18:46:46 -0700 Subject: [PATCH] fix(server-renderer): undo async renderComponentVNode, preserve fast path --- packages/server-renderer/src/render.ts | 37 ++++++++++++++++---------- 1 file changed, 23 insertions(+), 14 deletions(-) diff --git a/packages/server-renderer/src/render.ts b/packages/server-renderer/src/render.ts index 5a3cacdbb00..5f105b745e0 100644 --- a/packages/server-renderer/src/render.ts +++ b/packages/server-renderer/src/render.ts @@ -86,26 +86,35 @@ export function createBuffer() { } } -export async function renderComponentVNode( +export function renderComponentVNode( vnode: VNode, parentComponent: ComponentInternalInstance | null = null, slotScopeId?: string, -): Promise { +): SSRBuffer | Promise { const instance = createComponentInstance(vnode, parentComponent, null) - await setupComponent(instance, true /* isSSR */) - const prefetches = instance.sp - if (prefetches) { - /* LifecycleHooks.SERVER_PREFETCH */ - try { - await Promise.all( - prefetches.map(prefetch => prefetch.call(instance.proxy)), - ) - } catch (error) { - // NOOP + const res = setupComponent(instance, true /* isSSR */) + const hasAsyncSetup = isPromise(res) + let prefetches = instance.sp /* LifecycleHooks.SERVER_PREFETCH */ + if (hasAsyncSetup || prefetches) { + let p: Promise = ( + hasAsyncSetup + ? // instance.sp may be null until an async setup resolves, so evaluate it here + (res as Promise).then(() => (prefetches = instance.sp)) + : Promise.resolve() + ) + .then(() => { + if (prefetches) { + return Promise.all( + prefetches.map(prefetch => prefetch.call(instance.proxy)), + ) + } + }) // Note: error display is already done by the wrapped lifecycle hook function. - } + .catch(NOOP) + return p.then(() => renderComponentSubTree(instance, slotScopeId)) + } else { + return renderComponentSubTree(instance, slotScopeId) } - return renderComponentSubTree(instance, slotScopeId) } function renderComponentSubTree(