Skip to content

Commit

Permalink
fix: sanitize parentsArray in getStaticProps
Browse files Browse the repository at this point in the history
  • Loading branch information
julia-rabello committed Oct 15, 2024
1 parent 28a8a34 commit 1ea46da
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/pages/docs/tutorial/[slug].tsx
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,11 @@ export const getStaticProps: GetStaticProps = async ({
getParents(keyPath, 'slug', flattenedSidebar, currentLocale, parentsArray)
parentsArray.push(slug)

// Ensure parentsArray does not contain undefined values
const sanitizedParentsArray = parentsArray.map((item) =>
item === undefined ? null : item
)

getParents(keyPath, 'name', flattenedSidebar, currentLocale, parentsArrayName)
const mainKeyPath = keyPath.split('slug')[0]
const nameKeyPath = mainKeyPath.concat(`name.${locale}`)
Expand Down Expand Up @@ -301,9 +306,7 @@ export const getStaticProps: GetStaticProps = async ({
type,
sectionSelected,
sidebarfallback,
parentsArray: parentsArray.map((item) =>
item === undefined ? null : item
),
parentsArray: sanitizedParentsArray,
slug,
pagination,
isListed,
Expand Down Expand Up @@ -496,7 +499,7 @@ export const getStaticProps: GetStaticProps = async ({
type,
sectionSelected,
sidebarfallback,
parentsArray,
parentsArray: sanitizedParentsArray,
slug,
pagination,
isListed,
Expand Down

0 comments on commit 1ea46da

Please sign in to comment.