weft
ir 2.6.0 · warp 1.8.0
Part one · Step 2 of 19

The document, and documents that nest

Take over the shell, and discover that its holes are a contract.

Goal

Replace the framework’s document with your own, and find out that its slot holes are now a contract every route under it has to fill.

The framework’s document is a placeholder. Replacing it is adding one file, and the moment you do, its <slot> holes become the boundaries every route has to fill.

1 · Take over the shell

sketch — not compiled
// app/layout.tsx
import { fragment, raw } from '@weftjs/core'

interface Props {
  title: string
  css: string
  runtime: string
  body: string
  aside: string
}

export default fragment(({ title, css, runtime, body, aside }: Props) => (
  <>
    {raw('<!doctype html>')}
    <html lang="en">
      <head>
        <meta charset="utf-8" />
        <title>{title}</title>
        <link rel="stylesheet" href={css} />
        <script type="module" src={runtime} />
      </head>
      <body>
        <main><slot name="body">{body}</slot></main>
        <aside><slot name="aside">{aside}</slot></aside>
      </body>
    </html>
  </>
))

Fill it from the route’s declaration:

sketch — not compiled
// app/routes/index.data.ts
import { defineRoute } from '@weftjs/core'

export default defineRoute({
  head: { title: 'Shop' },
  slots: {
    aside: { html: '<p>Open 9–6.</p>' },
  },
})

Note what is not here. body is not declared: the route’s own .tsx fills it, which is the one convention the hole names rely on. title, css and runtime are not declared either — the framework supplies six values every document may read, and a hole outside that set has to come from layoutValues or the build says so.