Skip to content

Commit

Permalink
[v3] fix `TypeError: undefined is not iterable (cannot read property …
Browse files Browse the repository at this point in the history
…Symbol(Symbol.iterator))` on dev environment when `frontMatter.searchable: false` (#2770)

fix
  • Loading branch information
Dimitri POSTOLOV committed Mar 6, 2024
1 parent 9b41180 commit 2630461
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 5 deletions.
6 changes: 6 additions & 0 deletions .changeset/rotten-spies-exist.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
'nextra-theme-docs': patch
'nextra': patch
---

fix `TypeError: undefined is not iterable (cannot read property Symbol(Symbol.iterator))` on dev environment when `frontMatter.searchable: false`
10 changes: 6 additions & 4 deletions packages/nextra/src/server/loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,14 +175,16 @@ ${themeConfigImport && '__nextra_internal__.themeConfig = __themeConfig'}`
return `${result}
export default MDXLayout`
}
if (searchIndexKey && frontMatter.searchable !== false) {
if (searchIndexKey) {
// Store all the things in buildInfo.
const { buildInfo } = this._module as any
buildInfo.nextraSearch = {
indexKey: searchIndexKey,
title,
data: structurizedData,
route
...(frontMatter.searchable !== false && {
title,
data: structurizedData,
route
})
}
}

Expand Down
4 changes: 3 additions & 1 deletion packages/nextra/src/server/webpack-plugins/nextra-search.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ export class NextraSearchPlugin {
const { title, data, indexKey, route } = nextraSearch
const indexFilename = `nextra-data-${indexKey}.json`
indexFiles[indexFilename] ??= {}
indexFiles[indexFilename][route] = { title, data }
if (route) {
indexFiles[indexFilename][route] = { title, data }
}
}
}
for (const [file, content] of Object.entries(indexFiles)) {
Expand Down

0 comments on commit 2630461

Please sign in to comment.