-
Notifications
You must be signed in to change notification settings - Fork 26.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: cleanup page infos implementation
- Loading branch information
Showing
4 changed files
with
141 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import type { ServerRuntime } from '../../types' | ||
|
||
export interface PageInfo { | ||
isHybridAmp?: boolean | ||
size: number | ||
totalSize: number | ||
isStatic: boolean | ||
isSSG: boolean | ||
isPPR: boolean | ||
ssgPageRoutes: string[] | null | ||
initialRevalidateSeconds: number | false | ||
pageDuration: number | undefined | ||
ssgPageDurations: number[] | undefined | ||
runtime: ServerRuntime | ||
hasEmptyPrelude?: boolean | ||
hasPostponed?: boolean | ||
isDynamicAppRoute?: boolean | ||
} | ||
|
||
/** | ||
* Updates the page info for a given page. If the page info doesn't exist, it | ||
* will throw an error. | ||
* | ||
* @param pageInfos the page infos map | ||
* @param page the page to update | ||
* @param update the update to apply | ||
* @returns the updated page info | ||
*/ | ||
export function patchPageInfos( | ||
pageInfos: Map<string, PageInfo>, | ||
page: string, | ||
update: Partial<PageInfo> | ||
): PageInfo { | ||
const pageInfo = pageInfos.get(page) | ||
if (!pageInfo) { | ||
throw new Error(`Invariant: Expected page "${page}" to exist`) | ||
} | ||
|
||
// Patch the page info with the update. | ||
Object.assign(pageInfo, update) | ||
|
||
return pageInfo | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters