Skip to content

Commit 4689b49

Browse files
authored
Merge pull request #15369 from github/repo-sync
repo sync
2 parents b0379c5 + 2c82d14 commit 4689b49

File tree

1 file changed

+27
-16
lines changed

1 file changed

+27
-16
lines changed

pages/[versionId]/[productId]/index.tsx

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -45,10 +45,10 @@ function initiateArticleScripts() {
4545

4646
type Props = {
4747
mainContext: MainContextT
48-
productLandingContext: ProductLandingContextT
49-
productGuidesContext: ProductGuidesContextT
50-
tocLandingContext: TocLandingContextT
51-
articleContext: ArticleContextT
48+
productLandingContext?: ProductLandingContextT
49+
productGuidesContext?: ProductGuidesContextT
50+
tocLandingContext?: TocLandingContextT
51+
articleContext?: ArticleContextT
5252
}
5353
const GlobalPage = ({
5454
mainContext,
@@ -57,7 +57,6 @@ const GlobalPage = ({
5757
tocLandingContext,
5858
articleContext,
5959
}: Props) => {
60-
const { currentLayoutName, relativePath } = mainContext
6160
const router = useRouter()
6261

6362
useEffect(() => {
@@ -70,30 +69,32 @@ const GlobalPage = ({
7069
}, [router.events])
7170

7271
let content
73-
if (currentLayoutName === 'product-landing') {
72+
if (productLandingContext) {
7473
content = (
7574
<ProductLandingContext.Provider value={productLandingContext}>
7675
<ProductLanding />
7776
</ProductLandingContext.Provider>
7877
)
79-
} else if (currentLayoutName === 'product-guides') {
78+
} else if (productGuidesContext) {
8079
content = (
8180
<ProductGuidesContext.Provider value={productGuidesContext}>
8281
<ProductGuides />
8382
</ProductGuidesContext.Provider>
8483
)
85-
} else if (relativePath?.endsWith('index.md')) {
84+
} else if (tocLandingContext) {
8685
content = (
8786
<TocLandingContext.Provider value={tocLandingContext}>
8887
<TocLanding />
8988
</TocLandingContext.Provider>
9089
)
91-
} else {
90+
} else if (articleContext) {
9291
content = (
9392
<ArticleContext.Provider value={articleContext}>
9493
<ArticlePage />
9594
</ArticleContext.Provider>
9695
)
96+
} else {
97+
throw new Error('No context provided to page')
9798
}
9899

99100
return <MainContext.Provider value={mainContext}>{content}</MainContext.Provider>
@@ -105,13 +106,23 @@ export const getServerSideProps: GetServerSideProps<Props> = async (context) =>
105106
const req = context.req as any
106107
const res = context.res as any
107108

109+
const props: Props = {
110+
mainContext: getMainContext(req, res),
111+
}
112+
const { currentLayoutName, relativePath } = props.mainContext
113+
114+
// This looks a little funky, but it's so we only send one context's data to the client
115+
if (currentLayoutName === 'product-landing') {
116+
props.productLandingContext = getProductLandingContextFromRequest(req)
117+
} else if (currentLayoutName === 'product-guides') {
118+
props.productGuidesContext = getProductGuidesContextFromRequest(req)
119+
} else if (relativePath?.endsWith('index.md')) {
120+
props.tocLandingContext = getTocLandingContextFromRequest(req)
121+
} else {
122+
props.articleContext = getArticleContextFromRequest(req)
123+
}
124+
108125
return {
109-
props: {
110-
mainContext: getMainContext(req, res),
111-
productLandingContext: getProductLandingContextFromRequest(req),
112-
productGuidesContext: getProductGuidesContextFromRequest(req),
113-
tocLandingContext: getTocLandingContextFromRequest(req),
114-
articleContext: getArticleContextFromRequest(req),
115-
},
126+
props,
116127
}
117128
}

0 commit comments

Comments
 (0)