Fix _next loading to avoid error on initial routing (#48553)
This commit is contained in:
@@ -97,7 +97,7 @@ export type MainContextT = {
|
||||
href: string
|
||||
}
|
||||
currentProduct?: ProductT
|
||||
currentLayoutName: string
|
||||
currentLayoutName?: string
|
||||
isHomepageVersion: boolean
|
||||
data: DataT
|
||||
error: string
|
||||
@@ -120,7 +120,7 @@ export type MainContextT = {
|
||||
hidden: boolean
|
||||
noEarlyAccessBanner: boolean
|
||||
applicableVersions: string[]
|
||||
}
|
||||
} | null
|
||||
|
||||
enterpriseServerVersions: Array<string>
|
||||
|
||||
@@ -172,10 +172,9 @@ export const getMainContext = async (req: any, res: any): Promise<MainContextT>
|
||||
delete req.context.site.data.ui.ms
|
||||
}
|
||||
|
||||
if (!req.context.page) {
|
||||
throw new Error(`No page context (${req.url})`)
|
||||
}
|
||||
const { documentType } = req.context.page
|
||||
const { page } = req.context
|
||||
|
||||
const documentType = page ? (page.documentType as string) : undefined
|
||||
|
||||
const ui: UIStrings = {}
|
||||
addUINamespaces(req, ui, DEFAULT_UI_NAMESPACES)
|
||||
@@ -210,11 +209,24 @@ export const getMainContext = async (req: any, res: any): Promise<MainContextT>
|
||||
// as a full version string if the release candidate is set.
|
||||
const releaseCandidateVersion = releaseCandidate ? `enterprise-server@${releaseCandidate}` : null
|
||||
|
||||
return {
|
||||
const pageInfo =
|
||||
(page && {
|
||||
documentType,
|
||||
type: req.context.page.type || null,
|
||||
title: req.context.page.title,
|
||||
fullTitle: req.context.page.fullTitle || null,
|
||||
topics: req.context.page.topics || [],
|
||||
introPlainText: req.context.page?.introPlainText || null,
|
||||
applicableVersions: req.context.page?.permalinks.map((obj: any) => obj.pageVersion) || [],
|
||||
hidden: req.context.page.hidden || false,
|
||||
noEarlyAccessBanner: req.context.page.noEarlyAccessBanner || false,
|
||||
}) ||
|
||||
null
|
||||
|
||||
const props: MainContextT = {
|
||||
breadcrumbs: req.context.breadcrumbs || {},
|
||||
communityRedirect: req.context.page?.communityRedirect || {},
|
||||
currentProduct: req.context.productMap[req.context.currentProduct] || null,
|
||||
currentLayoutName: req.context.currentLayoutName,
|
||||
isHomepageVersion: req.context.page?.documentType === 'homepage',
|
||||
error: req.context.error ? req.context.error.toString() : '',
|
||||
data: {
|
||||
@@ -230,18 +242,7 @@ export const getMainContext = async (req: any, res: any): Promise<MainContextT>
|
||||
},
|
||||
currentCategory: req.context.currentCategory || '',
|
||||
currentPathWithoutLanguage: req.context.currentPathWithoutLanguage,
|
||||
relativePath: req.context.page?.relativePath,
|
||||
page: {
|
||||
documentType,
|
||||
type: req.context.page.type || null,
|
||||
title: req.context.page.title,
|
||||
fullTitle: req.context.page.fullTitle,
|
||||
topics: req.context.page.topics || [],
|
||||
introPlainText: req.context.page?.introPlainText,
|
||||
applicableVersions: req.context.page?.permalinks.map((obj: any) => obj.pageVersion) || [],
|
||||
hidden: req.context.page.hidden || false,
|
||||
noEarlyAccessBanner: req.context.page.noEarlyAccessBanner || false,
|
||||
},
|
||||
page: pageInfo,
|
||||
enterpriseServerReleases: pick(req.context.enterpriseServerReleases, [
|
||||
'isOldestReleaseDeprecated',
|
||||
'oldestSupported',
|
||||
@@ -267,6 +268,14 @@ export const getMainContext = async (req: any, res: any): Promise<MainContextT>
|
||||
status: res.statusCode,
|
||||
fullUrl: req.protocol + '://' + req.get('host') + req.originalUrl,
|
||||
}
|
||||
|
||||
if (req.context.currentLayoutName) {
|
||||
props.currentLayoutName = req.context.currentLayoutName
|
||||
}
|
||||
if (req.context.page?.relativePath) {
|
||||
props.relativePath = req.context.page.relativePath
|
||||
}
|
||||
return props
|
||||
}
|
||||
|
||||
export const MainContext = createContext<MainContextT | null>(null)
|
||||
|
||||
Reference in New Issue
Block a user