diff --git a/pages/[versionId]/[productId]/index.tsx b/pages/[versionId]/[productId]/index.tsx
index fa563d660eb0..dd0393ac3552 100644
--- a/pages/[versionId]/[productId]/index.tsx
+++ b/pages/[versionId]/[productId]/index.tsx
@@ -45,10 +45,10 @@ function initiateArticleScripts() {
type Props = {
mainContext: MainContextT
- productLandingContext: ProductLandingContextT
- productGuidesContext: ProductGuidesContextT
- tocLandingContext: TocLandingContextT
- articleContext: ArticleContextT
+ productLandingContext?: ProductLandingContextT
+ productGuidesContext?: ProductGuidesContextT
+ tocLandingContext?: TocLandingContextT
+ articleContext?: ArticleContextT
}
const GlobalPage = ({
mainContext,
@@ -57,7 +57,6 @@ const GlobalPage = ({
tocLandingContext,
articleContext,
}: Props) => {
- const { currentLayoutName, relativePath } = mainContext
const router = useRouter()
useEffect(() => {
@@ -70,30 +69,32 @@ const GlobalPage = ({
}, [router.events])
let content
- if (currentLayoutName === 'product-landing') {
+ if (productLandingContext) {
content = (
)
- } else if (currentLayoutName === 'product-guides') {
+ } else if (productGuidesContext) {
content = (
)
- } else if (relativePath?.endsWith('index.md')) {
+ } else if (tocLandingContext) {
content = (
)
- } else {
+ } else if (articleContext) {
content = (
)
+ } else {
+ throw new Error('No context provided to page')
}
return {content}
@@ -105,13 +106,23 @@ export const getServerSideProps: GetServerSideProps = async (context) =>
const req = context.req as any
const res = context.res as any
+ const props: Props = {
+ mainContext: getMainContext(req, res),
+ }
+ const { currentLayoutName, relativePath } = props.mainContext
+
+ // This looks a little funky, but it's so we only send one context's data to the client
+ if (currentLayoutName === 'product-landing') {
+ props.productLandingContext = getProductLandingContextFromRequest(req)
+ } else if (currentLayoutName === 'product-guides') {
+ props.productGuidesContext = getProductGuidesContextFromRequest(req)
+ } else if (relativePath?.endsWith('index.md')) {
+ props.tocLandingContext = getTocLandingContextFromRequest(req)
+ } else {
+ props.articleContext = getArticleContextFromRequest(req)
+ }
+
return {
- props: {
- mainContext: getMainContext(req, res),
- productLandingContext: getProductLandingContextFromRequest(req),
- productGuidesContext: getProductGuidesContextFromRequest(req),
- tocLandingContext: getTocLandingContextFromRequest(req),
- articleContext: getArticleContextFromRequest(req),
- },
+ props,
}
}