( name: string | Component | typeof Fragment, attributes: PropsWithChildren<unknown> | null, ...children: Children[] )
| 33 | const Fragment: unique symbol = Symbol.for("beth-stack-fragment"); |
| 34 | |
| 35 | async function createElement( |
| 36 | name: string | Component | typeof Fragment, |
| 37 | attributes: PropsWithChildren<unknown> | null, |
| 38 | ...children: Children[] |
| 39 | ): Promise<string> { |
| 40 | children = deepFlatten(children); |
| 41 | |
| 42 | const hasAnyPromiseChildren = children.reduce( |
| 43 | (acc, child) => acc || child instanceof Promise, |
| 44 | false, |
| 45 | ); |
| 46 | const hasAnyUnresolvedPromiseChildren = children.reduce( |
| 47 | (acc, child) => acc || Bun.peek.status(child) !== "fulfilled", |
| 48 | false, |
| 49 | ); |
| 50 | |
| 51 | const insideStreamCall = |
| 52 | BETH_GLOBAL_RENDER_CACHE.streamController !== undefined; |
| 53 | |
| 54 | if ( |
| 55 | name === Suspense && |
| 56 | hasAnyUnresolvedPromiseChildren && |
| 57 | insideStreamCall |
| 58 | ) { |
| 59 | const id = BETH_GLOBAL_RENDER_CACHE.registerChild(children); |
| 60 | |
| 61 | if (attributes !== null && "fallback" in attributes) { |
| 62 | attributes.fallback = ` |
| 63 | <div id="B:${id}" data-fallback> |
| 64 | ${await attributes.fallback} |
| 65 | </div> |
| 66 | `; |
| 67 | } |
| 68 | } else if (name !== ErrorBoundary) { |
| 69 | if (hasAnyPromiseChildren) { |
| 70 | // Converts children to a string if they are promises. |
| 71 | children = await Promise.all(children); |
| 72 | } |
| 73 | } |
| 74 | |
| 75 | // Adds the children to the attributes if it is not present. |
| 76 | if (attributes === null) { |
| 77 | attributes = { children }; |
| 78 | } |
| 79 | |
| 80 | // Calls the element creator function if the name is a function |
| 81 | if (typeof name === "function") { |
| 82 | // In case the children attributes is not present, add it as a property. |
| 83 | if (attributes.children === undefined) { |
| 84 | attributes.children = children; |
| 85 | } |
| 86 | |
| 87 | return name(attributes); |
| 88 | } |
| 89 | |
| 90 | if (name === Fragment) { |
| 91 | return contentsToString(children); |
| 92 | } |
nothing calls this directly
no test coverage detected