Skip to content

Commit a24d01f

Browse files
authored
Fix NextJS 500s (github#20048)
* feat: allow server to contextualize request when on a /_next/data path * add client side routing test, run lint * enable nextjs client side routing
1 parent 1b255f1 commit a24d01f

File tree

21 files changed

+75
-30
lines changed

21 files changed

+75
-30
lines changed

components/Link.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useMainContext } from 'components/context/MainContext'
44

55
const { NODE_ENV } = process.env
66

7-
const enableNextLinks = false
7+
const enableNextLinks = true
88

99
type Props = { locale?: string } & ComponentProps<'a'>
1010
export function Link(props: Props) {

components/Survey.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,9 @@ export const Survey = () => {
128128
</>
129129
)}
130130

131-
{state === ViewState.END && <p className="color-text-secondary f6" data-testid="survey-end">{t`feedback`}</p>}
131+
{state === ViewState.END && (
132+
<p className="color-text-secondary f6" data-testid="survey-end">{t`feedback`}</p>
133+
)}
132134
</form>
133135
)
134136
}

components/context/ProductSubLandingContext.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ export const getProductSubLandingContextFromRequest = (req: any): ProductSubLand
6262
includeGuides: (page.includeGuides || []).map((guide: any) => {
6363
return {
6464
...pick(guide, ['href', 'title', 'intro', 'topics']),
65-
type: guide.type || ''
65+
type: guide.type || '',
6666
}
6767
}),
6868
}

components/sublanding/ArticleCard.tsx

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@ export const ArticleCard = ({ card, typeLabel }: Props) => {
1010
<div data-testid="article-card" className="d-flex col-12 col-md-4 pr-0 pr-md-6 pr-lg-8">
1111
<a className="no-underline d-flex flex-column py-3 border-bottom" href={card.href}>
1212
<h4 className="h4 color-text-primary mb-1">{card.title}</h4>
13-
<div className="h6 text-uppercase" data-testid="article-card-type">{typeLabel}</div>
13+
<div className="h6 text-uppercase" data-testid="article-card-type">
14+
{typeLabel}
15+
</div>
1416
<p className="color-text-secondary my-3">{card.intro}</p>
1517
{card.topics.length > 0 && (
1618
<div>

components/sublanding/SubLandingHero.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export const SubLandingHero = () => {
99
const { t } = useTranslation('product_sublanding')
1010

1111
const guideItems = featuredTrack?.guides?.map((guide) => (
12-
<li className="px-2 d-flex flex-shrink-0">
12+
<li className="px-2 d-flex flex-shrink-0" key={guide.href}>
1313
<Link
1414
href={`${guide.href}?learn=${featuredTrack.trackName}`}
1515
className="d-inline-block Box p-5 color-bg-primary color-border-primary no-underline"

javascripts/wrap-code-terms.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ export default function () {
1111
const codeTerms = document.querySelectorAll('#article-contents table code')
1212
if (!codeTerms) return
1313

14-
codeTerms.forEach(node => {
14+
codeTerms.forEach((node) => {
1515
// Return early if a child node is an anchor element
16-
const hasChildAnchor = Array.from(node.childNodes).some(child => child.nodeName === 'A')
16+
const hasChildAnchor = Array.from(node.childNodes).some((child) => child.nodeName === 'A')
1717
if (hasChildAnchor) return
1818

1919
// Do the wrapping on the inner text only

middleware/context.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ module.exports = async function contextualize (req, res, next) {
3434
// e.g. searches for "req.context.page" will include results from this file
3535
req.context.currentLanguage = req.language
3636
req.context.userLanguage = req.userLanguage
37-
req.context.currentVersion = getVersionStringFromPath(req.path)
38-
req.context.currentProduct = getProductStringFromPath(req.path)
39-
req.context.currentCategory = getCategoryStringFromPath(req.path)
37+
req.context.currentVersion = getVersionStringFromPath(req.pagePath)
38+
req.context.currentProduct = getProductStringFromPath(req.pagePath)
39+
req.context.currentCategory = getCategoryStringFromPath(req.pagePath)
4040
req.context.productMap = productMap
4141
req.context.activeProducts = activeProducts
4242
req.context.allVersions = allVersions
43-
req.context.currentPathWithoutLanguage = getPathWithoutLanguage(req.path)
44-
req.context.currentPath = req.path
43+
req.context.currentPathWithoutLanguage = getPathWithoutLanguage(req.pagePath)
44+
req.context.currentPath = req.pagePath
4545
req.context.query = req.query
4646
req.context.languages = languages
4747
req.context.productNames = productNames

middleware/contextualizers/generic-toc.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ module.exports = async function genericToc (req, res, next) {
2323
const currentTocType = tocTypes[req.context.page.documentType]
2424

2525
// Find the part of the site tree that corresponds to the current path.
26-
const treePage = findPageInSiteTree(req.context.currentProductTree, req.context.currentEnglishTree, req.path)
26+
const treePage = findPageInSiteTree(req.context.currentProductTree, req.context.currentEnglishTree, req.pagePath)
2727

2828
// Conditionally run getTocItems() recursively.
2929
let isRecursive

middleware/contextualizers/graphql.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = function graphqlContext (req, res, next) {
1313
const currentVersionObj = allVersions[req.context.currentVersion]
1414
// ignore requests to non-GraphQL reference paths
1515
// and to versions that don't exist
16-
if (!req.path.includes('/graphql/') || !currentVersionObj) {
16+
if (!req.pagePath.includes('/graphql/') || !currentVersionObj) {
1717
return next()
1818
}
1919
// Get the relevant name of the GraphQL schema files for the current version

middleware/contextualizers/release-notes.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ const supported = all.filter(release => {
1212

1313
module.exports = async function releaseNotesContext (req, res, next) {
1414
// The `/release-notes` sub-path
15-
if (!(req.path.endsWith('/release-notes') || req.path.endsWith('/admin'))) return next()
15+
if (!(req.pagePath.endsWith('/release-notes') || req.pagePath.endsWith('/admin'))) return next()
1616

1717
const [requestedPlan, requestedRelease] = req.context.currentVersion.split('@')
1818
const releaseNotesPerPlan = req.context.site.data['release-notes'][requestedPlan]
@@ -28,7 +28,7 @@ module.exports = async function releaseNotesContext (req, res, next) {
2828
if (hasNumberedReleases) {
2929
const currentReleaseNotes = releaseNotesPerPlan[`${requestedRelease.replace(/\./g, '-')}`]
3030

31-
if (!currentReleaseNotes && req.path.endsWith('/release-notes')) {
31+
if (!currentReleaseNotes && req.pagePath.endsWith('/release-notes')) {
3232
// If the GHES version doesn't have any release notes, let's be helpful and redirect to `enterprise.github.com`
3333
return requestedPlan === 'enterprise-server'
3434
? res.redirect(`https://enterprise.github.com/releases/${requestedRelease}.0/notes`)

0 commit comments

Comments
 (0)