State and views (milestone M5)
The state is JSON with a version. gridState(table, host?) reads the table slices from table.store.state through an allowlist of 11 keys, and the Grid keys (scroll, activeCell) through a GridStateHost.
Context
Decision 17 of the plan keeps grid state in three places: the URL, localStorage and saved views
on a server. All three use one StateStore interface. Plan section 6 sets the precedence (URL,
personal view, shared view, column defaults) and the migration rule: old state migrates or drops
one key at a time, never the full state. Notion, Airtable and Linear (research section 7) show
the view patterns: personal and shared views, locked views, "save for everyone" as an explicit
action, and a view that a URL can share.
Decision drivers
Not recorded in the original ADR.
Options considered
Not recorded in the original ADR.
Decision
- The state is JSON with a version.
gridState(table, host?)reads the table slices fromtable.store.statethrough an allowlist of 11 keys, and the Grid keys (scroll,activeCell) through aGridStateHost.applyGridStatewrites each slice through its feature setter (setSortingand the others), so a controlled slice owner gets the change. The package uses a structuralTableLiketype and imports only types from core. - Migrations go one version at a time.
migrations[v]changes a state from versionvtov + 1. After the upgrade, a check for each key drops an unknown key or a bad value, with a warning. The allowlist also stops__proto__. The check is the trust boundary for the URL, localStorage and the server. - The first layer wins as a whole.
resolveStatetakes the first layer that is available (URL, then personal view, then shared view), and fills its missing keys from the defaults. It does not merge the layers key by key. With a merge, a link that sets only a sort would also get the personal filter of the reader, and the link would not show the view of the sender. A key that a migration drops thus goes back to its default. - Stores keep only the keys that are not default. The defaults are the state of the grid
when
persistGridStatestarts, before any load. - The URL encoding is short and stable. The URL holds JSON with one-letter top-level keys and sorted object keys, as base64url with no padding. A typical state is 346 characters. The one-letter names must never change, because old links use them.
- The URL store has no dependency on Ember or Joinery. Joinery
qpis a template helper that readsrouter.currentRoute.queryParams[name]. The store does that same read on a structural router type, and writes throughrouter.replaceWith. Without a router, it useshistory.replaceState. - A server save is personal.
serverStore.save(the automatic save) writes only the personal view of the current view name. Only an explicitsaveViewwithscope: 'shared'writes a shared view. A save to a locked view must setlocked, so the automatic save never changes a locked view. persistGridStateis a function, not a helper or a modifier. A helper runs during the render, and a write there causes the backtracking error. The caller runs the function before the render (in the constructor of the owner of the table). A sync store applies at once. An async store applies when it resolves, unless the user changed the grid before that. Each save waits for a timer, so no save occurs during a render.
Consequences
- The dev warnings use
console.warnthrough an option, because the package does not depend on@embroider/macros. When that dependency is added, wrap the default inisDevelopingApp(). - An app route must declare the query param for the router path of
urlStore. - The Grid persists the scroll offset and the active cell through a host.
LatticeGrid.stateHost()returns aGridStateHandle(packages/ember/src/grid/state-host.ts). It has the shape ofGridStateHost, with no import of the state package.- Make the handle before the grid renders. Give it to
@stateHostof the grid and topersistGridState({ host }). read()gives the scroll offset from the offset of the row and column virtualizers (scrollOffset), and the active cell as a row ID and a column ID.- A state that
apply()receives before the grid renders waits in the handle. The grid applies it when it attaches. If the grid detaches, the handle keeps the last state. - The grid calls
notify()on each scroll event and on each change of the active cell. apply()finds the active row by a linear search of the rows. With a row model, it searches only the loaded rows.
- Make the handle before the grid renders. Give it to
Confirmation
Not recorded in the original ADR.
Interview record
Each question of the interview with its answer and its source. A fact from the code or a document, a question that the author did not ask, and an assumption are rows too.
| Question | Answer | Source |
|---|---|---|
| Where does the text of this page come from? | From the Markdown file docs/adr/0011-state-and-views.md at commit 4c77ac4. The text of each section is the text of the Markdown file. A section that the Markdown file does not have says so. | Document: docs/adr/0011-state-and-views.md |
Changelog
| Date | Author | Change |
|---|---|---|
| 2026-12-01 | Joe Gaudet | Status in the Markdown file: accepted, 2026-12-01. |
| 2026-12-03 | Joe Gaudet | Commit 7ce4af2: Lattice 1.0 (#1) |
| 2026-12-04 | Joe Gaudet (agent) | Converted from docs/adr/0011-state-and-views.md to this page. The text is the text of the Markdown file. |
The adr skill of skillsaw wrote this page. The HTML in this file is the source of truth. The diagrams are the Mermaid sources in it.