Skip to content

Commit

Permalink
refactor: remove shouldPrefetch and shouldPreload
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Jul 31, 2023
1 parent db9a23c commit ce3b75a
Showing 1 changed file with 4 additions and 9 deletions.
13 changes: 4 additions & 9 deletions src/runtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,11 @@ export interface SSRContext {
}

export interface RenderOptions {
shouldPrefetch?: (resource: ResourceMeta) => boolean
shouldPreload?: (resource: ResourceMeta) => boolean
buildAssetsURL?: (id: string) => string
manifest: Manifest
}

export interface RendererContext extends Pick<RenderOptions, 'shouldPrefetch' | 'shouldPreload'>, Required<Pick<RenderOptions, 'buildAssetsURL' | 'manifest'>> {
export interface RendererContext extends Required<RenderOptions> {
_dependencies: Record<string, ModuleDependencies>
_dependencySets: Record<string, ModuleDependencies>
_entrypoints: string[]
Expand All @@ -43,11 +41,8 @@ interface LinkAttributes {
crossorigin?: '' | null
}

export function createRendererContext ({ manifest, buildAssetsURL, shouldPrefetch, shouldPreload }: RenderOptions): RendererContext {
export function createRendererContext ({ manifest, buildAssetsURL }: RenderOptions): RendererContext {
const ctx: RendererContext = {
// User customisation of output
shouldPrefetch,
shouldPreload,
// Manifest
buildAssetsURL: buildAssetsURL || withLeadingSlash,
manifest: undefined!,
Expand Down Expand Up @@ -115,7 +110,7 @@ export function getModuleDependencies (id: string, rendererContext: RendererCont
const filteredPreload: ModuleDependencies['preload'] = {}
for (const id in dependencies.preload) {
const dep = dependencies.preload[id]
if (rendererContext.shouldPreload ? rendererContext.shouldPreload(dep) : dep.preload) {
if (dep.preload) {
filteredPreload[id] = dep
}
}
Expand Down Expand Up @@ -155,7 +150,7 @@ export function getAllDependencies (ids: Set<string>, rendererContext: RendererC
const filteredPrefetch: ModuleDependencies['prefetch'] = {}
for (const id in allDeps.prefetch) {
const dep = allDeps.prefetch[id]
if (rendererContext.shouldPrefetch ? rendererContext.shouldPrefetch(dep) : dep.prefetch) {
if (dep.prefetch) {
filteredPrefetch[id] = dep
}
}
Expand Down

0 comments on commit ce3b75a

Please sign in to comment.