Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/search-hit-without-description.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'@doc-kit/generator-react': patch
---

Fix the search modal crashing with `Cannot read properties of undefined (reading 'split')` when a hit has no description, such as headings without a leading paragraph in the generated `orama-db.json` index.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ const { renderLabel } = await import(renderLabelModule);
process.once('exit', () => rm(output, { recursive: true, force: true }));

describe('renderLabel', () => {
it('returns the label unchanged when it is not a string', () => {
assert.equal(renderLabel(undefined), undefined);
assert.equal(renderLabel(''), '');
});

it('does not render elements for empty segments', () => {
const result = renderLabel('`value`');

Expand Down
7 changes: 6 additions & 1 deletion packages/react/src/html/ui/utils/renderLabel.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,15 @@
* a case where'd have extremely complex markdown
* within a sidebar like this)
*
* @param {string} label - Raw heading text.
* @param {string | undefined} label - Raw heading text. Search hits have no
* label for documents without a leading paragraph.
* @returns {import('preact').ComponentChildren}
*/
export const renderLabel = label => {
if (!label) {
return label;
}

const segments = label.split('`');

if (segments.length === 1) {
Expand Down
Loading