SkilVaultSign inStart free

Catalogue / astro-build-decision-ladder

astro-build-decision-ladder

Older skill: source not recordedSignedGuides an agent through a layered set of decisions for Astro work — render routes statically unless per-request output is genuinely required, write pages in Astro's own component syntax, confine framework components to small hydrated islands given the cheapest working directive, define schema-checke…
---
name: astro-build-decision-ladder
description: >
  Guides Astro work as a decision ladder: read the installed release, output mode, adapter registration, and content configuration before editing; keep routes prerendered unless a per-visitor fact or data newer than the build requires request-time rendering, which needs a server adapter and, on Astro 4, hybrid or server output; build pages as Astro components and hydrate only small framework islands on the cheapest client directive; register schema-checked collections in the shape the repository already uses, via the named collections export, honoring legacy flags on Astro 5 and Astro 6; fetch in frontmatter; finish with accessibility, weight, and convention checks. Use when building or reviewing Astro pages, layouts, components, routes, or content collections, when a page ships too much script, a collection build breaks, or a route renders at the wrong time. Not for other frontend frameworks, backend-only services, or deployment, hosting, and CI decisions.
---

Astro Build Decision Ladder

Move through Astro work as five decisions taken in order: learn what the repository already does, settle when each route renders, decide whether a framework participates and when its script wakes, give repeating content a schema-checked home, and place every fetch. Build time is the resting position — HTML finished before anyone visits — and you push work toward the browser only when a named need pushes back. Follow the ladder and the pages arrive complete, ship script only where interaction demands it, and match the project you are standing in.

1. Inventory the project before you edit

Open package.json for the pinned Astro release; open astro.config.mjs for the output value, any adapter, and any legacy flags; locate the content config if one exists. Note the styling system and naming habits while you are there.

What is on disk outranks the version number. Two projects on the same major can legitimately differ in collection shape or output mode, so let the repository's own configuration decide and treat your knowledge of majors as background. Where the config does not settle a question, consult documentation pinned to the exact installed release rather than assuming the next major behaves like the last. One consistent local pattern also beats two competing ones — follow the house convention even where your taste differs.

Keep the standard layout unless the project hands you a reason you could say out loud:

| Path | Holds | | --- | --- | | src/pages/ | routes; the file tree is the URL map, so keep it shallow | | src/layouts/ | shared page shells | | src/components/ | reusable markup; hydrated framework files sit at the leaves | | src/content/ | collection entries | | src/styles/ | global stylesheets and design tokens | | src/assets/ | images that should pass through the build optimizer | | public/ | files copied byte-for-byte, such as favicons and robots files |

Do not reorganize folders as a side effect of a feature task.

2. Settle each route's rendering time

Prerendered is the standing answer: built once, served as a file, cheap and cacheable. Move a route to per-request rendering only when its response depends on who is asking — cookies, request headers, personalization for a signed-in visitor — or on data newer than the last build, such as a status board that must reflect this morning's edits.

Before touching any per-route flag, read the output value together with the installed major, because the same assignment means different things in different configurations:

| Installed Astro | output value | Unmarked routes render | Making one route per-request | | --- | --- | --- | --- | | 5 and 6.0.0 | 'static' or unset | at build time | export const prerender = false; on that route, with an adapter registered — every other route stays prerendered | | 5 and 6.0.0 | 'server' | on each request | nothing to add; export const prerender = true; is the per-route move back to build time | | 4 | 'static' or unset | at build time | not available — the per-route flag is ignored on Astro 4 static output; change output first (see below) | | 4 | 'hybrid' | at build time | export const prerender = false; on that route, with an adapter registered | | 4 | 'server' | on each request | already per-request |

Three facts travel with every row:

  • An adapter is a hard prerequisite. Any on-request route needs a server adapter registered under adapter in astro.config.mjs; the prerender flag never supplies the runtime, and without an adapter the build stops when it meets an on-demand route. Which adapter suits the project is the project's call — your job is registering one before request-time routes exist.
  • output: 'server' on either major flips the default for every unmarked route to per-request. If you arrived expecting static, say so before editing: the surprise runs the other way too, and the per-route prerender = true restores build-time rendering one route at a time.
  • Astro 5 removed hybrid because static-plus-per-route-opt-out covers the same ground, and Astro 6.0.0 keeps that arrangement. On Astro 4 static output the opt-out does not exist, so switching output is a project-wide edit: hybrid preserves the prerendered default for every unflagged route (smallest blast radius), while server moves them all on-request. List for the user exactly which routes would change behavior and get their go-ahead before editing the config.

Worked call, a botanical-garden site: hours, admission, and planting guides carry nothing visitor-specific, so they stay prerendered. A blooming-today board must reflect horticulturist edits made since the last build, so that single route opts out on freshness grounds — adapter confirmed, output mode read — and the other forty-odd routes keep the static default.

