Collections
A Collection is a keyed, dynamic list. Its items arrive in the server state; the view only declares the item template and an upper bound. Tables, pagers, lists of bars and order lines are all collections.
The basics
‹Collection bind="contacts.rows" itemKey="id" maxItems={5} as="tbody" label="Contacts"> {(c) => ( ‹Stack as="tr"> ‹Text as="td">{c.name}‹/Text> ‹Text as="td">{c.email}‹/Text> ‹/Stack> )} ‹/Collection>
// contract rows: collection({ key: 'id', fields: { name: text(), email: text(), added: text() } }),
// load return ctx.snapshot(version, { 'contacts.rows': [{ id: 'c1', name: 'Contact One', email: '[email protected]', added: '01 Dec 2026' }], });
| Prop | Meaning |
|---|---|
| bind | A collection(...) path of the contract |
| itemKey | The item field that identifies each item, as the contract's key declares it (like React's key). Missing: LUXEL-E008 |
| maxItems | Required, 1 to 512: the most items the state may carry (LUXEL-E029). In a screen, for a list declared with page: false (below), it may be left out: the accessor carries the declared bound. With a path string (bind="view.list") it is always written |
| as | div (default), tbody, ul, ol |
| id | Zone id (default: the last segment of bind) |
| label | Accessible name of the list |
| className | Class of the list element |
| changeEvent, changeStatus | For rows with inputs (below) |
Every list declares its bound. A longer list is paginated on the server. luxel check also refuses a collection above policies.maxCollectionItems (LUXEL-E032), and a table (a row collection without inputs) showing more than policies.pageSize items per page (LUXEL-E048).
A short, fixed list longer than the page size
policies.pageSize is one number for every table of the app. A table that is a short, fixed list and is never paginated (the 12 months of a year, with pageSize: 10) is exempted where the collection is declared, in the contract, together with its bound:
// server/contract.ts cobranza: { months: collection({ key: 'id', fields: { month: text(), total: money() }, page: false, maxItems: 12 }), },
‹Collection bind="cobranza.months" itemKey="id" maxItems={12} as="tbody" label="Months"> {(m) => ( ‹Stack as="tr"> ‹Text as="td">{m.month}‹/Text> ‹Text as="td">{m.total}‹/Text> ‹/Stack> )} ‹/Collection>
- page: false and maxItems go together. One without the other, or a maxItems that is not an integer from 1 to 512, is a build error (LUXEL-E029).
- The declared maxItems bounds every view of the list: a view writes the same maxItems or a smaller one, never a larger one (LUXEL-E029). In a screen (bind={state.months}) the view may leave it out: the accessor carries the declared bound. A view bound by a path string (bind="cobranza.months") always writes it: the types require it and so does the build (LUXEL-E029).
- policies.maxCollectionItems still applies to it (LUXEL-E032), and so does the bound at run time (next section), exempt or not.
- Only the page size is lifted, only for that collection. luxel check lists every declared exemption next to the pageSize policy, with its bound and whether the page size needed it (report/months ≤ 12 (needed: the view shows up to 12)), and the exemption stays on the server (.luxel/): no public file carries it.
A table over the page size that is not exempt is refused with the two ways out:
manifests/cobranza.json:1:1 - error LUXEL-E048 (page-size-over-limit): Table "months" of "cobranza" shows up to 12 rows per page: over the policy (pageSize 10). suggestion: Write maxItems={10} or less and paginate on the server. If it is a short, fixed list that is never paginated (the 12 months of a year), exempt it where it is declared, in the contract: collection({ …, page: false, maxItems: 12 }). maxItems still bounds it (at most 50, policies.maxCollectionItems) and the server refuses a state with more.
Do not use the exemption for a list that grows with the data (contacts, orders, movements): those are paginated on the server.
The bound at run time
maxItems is checked by the server wherever a collection's state leaves it, for every collection and every adapter (handlers written with defineLoad / defineEvent, a screen, or an adapter written by hand in bindings.views):
- a load: the filled page and the state read (GET /_luxel/view/‹view>);
- an event's answer: a list given whole (ctx.set, a screen's ctx.update, ctx.sync), the inserts of one answer, and an insert into a list the answer does not give (counted on the server, below).
The browser decides none of this: it applies what the server answers.
A list over its bound is never shortened (which rows to drop is a decision about your data): the request is refused with a server error (HTTP 500, the generic body), and luxel-host logs one error line with the code, the collection, the count, the bound and the fix:
LUXEL-E029 (collection-without-limit): view report: "report.months": collection "months" has 13 items; it allows at most 12 (maxItems). Return at most 12 items and paginate on the server, or raise the bound where it is declared: maxItems on ‹Collection>, or collection({ …, page: false, maxItems }) for a short, fixed list.
The error is a CollectionBoundError (exported by @luxel-framework/server, with viewId, zoneId, count, maxItems and, where the adapter knows it, the state path). The rule is one (stateWithinBounds for a state, stepsWithinBounds for an answer, whose steps stepsOfOps reads from its ops; all in @luxel-framework/server), applied at two layers:
- The gateway applies it to what every adapter gives: each state before it is sent or fills a page, and the ops of each event's answer. This is the layer nothing bypasses. For an event it runs after the adapter has returned, so an adapter written by hand has already committed what it wrote, as with any other invalid answer it gives. Its log line names the zone, not the state path.
- For handlers written with defineEvent or a screen, the same rule also runs inside the handler's transaction, after the handler: the refusal makes the store's work fail exactly as an error thrown by the handler does, so a store that runs the work in a database transaction rolls the write back, and no answer is kept for the event id (the same id can be sent again). Only this layer knows the list a ctx.sync gives. Effects outside that transaction (a call to another service) are not undone, as with any handler error.
An insert into a list the answer does not give
ctx.insert adds one item to the list the page already shows. The answer alone does not say how many items the list has afterwards, so the server finds out, in one of two ways. Which one is decided by the compiled view (its manifest), not by an option of yours.
Form rows the event carries. A row collection with inputs holds the person's draft: the browser keeps the rows and sends them with every event that declares the collection as its rows input (fields={['lines']} on the action). For such an event the server has the list in the request (the decoder already refuses more rows than maxItems), so the count is exact and costs nothing: the rows received, plus the answer's inserts, minus its removes, step by step. Over maxItems the answer is refused. No load is run.
Every other list (the server holds it; the load returns it). After the handler, inside the same transaction, the server runs the view's load again (the same transaction handle, ctx.tx: the load sees what the handler just wrote) and checks two things against the state it gives:
- the answer is the state's: every key the answer inserts is in the list the load returns, and every key it removes is not. An answer that inserts a row the handler did not store, or removes one it did not delete, is refused (the log names the collection and how many keys disagree, never a key);
- the list is within its bound.
Either refusal is like the others: the transaction does not commit (a store that runs the work in a database transaction rolls the handler's write back), no answer is kept for the event id, HTTP 500.
What it costs, and when:
- one more run of the view's load per such event, and only for those: an answer with no insert, an answer whose inserts follow a ctx.set / ctx.sync of the same list, and an event that carries the rows of the collection never pay it;
- to avoid it, give the list: ctx.sync(path, before, now, seen) or ctx.set(path, list). The server then knows the list from the answer and counts its inserts and removes on it (a sync of 12 followed by an insert is 13: refused).
What this does and does not guarantee:
- The load must read through ctx.tx, as the handler writes through it, and must return the row the handler inserted. A list shown by pages, where the new row may not be on the page the load returns, uses ctx.sync or ctx.set; so does an event that adds a form row without carrying the rows (the load of form rows does not return them: the answer is refused; declare the rows in the action).
- The server does not know the list the page holds. It guarantees that ITS list after the event is within the bound, and that the keys the answer names agree with it. It does not guarantee that applying the answer to the page's list gives the server's list. Two ways it can differ:
- the page was stale before the event (a write from another tab, another page of a paginated list). The server checks the page's version only for a write that declares a lock (a version that does not match is refused with STATE_CONFLICT), and only as far as that version covers the rows of the list; a read event and a write without a lock are answered whatever version the page had;
- the answer omits a change the handler made. Example, with no stale page and no concurrent write: the page and the server both hold 12 rows; the handler deletes m12, stores x1, and returns only ctx.insert for x1. The reloaded list has 12 rows and includes x1, the answer names no removed key to check, so the answer is accepted; the page applies the insert and shows 13 rows, because the answer never removed m12.
The page's list is corrected when it next reads the state. A page over its bound is not refused in the browser: the browser applies what the server answers and decides nothing. See GAPS.md.
Answer every change you make to a list (or use ctx.sync), because the page applies only what the answer says.
An adapter written by hand has no transaction the framework knows. After an answer of that kind the gateway calls the adapter's load and applies the same two checks to its state (always: the gateway skips this only for the adapters @luxel-framework/server built itself, which it knows by a registry of its own, countsInsertsItself(adapter); nothing an adapter object says about itself changes that); a refused answer is HTTP 500 with the log line, but what the adapter wrote stays written, as with any other invalid answer it gives: every later load is refused until the data is corrected. The adapter's author keeps a list within its bound before writing.
The functions are exported by @luxel-framework/server for an adapter written by hand that wants to check before it writes: rowsHeld (the rows an event carried), stepsWithinBounds, answerMatchesState (which throws a CollectionAnswerError for an answer that is not the state's).
Item templates
The child of a Collection is a function of the item. It runs once, at build time, with placeholders instead of values. The result is the item template; the runtime stamps it per item.
The template is one of:
- one ‹Action>;
- one ‹Text>;
- a row: a ‹Stack> or ‹Row> with ‹Text>s, ‹Field>s, ‹Select>s, ‹Bar>s and ‹Action>s.
What you can do with an item field
- Place it as the text of a Text or the label of an Action: ‹Text as="td">{c.name}‹/Text>.
- Pass the item key as an action's param: param={c.id}.
- Pass a status([...]) field as a Text's state, with the classes of each state:
‹Text as="span" state={a.state} stateClasses={{ active: 'badge badge--on', inactive: 'badge badge--off' }}> {a.stateLabel} ‹/Text>
- Pass number fields to a Bar (see Charts).
What you cannot do
- Compute with it: no ` ${c.name}! , no c.name.toUpperCase(), no c.total * 2 (LUXEL-E016`). The text belongs to the server: format it there.
- Use it as an attribute: no className={c.state} (LUXEL-E028). The only dynamic attributes are the compiler's: the state class through state/stateClasses, disabled and the item key.
- Use a field the contract does not declare, put static text alone in the template, or pass as param anything but the key (LUXEL-E015).
- Give an Action an id inside an item template: ids are per view, items repeat.
- Branch on an item field (c.active && ‹X />): the template runs once, without values. Use a status field and stateClasses, or let the server send a different label.
Unavailable actions
An item may carry disabled: true (a boolean) next to its fields. The page then writes the disabled attribute on the item's actions, for example a pager's "Previous" on the first page. The server decides; the page only writes the attribute.
'transactions.pager': [ { id: `a${Math.max(1, page - 1)}`, label: 'Previous', disabled: page <= 1 }, { id: `b${Math.min(pages, page + 1)}`, label: 'Next', disabled: page >= pages }, ],
The generated types of item fields do not list disabled yet; the lab's code passes these values through an untyped object.
Tables
A table is a Stack as="table", a header written as static Text as="th", and a Collection as="tbody" whose item is a Stack as="tr":
‹Stack as="table" className="table"> ‹Stack as="thead"> ‹Stack as="tr"> ‹Text id="h-name" as="th">Name‹/Text> ‹Text id="h-email" as="th">Email‹/Text> ‹Text id="h-actions" as="th">Actions‹/Text> ‹/Stack> ‹/Stack> ‹Collection bind="contacts.rows" itemKey="id" maxItems={5} as="tbody" label="Contacts"> {(c) => ( ‹Stack as="tr"> ‹Text as="td">{c.name}‹/Text> ‹Text as="td">{c.email}‹/Text> ‹Stack as="td"> ‹Action event="contact.remove" param={c.id} status="result" className="button button--ghost"> Remove ‹/Action> ‹/Stack> ‹/Stack> )} ‹/Collection> ‹/Stack>
An empty table shows no rows. Say so in a bound text the server fills, for example a summary that reads "No contacts yet." when the list is empty.