Skip to content
Myr

fix(jsx): render async children of document metadata tags instead of [object Promise] (#5204)

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

authored by Paco Cartones · committed by GitHub · parent 13a9481 · Browse files · 2 files+38 added−1 removed
This commit

State

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

Diff stats

2 files+38 added−1 removed

  • tests:+37 added−0 removed
  • other:+1 added−1 removed

2 files+38 added−1 removed

modified:src/jsx/intrinsic-element/components.test.tsx+37 added
34 unmodified lines
35 expect(await resolveCallback(rendered, HtmlEscapedCallbackPhase.Stringify, false, {})).toBe(36 '<html><head><title>Hello</title></head><body><h1>World</h1></body></html>'37 )38 })3940 it('should hoist a title with async children', async () => {41 const AsyncChild = async () => <>{'Hello'}</>42 const template = (43 <html>44 <head></head>45 <body>46 <title>47 <AsyncChild />48 </title>49 <h1>World</h1>50 </body>51 </html>52 )53 const rendered = await template.toString()54 expect(await resolveCallback(rendered, HtmlEscapedCallbackPhase.Stringify, false, {})).toBe(55 '<html><head><title>Hello</title></head><body><h1>World</h1></body></html>'56 )57 })5859 it('should render a title with async children without a head element', async () => {60 const AsyncChild = async () => <>{'Hello'}</>61 const template = (62 <html>63 <body>64 <title>65 <AsyncChild />66 </title>67 <h1>World</h1>68 </body>69 </html>70 )71 const rendered = await template.toString()72 const html = await resolveCallback(rendered, HtmlEscapedCallbackPhase.Stringify, false, {})73 expect(html.toString()).toBe('<html><body><title>Hello</title><h1>World</h1></body></html>')74 expect(html.toString()).not.toContain('[object Promise]')75 })76 })7778 describe('link element', () => {79 it('should be hoisted link tag', async () => {
562 unmodified lines
modified:src/jsx/intrinsic-element/components.ts+1 added-1 removed
106 unmodified lines
107 const string = new JSXNode(tag, restProps, toArray(children || [])).toString()108109 if (string instanceof Promise) {110 return string.then((resString) =>111 raw(string, [111 raw(resString, [112 ...((resString as HtmlEscapedString).callbacks || []),113 insertIntoHead(tag, resString, restProps, precedence),114 ])115 )
95 unmodified lines