Skip to content

Commit

Permalink
fix(docs-page): process.env.ENABLE_VERSIONED_DOCS is string (#382)
Browse files Browse the repository at this point in the history
* fix(docs-page): env-var check
- `process.env.ENABLE_VERSIONED_DOCS === 'true'`

* chore: changeset
  • Loading branch information
thiskevinwang committed Oct 5, 2021
1 parent ef6333f commit cc46ed6
Show file tree
Hide file tree
Showing 6 changed files with 14 additions and 6 deletions.
7 changes: 7 additions & 0 deletions .changeset/tender-lies-type.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
'@hashicorp/react-docs-page': patch
---

This updates logic to check `process.env.ENABLE_VERSIONED_DOCS === 'true'` since environment variables are _always strings_.

This should prevent some unintended behavior if ENABLE_VERSIONED_DOCS is parsed as a string `"false"`, but unintentionally evaluating to `truthy`
2 changes: 1 addition & 1 deletion packages/docs-page/docs.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ We have a lot of docs sites, all of which render content in exactly the same way
>{`<DocsPage
product={{ name: 'Nomad', slug: 'nomad' }}
baseRoute='docs'
showVersionSelect={false /*process.env.ENABLE_VERSIONED_DOCS*/}
showVersionSelect={false /* process.env.ENABLE_VERSIONED_DOCS === "true" */}
// pass in the results of executing the 'generateStaticProps' function from '@hashicorp/react-docs-page/server'
staticProps={staticPropsResult}
>
Expand Down
5 changes: 3 additions & 2 deletions packages/docs-page/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ const DocsPageWrapper: FunctionComponent<DocsPageWrapperProps> = ({
githubFileUrl,
product: { name, slug },
showEditPage = true,
showVersionSelect = process.env.ENABLE_VERSIONED_DOCS,
showVersionSelect = process.env.ENABLE_VERSIONED_DOCS === 'true',
versions,
}) => {
const isMobile = useIsMobile()
Expand Down Expand Up @@ -117,7 +117,8 @@ const DocsPageWrapper: FunctionComponent<DocsPageWrapperProps> = ({
id="inner"
role="main"
className={classNames(s.inner, s.tempJumpToSectionParent, {
[s.versionedDocsOffset]: process.env.ENABLE_VERSIONED_DOCS,
[s.versionedDocsOffset]:
process.env.ENABLE_VERSIONED_DOCS === 'true',
})}
>
<Content
Expand Down
2 changes: 1 addition & 1 deletion packages/docs-page/props.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ module.exports = {
showVersionedDocs: {
type: 'boolean',
description:
'If `true`, a version select option will be displayed. Defaults to `process.env.ENABLE_VERSIONED_DOCS`',
'If `true`, a version select option will be displayed. Defaults to `process.env.ENABLE_VERSIONED_DOCS === "true"`',
default: null,
},
additionalComponents: {
Expand Down
2 changes: 1 addition & 1 deletion packages/docs-page/server/generate-static-paths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface GenerateStaticPathsContext {

const defaultOptions = {
VERCEL_ENV: process.env.VERCEL_ENV,
ENABLE_VERSIONED_DOCS: process.env.ENABLE_VERSIONED_DOCS,
ENABLE_VERSIONED_DOCS: process.env.ENABLE_VERSIONED_DOCS === 'true',
}

export async function generateStaticPaths(
Expand Down
2 changes: 1 addition & 1 deletion packages/docs-page/server/generate-static-props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export function mapVersionList(

const defaultOptions = {
VERCEL_ENV: process.env.VERCEL_ENV,
ENABLE_VERSIONED_DOCS: process.env.ENABLE_VERSIONED_DOCS,
ENABLE_VERSIONED_DOCS: process.env.ENABLE_VERSIONED_DOCS === 'true',
}

export async function generateStaticProps(
Expand Down

1 comment on commit cc46ed6

@vercel
Copy link

@vercel vercel bot commented on cc46ed6 Oct 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.