MCPcopy
hub / github.com/freshframework/fresh / render

Method render

packages/fresh/src/context.ts:264–457  ·  view source on GitHub ↗

* Render JSX and return an HTML `Response` instance. * ```tsx * ctx.render( hello world ); * ```

(
    // deno-lint-ignore no-explicit-any
    vnode: VNode<any> | null,
    init: ResponseInit | undefined = {},
    config: LayoutConfig = {},
  )

Source from the content-addressed store, hash-verified

262 * ```
263 */
264 async render(
265 // deno-lint-ignore no-explicit-any
266 vnode: VNode<any> | null,
267 init: ResponseInit | undefined = {},
268 config: LayoutConfig = {},
269 ): Promise<Response> {
270 if (arguments.length === 0) {
271 throw new Error(`No arguments passed to: ctx.render()`);
272 } else if (vnode !== null && !isValidElement(vnode)) {
273 throw new Error(`Non-JSX element passed to: ctx.render()`);
274 }
275
276 const defs = config.skipInheritedLayouts ? [] : this.#internal.layouts;
277 const appDef = config.skipAppWrapper ? null : this.#internal.app;
278 const props = this as Context<State>;
279
280 // Compose final vnode tree
281 for (let i = defs.length - 1; i >= 0; i--) {
282 const child = vnode;
283 props.Component = () => child;
284
285 const def = defs[i];
286
287 const result = await renderRouteComponent(this, def, () => child);
288 if (result instanceof Response) {
289 return result;
290 }
291
292 vnode = result;
293 }
294
295 let appChild = vnode;
296 // deno-lint-ignore no-explicit-any
297 let appVNode: VNode<any>;
298
299 let hasApp = true;
300
301 if (isAsyncAnyComponent(appDef)) {
302 props.Component = () => appChild;
303 const result = await renderAsyncAnyComponent(appDef, props);
304 if (result instanceof Response) {
305 return result;
306 }
307
308 appVNode = result;
309 } else if (appDef !== null) {
310 appVNode = h(appDef, {
311 Component: () => appChild,
312 config: this.config,
313 data: null,
314 error: this.error,
315 info: this.info,
316 isPartial: this.isPartial,
317 params: this.params,
318 req: this.req,
319 state: this.state,
320 url: this.url,
321 route: this.route,

Callers 13

app_test.tsxFile · 0.45
renderRouteFunction · 0.45
fs_routes_test.tsxFile · 0.45
context_test.tsxFile · 0.45
partials_test.tsxFile · 0.45
islands_test.tsxFile · 0.45
islandAppFunction · 0.45
head_test.tsxFile · 0.45
main.tsxFile · 0.45
app2.tsxFile · 0.45

Calls 7

clearMethod · 0.95
renderRouteComponentFunction · 0.90
isAsyncAnyComponentFunction · 0.90
renderAsyncAnyComponentFunction · 0.90
setRenderStateFunction · 0.90
getHeadersFromInitFunction · 0.85
addMethod · 0.65

Tested by

no test coverage detected