Skip to content
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

Feat: Promise.all homepage and global Promises #2471

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions packages/core/src/components/cms/GlobalSections.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const getGlobalSectionsData = async (
const page = cmsData[GLOBAL_SECTIONS_CONTENT_TYPE][0]

if (page) {
const pageData = await getPage<PageContentType>({
const pageData = getPage<PageContentType>({
contentType: GLOBAL_SECTIONS_CONTENT_TYPE,
documentId: page.documentId,
versionId: page.versionId,
Expand All @@ -66,11 +66,11 @@ export const getGlobalSectionsData = async (
}
}

const { sections } = await getPage<PageContentType>({
const pageData = getPage<PageContentType>({
...(previewData?.contentType === GLOBAL_SECTIONS_CONTENT_TYPE &&
previewData),
contentType: GLOBAL_SECTIONS_CONTENT_TYPE,
})

return { sections }
return pageData
}
20 changes: 16 additions & 4 deletions packages/core/src/pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -100,31 +100,43 @@ export const getStaticProps: GetStaticProps<
Record<string, string>,
Locator
> = async ({ previewData }) => {
const serverData = await getDynamicContent({ pageType: 'home' })
const globalSections = await getGlobalSectionsData(previewData)
const globalSectionsPromise = getGlobalSectionsData(previewData)
const serverDataPromise = getDynamicContent({ pageType: 'home' })

if (storeConfig.cms.data) {
const cmsData = JSON.parse(storeConfig.cms.data)
const page = cmsData['home'][0]

if (page) {
const pageData = await getPage<PageContentType>({
const pageDataPromise = getPage<PageContentType>({
contentType: 'home',
documentId: page.documentId,
versionId: page.versionId,
})

const [pageData, globalSections, serverData] = await Promise.all([
pageDataPromise,
globalSectionsPromise,
serverDataPromise,
])

return {
props: { page: pageData, globalSections, serverData },
}
}
}

const page = await getPage<PageContentType>({
const pagePromise = getPage<PageContentType>({
...(previewData?.contentType === 'home' && previewData),
contentType: 'home',
})

const [page, globalSections, serverData] = await Promise.all([
pagePromise,
globalSectionsPromise,
serverDataPromise,
])

return {
props: { page, globalSections, serverData },
}
Expand Down
Loading