CookbookBooks and writingNo. 1
A technical bookchapters, code notes and a glossary that stay in step with the software
See it in know.sh
Larkspur in PracticeNo. 14
Chapter 7Data loading
11 sections, 3,940 words, about 17 minutes, filed 2 August, revised 19 September, 4 highlights.
By the end of this chapter a reader can load data for a route, cache it sensibly and stream the slow parts. Checked against Larkspur 4.2.0 on 2 August; drift check against 4.3.0 on 19 September, see section 10.
The sample code is examples/ch07 in the book repository; the manuscript is ch07-data-loading.adoc.
examples/ch07, each file with the section it illustrates
The examples folder of the book repository, opened at ch07. At its top, a README on running the example, package.json asking for any Larkspur 4 release from 4.2.0, and a lockfile that now resolves 4.3.0. loader.ts, highlighted, is the file section 3 describes; it still passes the renamed cache option. The routes folder holds books.tsx for route loaders (section 1), book.tsx for loader errors (section 2) and reviews.tsx for deferred data (section 6). The tests folder holds loader.test.ts, run before every drift check.
- examples/
- ch06/ — Chapter 6
- ch07/ — This chapter
- README.md — How to run it
- package.json — larkspur ^4.2.0
- package-lock.json — Resolves 4.3.0
- loader.ts — 3: still passes cache, highlighted
- routes/
- books.tsx — 1: route loaders
- book.tsx — 2: loader errors
- reviews.tsx — 6: defer()
- tests/
- loader.test.ts — Run before each check
- ch08/ — Chapter 8
```element file-tree
{
"caption": "examples/ch07, each file with the section it illustrates",
"description": "The examples folder of the book repository, opened at ch07. At its top, a README on running the example, package.json asking for any Larkspur 4 release from 4.2.0, and a lockfile that now resolves 4.3.0. loader.ts, highlighted, is the file section 3 describes; it still passes the renamed cache option. The routes folder holds books.tsx for route loaders (section 1), book.tsx for loader errors (section 2) and reviews.tsx for deferred data (section 6). The tests folder holds loader.test.ts, run before every drift check.",
"entries": [
{
"name": "examples",
"kind": "folder",
"id": "examples"
},
{
"name": "ch06",
"kind": "folder",
"id": "ch06",
"parent": "examples",
"description": "Chapter 6"
},
{
"name": "ch07",
"kind": "folder",
"id": "ch07",
"parent": "examples",
"description": "This chapter"
},
{
"name": "README.md",
"kind": "file",
"parent": "ch07",
"description": "How to run it"
},
{
"name": "package.json",
"kind": "file",
"parent": "ch07",
"description": "larkspur ^4.2.0"
},
{
"name": "package-lock.json",
"kind": "file",
"parent": "ch07",
"description": "Resolves 4.3.0"
},
{
"name": "loader.ts",
"kind": "file",
"parent": "ch07",
"description": "3: still passes cache",
"highlighted": true
},
{
"name": "routes",
"kind": "folder",
"id": "routes",
"parent": "ch07"
},
{
"name": "books.tsx",
"kind": "file",
"parent": "routes",
"description": "1: route loaders"
},
{
"name": "book.tsx",
"kind": "file",
"parent": "routes",
"description": "2: loader errors"
},
{
"name": "reviews.tsx",
"kind": "file",
"parent": "routes",
"description": "6: defer()"
},
{
"name": "tests",
"kind": "folder",
"id": "tests",
"parent": "ch07"
},
{
"name": "loader.test.ts",
"kind": "file",
"parent": "tests",
"description": "Run before each check"
},
{
"name": "ch08",
"kind": "folder",
"id": "ch08",
"parent": "examples",
"description": "Chapter 8"
}
]
}
```Sections
- 1Route loadersEvidence, keyA loader runs on the server before the route renders; its return type flows into the component’s props. Sources: docs, “Loading data”; 4.0 release notes.
- 2Loader errors and the error boundaryEvidenceA thrown response renders the nearest error boundary; a thrown error renders it with a 500.
- 3Loader cachingEvidence, 1 noteRenamed in 4.3:
cachebecamerevalidate. The example still uses the old name. - 4Form actions belong in chapter 8Decision, keyReaders need loaders before mutations make sense. Chapter 7 mentions actions once, with a forward reference.
- 5Does streaming work on the edge adapter?QuestionThe docs say yes; issue 4127 says not with compression on. Test before the review draft.
and 6 more sections
How it works
A framework moves faster than a book. A coding assistant with the know.sh plugin reads your manuscript and the official docs, files a sourced section for every concept, and later checks chapter 7 against the version in your lockfile: holds, changed or cannot tell. The index becomes the first draft of your glossary.
Try this prompt
Made with
ShelfDocumentYour AI assistantElementsThe A–Z indexPublic link