Skip to content

WIP: Add API for making it possible to block loading of SSR only static content components with vue-lazy-hydration #8

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/renderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@ export type SSRContext = {
head?: string,
styles?: string,
_mappedFiles?: Array<Resource>,
_mappedStaticFiles?: Array<Resource>,
_registeredComponents?: Set<any>,
_staticComponents?: Set<any>,
}

export type RenderContext = {
Expand Down Expand Up @@ -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) => {
Expand Down Expand Up @@ -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)
Expand Down