· 2 min read · updated
Each route picks its composition
A route can now say how the root layout arranges it: composition in its load data. Two values for now: default and reading.
What we did
- A route can now say how the root layout arranges it:
compositionin its load data. Two values for now:defaultandreading. - The type lives in
App.PageData(src/app.d.ts), sopage.data.compositionis typed everywhere. - The root layout puts it on
<main data-composition>, andglobal.cssstylesmainfor each value. Reading is one 60ch column. /blogand/bitacorasetreadingin their+layout.ts, so every page under them gets it too.- Fixed
mainshrinking to its content: it now always takes its full max width (inline-size: 100%).
What I learned
- Why not just style
mainfrom the page? A page's styles are scoped to the page component;mainbelongs to the root layout. The page can only send data up, and the layout decides what to do with it. - A
+layout.tsload applies to its route and everything below it, so/devlog/[slug]will bereadingwithout doing anything. satisfies App.PageDatachecks the value against the type and keeps'reading'as that exact string. Without it TypeScript widens it tostring.- In a grid,
margin-inline: autostops an item from stretching: it shrinks to fit its content. So each page was as wide as its text.inline-size: 100%plusmax-inline-sizefixes it. - With the route view transitions, changing composition (home 1120px → blog 576px) needs nothing extra: the content box jumps to the new size and the new content fades in.
Links
Next
- The real tagline (Alfonso's words), then the Phase 4.5 PR.