3. Admit a framework only when script is genuinely needed

List the behaviors that need browser script: state that changes after load, event listeners, lifecycle work. An empty list means the whole page is .astro components — the template language already covers props, branching, and iteration, so a framework import would add download weight and deliver nothing. Each surviving item becomes one small island at a leaf of the component tree with static markup around it, because hydration bills everything inside the island's subtree. A museum's interactive floor-plan explorer is the island; the opening hours, exhibit copy, and café menu stay .astro.

4. Wake each island as late as it tolerates

| Directive | Script starts | Reach for it when | | --- | --- | --- | | client:load | right after first paint | the interaction is why the page exists, like a seat picker opened instantly | | client:idle | once the main thread goes quiet | enhancements that can arrive a beat late, like a follow-this-topic toggle | | client:visible | on scroll into view | widgets far down a long page, like a comments thread nine screens in | | client:only | browser only, never on the server | init code touching browser-only globals; nothing renders before script, so ship a static poster beside it |

Hydrating a layout or a wide region is a smell, not a setting: redraw the boundary around the small interactive piece first. Hydrate broadly only when you can explain why no smaller boundary delivers the behavior, and leave that explanation in a comment for the next reader.

5. Give repeating content a schema-checked home

Tours, articles, staff — entries that repeat belong in a collection with a schema, so a typo'd field fails the build instead of silently blanking a live page. The shape follows what the repository already uses, never the installed major alone. Work this order: find the config (src/content.config.ts is the Content Layer path, src/content/config.ts the legacy one), check astro.config.mjs for active legacy flags, then add your collection in the existing shape.

| What the repository shows | Shape to write | Support notes | | --- | --- | --- | | src/content.config.ts already using loaders | Content Layer — defineCollection({ loader, schema }) | the current path on every major that has it | | src/content/config.ts with type: 'content' or type: 'data' | the legacy shape, unchanged | the only shape Astro 4 knows; still supported across Astro 5, with or without its legacy.collections flag | | Astro 6 with legacy.collectionsBackwardsCompat set | keep the legacy shape running under the flag | Astro 6.0.0 removed the automatic compatibility and the Astro 5 legacy.collections flag, but this separate flag re-enables the old config path, type-based collections without loaders, and the legacy entry APIs as a temporary migration bridge | | Astro 6 without that flag | Content Layer | a legacy config here means migration is already due — surface it, and still plan it as its own task | | Astro 5, nothing configured yet | either works; prefer the Content Layer as the forward path | Astro 5 supports both |

Two cautions. First, the table is pinned to releases that exist today (Astro 4.x, 5.x, and 6.0.0): before concluding anything on a newer release, read that release's own legacy-flags documentation, because flag behavior has already changed once between majors and may change again. Second, if a mid-migration project holds both config files, confirm which one the build actually consumes before adding to either. Never migrate shapes as a side effect of adding a collection; if migration is due, plan it separately and tell the user.

Every supported shape ends the config file the same way: a named export of the collections object. Registration reads that named binding — a file ending in a default export registers nothing, and every later query comes back empty.

// src/content.config.ts — Content Layer shape
import { defineCollection, z } from 'astro:content';
import { glob } from 'astro/loaders';

const tours = defineCollection({
  loader: glob({ pattern: '**/*.md', base: './src/content/tours' }),
  schema: z.object({
    title: z.string(),
    durationMinutes: z.number().int().min(15),
    capacity: z.number().int().positive(),
    childFriendly: z.boolean().default(false),
  }),
});

export const collections = { tours };
// src/content/config.ts — legacy shape; identical named export
import { defineCollection, z } from 'astro:content';

export const collections = {
  walks: defineCollection({
    type: 'content',
    schema: z.object({ title: z.string(), distanceKm: z.number().positive() }),
  }),
};

Reading entries works the same in both shapes: await getCollection('tours') resolves to an array of entry objects, each carrying an id and a data object parsed through the schema. An optional second argument is a predicate evaluated per entry that filters the result before it reaches your template; the query never mutates the stored entries. Keep it beside the component that renders it rather than threading props through five layers of children.

---
import { getCollection } from 'astro:content';
const small = await getCollection('tours', ({ data }) => data.capacity <= 12);
---
<ul>{small.map((t) => <li>{t.data.title} — {t.data.durationMinutes} min</li>)}</ul>

6. Place every fetch on the server by default

Fetch in frontmatter — build time or request time — so the browser receives markup with its data already inside. Fetch from the browser only for data that genuinely lives client-side: values that must keep updating without a navigation (a live scoreboard), requests driven by the visitor's own actions (search-as-you-type), or calls carrying per-visitor context your server never holds. Take the exception inside the island that needs it and comment why. Do not bounce visitor-local data through your server for no gain.

7. Weave accessibility and weight in as you go

Retrofitting is where these get dropped, so fold them into each step:

Preview shortened. The full SKILL.md is in the pack.