Describe the bug
There is a logic flaw in the checkHasContent utility function (lib/markdownUtils.ts) that causes a complete page crash when a Markdown table header has exactly one column.
The function assumes reactNode.props.children is an array and calls .reduce() on it. However, if a component only has one child in React, props.children is an object, not an array. When markdown-to-jsx renders a single-column table, props.children on the <tr> wrapper is a single <th> object. Calling .reduce() on this object throws TypeError: reactNode.props.children.reduce is not a function, crashing the entire page render.
Steps To Reproduce
- Create or edit a markdown file rendered via
StyledMarkdownBlock.
- Add a table with only one column:
- Load the page locally or in preview.
- See the
TypeError complete page crash in the browser console / terminal.
Expected Behavior
The page should render the single-column table correctly without crashing. The utility function should safely iterate React children using React.Children.toArray() or check Array.isArray() before assuming array methods are available.
Screenshots
No response
Device Information [optional]
- OS:
- Browser:
- version:
Are you working on this issue?
Yes
Do you think this work might require an [Architectural Decision Record (ADR)]? (significant or noteworthy)
Yes
Describe the bug
There is a logic flaw in the
checkHasContentutility function (lib/markdownUtils.ts) that causes a complete page crash when a Markdown table header has exactly one column.The function assumes
reactNode.props.childrenis an array and calls.reduce()on it. However, if a component only has one child in React,props.childrenis an object, not an array. Whenmarkdown-to-jsxrenders a single-column table,props.childrenon the<tr>wrapper is a single<th>object. Calling.reduce()on this object throwsTypeError: reactNode.props.children.reduce is not a function, crashing the entire page render.Steps To Reproduce
StyledMarkdownBlock.TypeErrorcomplete page crash in the browser console / terminal.Expected Behavior
The page should render the single-column table correctly without crashing. The utility function should safely iterate React children using
React.Children.toArray()or checkArray.isArray()before assuming array methods are available.Screenshots
No response
Device Information [optional]
Are you working on this issue?
Yes
Do you think this work might require an [Architectural Decision Record (ADR)]? (significant or noteworthy)
Yes