Skip to content

Commit 6bc50f7

Browse files
authored
fix: filter hidden pages from the currentProductTree (SidebarProduct) (github#20404)
* fix some async test things * allow eslint to parse top-level awaits * fix: filter out hidden pages closer to SidebarProduct usage
1 parent 2d99aee commit 6bc50f7

File tree

9 files changed

+34
-21
lines changed

9 files changed

+34
-21
lines changed

.babelrc

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"presets": ["next/babel"],
3-
"plugins": [["styled-components", { "ssr": true }]]
3+
"plugins": [["styled-components", { "ssr": true }], "@babel/plugin-syntax-top-level-await"]
44
}

.eslintrc.js

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ module.exports = {
1111
ecmaVersion: 11,
1212
requireConfigFile: 'false',
1313
babelOptions: { configFile: './.babelrc' },
14+
sourceType: 'module',
1415
},
1516
rules: {
1617
'import/no-extraneous-dependencies': ['error', { packageDir: '.' }],

components/context/MainContext.tsx

+7-2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import pick from 'lodash/pick'
33

44
import type { BreadcrumbT } from 'components/Breadcrumbs'
55
import type { FeatureFlags } from 'components/hooks/useFeatureFlags'
6+
import { ExcludesNull } from 'components/lib/ExcludesNull'
67

78
type ProductT = {
89
external: boolean
@@ -186,7 +187,11 @@ export const getMainContextFromRequest = (req: any): MainContextT => {
186187
}
187188

188189
// only pull things we need from the product tree, and make sure there are default values instead of `undefined`
189-
const getCurrentProductTree = (input: any): ProductTreeNode => {
190+
const getCurrentProductTree = (input: any): ProductTreeNode | null => {
191+
if (input.page.hidden) {
192+
return null
193+
}
194+
190195
return {
191196
href: input.href,
192197
renderedShortTitle: input.renderedShortTitle || '',
@@ -197,7 +202,7 @@ const getCurrentProductTree = (input: any): ProductTreeNode => {
197202
title: input.page.title,
198203
shortTitle: input.page.shortTitle || '',
199204
},
200-
childPages: (input.childPages || []).map(getCurrentProductTree),
205+
childPages: (input.childPages || []).map(getCurrentProductTree).filter(ExcludesNull),
201206
}
202207
}
203208

lib/page-data.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ export async function versionPages(obj, version, langCode, site) {
102102

103103
const versionedChildPages = await Promise.all(
104104
obj.childPages
105-
// Drop child pages that do not apply to the current version.
105+
// Drop child pages that do not apply to the current version
106106
.filter((childPage) => childPage.page.applicableVersions.includes(version))
107107
// Version the child pages recursively.
108108
.map((childPage) => versionPages(Object.assign({}, childPage), version, langCode, site))

middleware/next.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ import next from 'next'
33
const { NODE_ENV } = process.env
44
const isDevelopment = NODE_ENV === 'development'
55

6-
const nextApp = next({ dev: isDevelopment })
6+
export const nextApp = next({ dev: isDevelopment })
77
export const nextHandleRequest = nextApp.getRequestHandler()
8-
nextApp.prepare()
8+
await nextApp.prepare()
99

1010
function renderPageWithNext(req, res, next) {
1111
if (req.path.startsWith('/_next') && !req.path.startsWith('/_next/data')) {

package-lock.json

+15-8
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@
9595
"@actions/github": "^5.0.0",
9696
"@babel/core": "^7.14.3",
9797
"@babel/eslint-parser": "^7.14.3",
98+
"@babel/plugin-syntax-top-level-await": "^7.14.5",
9899
"@babel/plugin-transform-runtime": "^7.14.3",
99100
"@babel/preset-env": "^7.14.2",
100101
"@graphql-inspector/core": "^2.5.0",

tests/helpers/supertest.js

-2
Original file line numberDiff line numberDiff line change
@@ -47,5 +47,3 @@ export const getJSON = (helpers.getJSON = async function (route) {
4747
const res = await helpers.get(route, { followRedirects: true })
4848
return JSON.parse(res.text)
4949
})
50-
51-
export default helpers

tests/unit/early-access.js

+6-5
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,26 @@
11
import { jest } from '@jest/globals'
2-
import xFs from 'fs'
2+
import { stat } from 'fs/promises'
33
import path from 'path'
44
import { testViaActionsOnly } from '../helpers/conditional-runs.js'
55
import { getDOM } from '../helpers/supertest.js'
66
import got from 'got'
7-
const fs = xFs.promises
7+
8+
jest.useFakeTimers()
89

910
describe('cloning early-access', () => {
1011
testViaActionsOnly('the content directory exists', async () => {
1112
const eaDir = path.join(process.cwd(), 'content/early-access')
12-
expect(await fs.stat(eaDir)).toBeTruthy()
13+
expect(await stat(eaDir)).toBeTruthy()
1314
})
1415

1516
testViaActionsOnly('the data directory exists', async () => {
1617
const eaDir = path.join(process.cwd(), 'data/early-access')
17-
expect(await fs.stat(eaDir)).toBeTruthy()
18+
expect(await stat(eaDir)).toBeTruthy()
1819
})
1920

2021
testViaActionsOnly('the assets/images directory exists', async () => {
2122
const eaDir = path.join(process.cwd(), 'assets/images/early-access')
22-
expect(await fs.stat(eaDir)).toBeTruthy()
23+
expect(await stat(eaDir)).toBeTruthy()
2324
})
2425
})
2526

0 commit comments

Comments
 (0)