You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 3feb355
Browse filesBrowse the repository at this point in the historyBrowse files
fix(jsx): allow a function component to return an array (#5179)
* fix(jsx): allow a function component to return an array
A function component returning an array threw "str.search is not a
function" during server-side rendering. The return value did not match
any branch in JSXFunctionNode.toStringToBuffer() and fell through to
escapeToBuffer(), which expects a string.
Handle arrays with childrenToStringToBuffer(), the same path already
used for array children. JSX.ElementType is also added so that the
type layer accepts components returning any renderable value, matching
what hono/jsx/dom already supports at runtime.
* fix(jsx): accept an array return in the type layer
The runtime already renders a function component that returns an array,
but the type layer still rejected it. Add `Child[]` to the call
signature of `FC`, and define `JSX.ElementType` with the same return
type.
Without `JSX.ElementType`, TypeScript checks the return type against
`JSX.Element` and reports TS2786. Both types now accept exactly the same
set of return values, so nothing beyond arrays becomes newly valid.
* fix(jsx): render an array resolved from a promise
An async function component returning an array produced escaped,
comma-joined text instead of markup, because the resolved array reached
the string buffer as-is and was stringified by `String()`. Wrap a
resolved array in a fragment so it is rendered like any other node.
`Child` now carries `Promise<string | Child[]>`, which surfaced the same
hole for children: a child promise resolving to an array took the same
path. Both call sites share `resolveArrayToFragment()`, which also
attaches the suspended context, so the promise branch of
`JSXFunctionNode` no longer needs its own `then()` chain.
* fix(jsx): scope promised arrays to component results
* fix(jsx-renderer): accept array component results
* fix(jsx): preserve callbacks in component arrays
* refactor(jsx): remove obsolete suspended context state
---------
Co-authored-by: Taku Amano <[email protected]>
0 commit comments