Client navigation and hydration
What happens after the first paint: client-side transitions and what they tell a keyboard and a screen reader, prefetching, scroll restoration, per-route code splitting, hydration modes and islands.
Client-side navigation and code splitting#
Plain <a> tags become client-side transitions — no <Link> component. The runtime intercepts same-origin left clicks (no modifier keys, no target, no download), fetches the destination's route chunk and its loader props as JSON (?__borgo=props) in parallel, swaps the composed tree in place and updates head, history and scroll. Anything it cannot handle — external links, unknown routes, a failed fetch — falls back to a normal full navigation.
The build emits one lazy chunk per route; React, the runtime and layouts live in the shared entry chunk, loaded once.
The same applies to <form method="post">: submits run the page action over fetch and re-render in place, keeping the scroll position — see form actions.
A link to the page you are already on refreshes it and replaces the current history entry rather than pushing a duplicate, the way the browser does — otherwise leaving the page would take two presses of the back button. A link to a #fragment on the current page is left entirely to the browser.
Nothing is ever taken over that the user asked for explicitly: a middle click, Ctrl/Cmd-click, target, download, and any anchor whose click handler called preventDefault all behave natively.
What a navigation tells the keyboard and the screen reader#
A full page load moves keyboard focus to the top of the new document, and a screen reader reads its title. A client navigation used to replace the page and do neither: focus stayed on the link that was clicked, in a page that was gone, and nothing was announced. Since 1.1 the runtime does both once it has rendered the new page:
- The title is announced. The document's title is written into a visually hidden
aria-live="polite"element the runtime adds to the body once (#borgo-announcer). Give every page ahead.title, and that title is what a screen reader says. - Focus moves to the heading. The first
<h1>in what was rendered — layouts included, so a layout that puts the site's name in an<h1>takes the focus on every page — or failing that the first<main>or[role=main], is focused without scrolling. An element that could not take focus is giventabindex="-1", which makes it focusable from code and leaves it out of the tab order. The next press of Tab starts from the top of the new page.
Three cases are left alone: the same page shown again (a refresh, revalidate()); a navigation to a #fragment, which is the browser's to scroll and focus; and a page in which somebody is already typing — focus is not taken from an input, a textarea, a select or an editable element that holds it.
A focused heading may show the browser's focus ring. That is the browser saying where the keyboard is; style h1:focus or h1:focus-visible if the default does not suit the design, and do not remove it without putting something in its place.
Navigating from code#
A link covers most navigation and an action's redirect covers the rest of what a form does. Two things are left, and both are functions:
import { navigate, revalidate, subscribe } from "borgo-framework";
import { useEffect } from "react";
export default function Board({ columns }: { columns: string[] }) {
useEffect(() => {
// the page's data went stale somewhere other than its own form
const channel = subscribe("board", () => revalidate());
return () => channel.close();
}, []);
return (
<main onKeyDown={(e) => e.key === "s" && navigate("/search")}>
{columns.map((c) => (
<section key={c}>{c}</section>
))}
</main>
);
}
navigate(to) is the road a clicked link takes: the destination's props are fetched while its chunk loads, a history entry is pushed — navigate(to, { replace: true }) rewrites the current one instead — and nothing is reloaded. revalidate() runs the current page's loader again and renders what it returns where the page is: the scroll stays, and so does the state of every component that stays mounted, which is the difference from a reload. Both return a promise that settles when the page has rendered.
In the browser, neither can fail to arrive. Where there is no client navigation to take — the page has hydrate = false, the site is a static export, the destination is on another origin — navigate hands the address to the browser and revalidate reloads. The one refusal is a destination that is not http(s): navigate("javascript:…") throws, here as everywhere a URL is handed to the browser. On the server both throw: navigate names what to do instead, a loader or an action returning redirect(to), and revalidate says the loader is already running.
Prefetching#
Links scrolled into the viewport get their route chunk prefetched. Hovering, focusing or touching a link additionally prefetches its loader props — hovering waits a beat first, so sweeping the pointer across a list of fifty links does not fire fifty requests at your server; focus and touch are immediate, because both are deliberate.
Prefetched props are kept for ten seconds, consumed by the navigation that follows, and dropped whenever a form action mutates something — so a hover-then-click usually renders with zero waiting, and never renders data the mutation just invalidated. The cache is bounded, and anything evicted has its response body cancelled rather than left dangling.
By design, props arrive as one JSON payload fetched in parallel with the chunk: loader data is not streamed on client navigations. Streaming applies to the initial server render, where it matters most.
Scroll restoration#
Every history entry gets a key; scroll positions are saved per entry in sessionStorage, so they survive a reload and a cross-document round trip. Back and forward restore the saved position, a new navigation goes to the top or to the #fragment target, and an action that redirects back to the page you were on leaves you exactly where you were.
Partial hydration#
A page may export hydrate (as a literal, so the build can read it without executing the page):
export const hydrate = false— the page is server-rendered HTML only: no props script, no client bundle, no route chunk built. Right for pure content pages; classic form actions still work, and links on it are normal full navigations. These pages also export statically with zero JavaScript.export const hydrate = "visible"— the entry loads, but the page's chunk is fetched and hydrated only when the element markeddata-borgo-visible(or the page root, if unmarked) scrolls into view. Right for pages whose interactive part sits below a long read.
The default is eager hydration. Client-side navigation to a "visible" page hydrates it immediately — the deferral applies to the initial load, where the HTML is already on screen.
Islands#
For finer granularity than the page, drop a component in islands/ and mark it in any page:
import { Island } from "borgo-framework";
export const hydrate = false; // the page ships no page bundle at all
export default function Guide() {
return (
<article>
{/* ...static content... */}
<Island name="Counter" props={{ start: 5 }} />
<Island name="Counter" props={{ start: 0 }} client="visible" />
</article>
);
}
On a hydrate = false page each island hydrates independently — through a small dedicated entry that touches only the island markers — so a content page can carry a search box without hydrating anything else. client="visible" waits until the island scrolls into view. On normally hydrated pages <Island> renders inline as part of the page tree.
The tradeoff, stated: island modules are registered eagerly, so their code rides with the client entry (and the islands entry loads React). client="visible" defers the hydration work, not the download. Props must be JSON-serializable — they are inlined into the island's HTML marker, and one island with an unreadable marker is skipped without stopping the others on the page.
When the client cannot cope#
Every failure mode falls back to something that works rather than to a broken page:
| Situation | What happens |
|---|---|
| Route chunk fails to load (a deploy changed the hashes) | full navigation to the destination |
| The props come from a build other than the one the tab is running (a deploy happened under it) | full navigation, so new data is never rendered by old components |
| Loader props fetch fails | full navigation |
| The destination is not a known route | full navigation |
| A loader redirects to another origin | the browser navigates there |
| A redirect chain exceeds ten hops | full navigation, rather than looping forever |
A redirect with a javascript: or data: scheme |
refused; a navigation falls back to a full load of the link target, a form submit reloads |
| The server answers a submit with something unparseable | reload, so the page reflects whatever the mutation did |
A submit is refused with 413 before the action ran (BORGO_MAX_BODY, or a proxy's body limit) |
no reload — the form keeps what was typed and an overlay says nothing was saved and why; see form actions |
A submit gets 403 (stale CSRF token) or 405 (no action on that page) |
native resubmit, so the browser shows the real error |
The runtime never leaves a mutation in an unknown state silently: if it cannot interpret the answer, it goes and asks the server again. The one deliberate exception is the 413: there the server has already said that nothing ran, and a reload would only destroy the draft.
The build is named by its client entry, whose file name carries a hash of the client code: a deploy that changed only Go, or only loaders, is the same build to a tab, and its navigations stay client-side. borgo dev sends no build name. And when a page's own rendering throws, the page is replaced by its ErrorBoundary and the layouts stay.