Skip to content

Commit d7505a8

Browse files
authored
Merge pull request github#18132 from github/repo-sync
repo sync
2 parents d7a7b56 + 791bab0 commit d7505a8

23 files changed

+700
-572
lines changed

.github/workflows/check-broken-links-github-github.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,11 @@ jobs:
5757
env:
5858
NODE_ENV: production
5959
PORT: 4000
60+
# Overload protection is on by default (when NODE_ENV==production)
61+
# but it would help in this context.
6062
DISABLE_OVERLOAD_PROTECTION: true
61-
DISABLE_RENDER_CACHING: true
63+
# Render caching won't help when we visit every page exactly once.
64+
DISABLE_RENDERING_CACHE: true
6265
run: |
6366
6467
node server.mjs &

.github/workflows/sync-search-indices.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,8 @@ jobs:
9292
# Because the overload protection runs in NODE_ENV==production
9393
# and it can break the sync-search.
9494
DISABLE_OVERLOAD_PROTECTION: true
95+
# Render caching won't help when we visit every page exactly once.
96+
DISABLE_RENDERING_CACHE: true
9597

9698
run: npm run sync-search
9799

components/DefaultLayout.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ export const DefaultLayout = (props: Props) => {
2727
const { t } = useTranslation(['errors', 'meta', 'scroll_button'])
2828
const router = useRouter()
2929
const metaDescription = page.introPlainText ? page.introPlainText : t('default_description')
30+
3031
return (
3132
<div className="d-lg-flex">
3233
<Head>
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
import { createContext, useContext } from 'react'
2+
3+
export type DotComAuthenticatedContextT = {
4+
isDotComAuthenticated: boolean
5+
}
6+
7+
export const DotComAuthenticatedContext = createContext<DotComAuthenticatedContextT | null>(null)
8+
9+
export const useAuth = (): DotComAuthenticatedContextT => {
10+
const context = useContext(DotComAuthenticatedContext)
11+
12+
if (!context) {
13+
throw new Error(
14+
'"useAuthContext" may only be used inside "DotComAuthenticatedContext.Provider"'
15+
)
16+
}
17+
18+
return context
19+
}

components/context/LanguagesContext.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ type LanguageItem = {
1010

1111
export type LanguagesContextT = {
1212
languages: Record<string, LanguageItem>
13+
userLanguage: string
1314
}
1415

1516
export const LanguagesContext = createContext<LanguagesContextT | null>(null)

components/context/MainContext.tsx

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,6 @@ export type MainContextT = {
9393
relativePath?: string
9494
enterpriseServerReleases: EnterpriseServerReleases
9595
currentPathWithoutLanguage: string
96-
userLanguage: string
9796
allVersions: Record<string, VersionItem>
9897
currentVersion?: string
9998
currentProductTree?: ProductTreeNode | null
@@ -125,7 +124,6 @@ export type MainContextT = {
125124

126125
status: number
127126
fullUrl: string
128-
isDotComAuthenticated: boolean
129127
}
130128

131129
export const getMainContext = (req: any, res: any): MainContextT => {
@@ -181,7 +179,6 @@ export const getMainContext = (req: any, res: any): MainContextT => {
181179
'supported',
182180
]),
183181
enterpriseServerVersions: req.context.enterpriseServerVersions,
184-
userLanguage: req.context.userLanguage || '',
185182
allVersions: req.context.allVersions,
186183
currentVersion: req.context.currentVersion,
187184
currentProductTree: req.context.currentProductTree
@@ -192,7 +189,6 @@ export const getMainContext = (req: any, res: any): MainContextT => {
192189
nonEnterpriseDefaultVersion: req.context.nonEnterpriseDefaultVersion,
193190
status: res.statusCode,
194191
fullUrl: req.protocol + '://' + req.get('host') + req.originalUrl,
195-
isDotComAuthenticated: Boolean(req.cookies.dotcom_user),
196192
}
197193
}
198194

components/page-header/Header.tsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { useVersion } from 'components/hooks/useVersion'
66

77
import { Link } from 'components/Link'
88
import { useMainContext } from 'components/context/MainContext'
9+
import { useAuth } from 'components/context/DotComAuthenticatedContext'
910
import { LanguagePicker } from './LanguagePicker'
1011
import { HeaderNotifications } from 'components/page-header/HeaderNotifications'
1112
import { ProductPicker } from 'components/page-header/ProductPicker'
@@ -17,14 +18,16 @@ import styles from './Header.module.scss'
1718

1819
export const Header = () => {
1920
const router = useRouter()
20-
const { isDotComAuthenticated, error } = useMainContext()
21+
const { error } = useMainContext()
2122
const { currentVersion } = useVersion()
2223
const { t } = useTranslation(['header', 'homepage'])
2324
const [isMenuOpen, setIsMenuOpen] = useState(
2425
router.pathname !== '/' && router.query.query && true
2526
)
2627
const [scroll, setScroll] = useState(false)
2728

29+
const { isDotComAuthenticated } = useAuth()
30+
2831
const signupCTAVisible =
2932
!isDotComAuthenticated &&
3033
(currentVersion === 'free-pro-team@latest' || currentVersion === 'enterprise-cloud@latest')

components/page-header/HeaderNotifications.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ type Notif = {
2121
export const HeaderNotifications = () => {
2222
const router = useRouter()
2323
const { currentVersion } = useVersion()
24-
const { relativePath, allVersions, data, userLanguage, currentPathWithoutLanguage, page } =
25-
useMainContext()
26-
const { languages } = useLanguages()
24+
const { relativePath, allVersions, data, currentPathWithoutLanguage, page } = useMainContext()
25+
const { languages, userLanguage } = useLanguages()
26+
2727
const { t } = useTranslation('header')
2828

2929
const translationNotices: Array<Notif> = []

lib/get-theme.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
// export const defaultCSSThemeProps = {
21
export const defaultCSSTheme = {
32
colorMode: 'auto', // light, dark, auto
43
nightTheme: 'dark',
54
dayTheme: 'light',
65
}
76

8-
// export const defaultComponentThemeProps = {
97
export const defaultComponentTheme = {
108
colorMode: 'auto', // day, night, auto
119
nightTheme: 'dark',

lib/page.js

Lines changed: 8 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,6 @@ import { union } from 'lodash-es'
2424
// every single time, we turn it into a Set once.
2525
const productMapKeysAsSet = new Set(Object.keys(productMap))
2626

27-
// Wrapper on renderContent() that caches the output depending on the
28-
// `context` by extracting information about the page's current permalink
29-
const _renderContentCache = new Map()
30-
31-
function renderContentCacheByContext(prefix) {
32-
return async function (template = '', context = {}, options = {}) {
33-
const { currentPath } = context
34-
const cacheKey = prefix + currentPath
35-
36-
if (!_renderContentCache.has(cacheKey)) {
37-
_renderContentCache.set(cacheKey, await renderContent(template, context, options))
38-
}
39-
return _renderContentCache.get(cacheKey)
40-
}
41-
}
42-
4327
class Page {
4428
static async init(opts) {
4529
opts = await Page.read(opts)
@@ -186,26 +170,26 @@ class Page {
186170
context.englishHeadings = englishHeadings
187171
}
188172

189-
this.intro = await renderContentCacheByContext('intro')(this.rawIntro, context)
190-
this.introPlainText = await renderContentCacheByContext('rawIntro')(this.rawIntro, context, {
173+
this.intro = await renderContent(this.rawIntro, context)
174+
this.introPlainText = await renderContent(this.rawIntro, context, {
191175
textOnly: true,
192176
})
193-
this.title = await renderContentCacheByContext('rawTitle')(this.rawTitle, context, {
177+
this.title = await renderContent(this.rawTitle, context, {
194178
textOnly: true,
195179
encodeEntities: true,
196180
})
197-
this.titlePlainText = await renderContentCacheByContext('titleText')(this.rawTitle, context, {
181+
this.titlePlainText = await renderContent(this.rawTitle, context, {
198182
textOnly: true,
199183
})
200-
this.shortTitle = await renderContentCacheByContext('shortTitle')(this.shortTitle, context, {
184+
this.shortTitle = await renderContent(this.shortTitle, context, {
201185
textOnly: true,
202186
encodeEntities: true,
203187
})
204188

205189
this.product_video = await renderContent(this.raw_product_video, context, { textOnly: true })
206190

207191
context.relativePath = this.relativePath
208-
const html = await renderContentCacheByContext('markdown')(this.markdown, context)
192+
const html = await renderContent(this.markdown, context)
209193

210194
// Adding communityRedirect for Discussions, Sponsors, and Codespaces - request from Product
211195
if (
@@ -222,15 +206,12 @@ class Page {
222206

223207
// product frontmatter may contain liquid
224208
if (this.rawProduct) {
225-
this.product = await renderContentCacheByContext('product')(this.rawProduct, context)
209+
this.product = await renderContent(this.rawProduct, context)
226210
}
227211

228212
// permissions frontmatter may contain liquid
229213
if (this.rawPermissions) {
230-
this.permissions = await renderContentCacheByContext('permissions')(
231-
this.rawPermissions,
232-
context
233-
)
214+
this.permissions = await renderContent(this.rawPermissions, context)
234215
}
235216

236217
// Learning tracks may contain Liquid and need to have versioning processed.

0 commit comments

Comments
 (0)