* Create a child renderer. The child renderer inherits the state from the parent, * but has its own content. * @param {(renderer: Renderer) => MaybePromise<void>} fn
(fn)
| 199 | * @param {(renderer: Renderer) => MaybePromise<void>} fn |
| 200 | */ |
| 201 | child(fn) { |
| 202 | const child = new Renderer(this.global, this); |
| 203 | this.#out.push(child); |
| 204 | |
| 205 | const parent = ssr_context; |
| 206 | |
| 207 | set_ssr_context({ |
| 208 | ...ssr_context, |
| 209 | p: parent, |
| 210 | c: null, |
| 211 | r: child |
| 212 | }); |
| 213 | |
| 214 | const result = fn(child); |
| 215 | |
| 216 | set_ssr_context(parent); |
| 217 | |
| 218 | if (result instanceof Promise) { |
| 219 | // catch to avoid unhandled promise rejections - we'll end up throwing in `collect_async` if something fails |
| 220 | result.catch(noop); |
| 221 | result.finally(() => set_ssr_context(null)).catch(noop); |
| 222 | |
| 223 | if (child.global.mode === 'sync') { |
| 224 | e.await_invalid(); |
| 225 | } |
| 226 | |
| 227 | child.promise = result; |
| 228 | } |
| 229 | |
| 230 | return child; |
| 231 | } |
| 232 | |
| 233 | /** |
| 234 | * Render children inside an error boundary. If the children throw and the API-level |