From 89a1135b21229dab6b325850049c7bbda051852c Mon Sep 17 00:00:00 2001 From: Markus Oberlehner Date: Fri, 19 Feb 2021 11:57:43 +0100 Subject: [PATCH] feat: static component handling for lazy hydration This adds the necessary API for vue-lazy-hydration to register static components. --- src/renderer.ts | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/src/renderer.ts b/src/renderer.ts index 220cffb..08712be 100644 --- a/src/renderer.ts +++ b/src/renderer.ts @@ -31,7 +31,9 @@ export type SSRContext = { head?: string, styles?: string, _mappedFiles?: Array, + _mappedStaticFiles?: Array, _registeredComponents?: Set, + _staticComponents?: Set, } export type RenderContext = { @@ -115,7 +117,18 @@ export function renderPreloadLinks (ssrContext: SSRContext, renderContext: Rende } export function renderPrefetchLinks (ssrContext: SSRContext, renderContext: RenderContext): string { - const shouldPrefetch = renderContext.shouldPrefetch + const shouldPrefetch = (fileWithoutQuery: string, asType: string) => { + const isStaticFile = Boolean( + ssrContext._mappedStaticFiles && + ssrContext._mappedStaticFiles.find(f => f.fileWithoutQuery === fileWithoutQuery) + ) + if (isStaticFile) { + return false + } + + const contextShouldPrefetch = renderContext.shouldPrefetch || (() => true) + return contextShouldPrefetch(fileWithoutQuery, asType) + } if (renderContext.prefetchFiles) { const usedAsyncFiles = getUsedAsyncFiles(ssrContext, renderContext) const alreadyRendered = (file: string) => { @@ -171,6 +184,7 @@ export function createRenderer (createApp: any, renderOptions: RenderOptions & { return { async renderToString (ssrContext: SSRContext) { ssrContext._registeredComponents = ssrContext._registeredComponents || new Set() + ssrContext._staticComponents = ssrContext._staticComponents || new Set() const _createApp = await Promise.resolve(createApp).then(r => r.default || r) const app = await _createApp(ssrContext)