Architecture decision record · ADR-0011

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.

Status
Accepted
Deciders
Joe Gaudet
Created
Updated
PRD
PRD
Related
None

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

  1. 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. applyGridState writes each slice through its feature setter (setSorting and the others), so a controlled slice owner gets the change. The package uses a structural TableLike type and imports only types from core.
  2. Migrations go one version at a time. migrations[v] changes a state from version v to v + 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.
  3. The first layer wins as a whole. resolveState takes 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.
  4. Stores keep only the keys that are not default. The defaults are the state of the grid when persistGridState starts, before any load.
  5. 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.
  6. The URL store has no dependency on Ember or Joinery. Joinery qp is a template helper that reads router.currentRoute.queryParams[name]. The store does that same read on a structural router type, and writes through router.replaceWith. Without a router, it uses history.replaceState.
  7. A server save is personal. serverStore.save (the automatic save) writes only the personal view of the current view name. Only an explicit saveView with scope: 'shared' writes a shared view. A save to a locked view must set locked, so the automatic save never changes a locked view.
  8. persistGridState is 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.warn through an option, because the package does not depend on @embroider/macros. When that dependency is added, wrap the default in isDevelopingApp().
  • 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 a GridStateHandle (packages/ember/src/grid/state-host.ts). It has the shape of GridStateHost, with no import of the state package.
    • Make the handle before the grid renders. Give it to @stateHost of the grid and to persistGridState({ 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.

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.

QuestionAnswerSource
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

DateAuthorChange
2026-12-01Joe GaudetStatus in the Markdown file: accepted, 2026-12-01.
2026-12-03Joe GaudetCommit 7ce4af2: Lattice 1.0 (#1)
2026-12-04Joe 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.