Skip to content
Myr

fix(hono/jsx): display blank when children is nullish (#4573)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

* fix(hono/jsx): return fallback when no children are provided Co-authored-by: EdamAmex <edame8080@gmail.com> * chore: add tests Co-authored-by: Taku Amano <taku@taaas.jp> ---------

authored by techfish · committed by GitHub · parent ee52b25 · Browse files · 2 files+36 added−3 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Trailers

  • Co-authored-by: EdamAmex <edame8080@gmail.com>
  • Co-authored-by: Taku Amano <taku@taaas.jp>

Diff stats

2 files+36 added−3 removed

  • tests:+36 added−0 removed
  • other:+0 added−3 removed

2 files+36 added−3 removed

modified:src/jsx/streaming.test.tsx+36 added
191 unmodified lines
192193 suspenseCounter -= 1 // fallback is not rendered194 })195196 it('without children', async () => {197 const stream = renderToReadableStream(198 <div>199 <Suspense fallback={<p>Loading...</p>}></Suspense>200 </div>201 )202203 const chunks = []204 const textDecoder = new TextDecoder()205 for await (const chunk of stream as any) {206 chunks.push(textDecoder.decode(chunk))207 }208209 expect(chunks).toEqual(['<div></div>'])210211 suspenseCounter -= 1 // fallback is not rendered212 })213214 it('only a "false" child', async () => {215 const stream = renderToReadableStream(216 <div>217 <Suspense fallback={<p>Loading...</p>}>{false}</Suspense>218 </div>219 )220221 const chunks = []222 const textDecoder = new TextDecoder()223 for await (const chunk of stream as any) {224 chunks.push(textDecoder.decode(chunk))225 }226227 expect(chunks).toEqual(['<div></div>'])228229 suspenseCounter -= 1 // fallback is not rendered230 })231232 it('async nullish children', async () => {233 let resolved = false234 const Content = () => {235 if (!resolved) {
649 unmodified lines
modified:src/jsx/streaming.ts-3 removed
41 unmodified lines
42export const Suspense: FC<PropsWithChildren<{ fallback: any }>> = async ({43 children,44 fallback,45}) => {46 if (!children) {47 return fallback.toString()48 }46 if (!Array.isArray(children)) {47 children = [children]48 }49
157 unmodified lines