Skip to content

Commit 3676b1e

Browse files
authored
Branch was updated using the 'autoupdate branch' Actions workflow.
2 parents 910470f + ef48759 commit 3676b1e

File tree

10 files changed

+24
-12
lines changed

10 files changed

+24
-12
lines changed

components/DefaultLayout.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { useTranslation } from './hooks/useTranslation'
1111

1212
type Props = { children?: React.ReactNode }
1313
export const DefaultLayout = (props: Props) => {
14-
const { builtAssets, expose, page, error, isHomepageVersion } = useMainContext()
14+
const { builtAssets, page, error, isHomepageVersion } = useMainContext()
1515
const { t } = useTranslation('errors')
1616
return (
1717
<div className="d-lg-flex">
@@ -22,7 +22,6 @@ export const DefaultLayout = (props: Props) => {
2222
<title>{page.fullTitle}</title>
2323
) : null}
2424

25-
<script id="expose" type="application/json" dangerouslySetInnerHTML={{ __html: expose }} />
2625
<script src={builtAssets.main.js} />
2726

2827
{/* For Google and Bots */}

components/Search.tsx

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,14 +30,11 @@ export function Search({ isStandalone = false, updateSearchParams = true, childr
3030
const { currentVersion } = useVersion()
3131

3232
// Figure out language and version for index
33-
const { expose } = useMainContext()
34-
const {
35-
searchOptions: { languages, versions, nonEnterpriseDefaultVersion },
36-
} = JSON.parse(expose)
33+
const { languages, searchVersions, nonEnterpriseDefaultVersion } = useMainContext()
3734
const router = useRouter()
3835
// fall back to the non-enterprise default version (FPT currently) on the homepage, 404 page, etc.
39-
const version = versions[currentVersion] || versions[nonEnterpriseDefaultVersion]
40-
const language = (languages.includes(router.locale) && router.locale) || 'en'
36+
const version = searchVersions[currentVersion] || searchVersions[nonEnterpriseDefaultVersion]
37+
const language = (Object.keys(languages).includes(router.locale || '') && router.locale) || 'en'
4138

4239
// If the user shows up with a query in the URL, go ahead and search for it
4340
useEffect(() => {

components/context/MainContext.tsx

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ export type MainContextT = {
6969
article?: BreadcrumbT
7070
}
7171
builtAssets: { main: { js: string } }
72-
expose: string
7372
activeProducts: Array<ProductT>
7473
currentProduct?: ProductT
7574
currentLayoutName: string
@@ -106,12 +105,14 @@ export type MainContextT = {
106105
}
107106

108107
enterpriseServerVersions: Array<string>
108+
109+
searchVersions: Record<string, string>
110+
nonEnterpriseDefaultVersion: string
109111
}
110112

111113
export const getMainContextFromRequest = (req: any): MainContextT => {
112114
return {
113115
builtAssets: { main: { js: req.context.builtAssets.main.js } },
114-
expose: req.context.expose,
115116
breadcrumbs: req.context.breadcrumbs || {},
116117
activeProducts: req.context.activeProducts,
117118
currentProduct: req.context.productMap[req.context.currentProduct] || null,
@@ -179,6 +180,8 @@ export const getMainContextFromRequest = (req: any): MainContextT => {
179180
? getCurrentProductTree(req.context.currentProductTree)
180181
: null,
181182
featureFlags: {},
183+
searchVersions: req.context.searchVersions,
184+
nonEnterpriseDefaultVersion: req.context.nonEnterpriseDefaultVersion,
182185
}
183186
}
184187

javascripts/airgap-links.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
export default function airgapLinks () {
2+
if (window.IS_NEXTJS_PAGE) return
3+
24
// When in an airgapped environment,
35
// show a tooltip on external links
46
const { airgap } = JSON.parse(document.getElementById('expose').text)

javascripts/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,10 @@ import releaseNotes from './release-notes'
2222
import showMore from './show-more'
2323
import airgapLinks from './airgap-links'
2424
import toggleImages from './toggle-images'
25+
import setNextEnv from './set-next-env'
2526

2627
document.addEventListener('DOMContentLoaded', async () => {
28+
setNextEnv()
2729
displayPlatformSpecificContent()
2830
displayToolSpecificContent()
2931
explorer()

javascripts/search.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ let version
1515
let language
1616

1717
export default function search () {
18-
if (window.next) return
18+
if (window.IS_NEXTJS_PAGE) return
1919

2020
// We don't want to mess with query params intended for the GraphQL Explorer
2121
isExplorerPage = Boolean(document.getElementById('graphiql'))

javascripts/set-next-env.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export default function setNextEnv () {
2+
window.IS_NEXTJS_PAGE = !!document.querySelector('#__next')
3+
}

javascripts/survey.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ function trackEvent ({ token, vote, email, comment }) {
4646
}
4747

4848
export default function survey () {
49-
if (window.next) return
49+
if (window.IS_NEXTJS_PAGE) return
5050

5151
const form = document.querySelector('.js-survey')
5252
const texts = Array.from(document.querySelectorAll('.js-survey input, .js-survey textarea'))

middleware/context.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,8 @@ module.exports = async function contextualize (req, res, next) {
7474
airgap: Boolean(process.env.AIRGAP || req.cookies.AIRGAP) || undefined
7575
})
7676
if (process.env.AIRGAP || req.cookies.AIRGAP) req.context.AIRGAP = true
77+
req.context.searchVersions = searchVersions
78+
req.context.nonEnterpriseDefaultVersion = nonEnterpriseDefaultVersion
7779

7880
return next()
7981
}

tests/browser/browser.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,13 +315,17 @@ describe('nextjs query param', () => {
315315
it('conditionally renders through nextjs pipeline depending on FEATURE_NEXTJS value', async () => {
316316
const flagVal = require('../../feature-flags.json').FEATURE_NEXTJS
317317
await page.goto('http://localhost:4001/en/actions?nextjs=')
318+
const IS_NEXTJS_PAGE = await page.evaluate(() => window.IS_NEXTJS_PAGE)
318319
const nextWrapper = await page.$('#__next')
319320
flagVal === true ? expect(nextWrapper).toBeDefined() : expect(nextWrapper).toBeNull()
321+
flagVal === true ? expect(IS_NEXTJS_PAGE).toBe(true) : expect(IS_NEXTJS_PAGE).toBe(false)
320322
})
321323

322324
it('does not render through nextjs pipeline when nextjs query param is missing', async () => {
323325
await page.goto('http://localhost:4001/en/actions')
324326
const nextWrapper = await page.$('#__next')
327+
const IS_NEXTJS_PAGE = await page.evaluate(() => window.IS_NEXTJS_PAGE)
325328
expect(nextWrapper).toBeNull()
329+
expect(IS_NEXTJS_PAGE).toBe(false)
326330
})
327331
})

0 commit comments

Comments
 (0)