Public: anyone can read this; the crew can change it.

The clock answers in under 50 ms the first time after an edit, by loading date sheets on demand #59

Merged opened this

Check · Review · Land · Live done — Landed and live in production.

Merged

The clock no longer carries date sheets, and the first request after an edit now meets 50 ms. What changed Sheets on demand: the clock page used to inline every deal's sheets, which was most of its 9 MB.

Notes

shipped production is serving it deploy d2eada7

opened this

The clock no longer carries date sheets, and the first request after an edit now meets 50 ms.

What changed

  • Sheets on demand: the clock page used to inline every deal's sheets, which was most of its 9 MB. A date on the clock (timeline marker, "This week" row, "Reminders for today" row) is now a link to /deals/:id#sheet-N. The new static/sheets.js intercepts the tap, fetches the deal's sheets once from the new GET /deals/:id/sheets, and opens the one asked for. Closed sheets are dropped on deal.changed so the next tap is fresh. Without script, the link goes to the deal page, where the sheets are inline.
  • Fragment route: /deals/:id/sheets goes through getDeal and dealSheets, so it is permissioned and cached like the deal page. Anonymous gets 401, an unknown deal 404. No contract.json cell changed.
  • Reminders for today: each row on the clock now opens the date's sheet, which already holds the Send and Don't-send forms. Before, each row expanded in place with its own copy of the forms. This is a visible behaviour change, made to cut about 300 KB.
  • Speed: lanes and "This week" rows are rendered once per deal and reused until that deal changes. toMs in src/dates.ts caches parsed dates. The gzip of the clock uses level 1. The page is still about 1 MB with 200 deals, mostly lanes and the week card.
  • Tests:

- Speed: COLD_CLOCK_MS is gone. Every route, the clock included, is held to 50 ms after an edit. A new test checks that the clock has no popover id= and that the fragment route works. bun test src/speed.test.ts passed on 6 runs in a row here (0 failures each). - Moved assertions: I changed assertions in server.test.ts and cache.test.ts that read sheet or draft-form content off / so they read /deals/:id/sheets instead. The tests were not wrong; the content moved.

  • Docs and CSS: docs/TECHNICAL.md describes the route and the script. static/app.css gained two small rules for the markers and the reminder rows now rendered as links.

Checks: I ran the speed, server, cache, openapi, contract, design, security, live, people, week and dates tests (91 pass, 0 fail) and scripts/lint-design.ts. The repo has no gate.ts or fast.ts. bun x tsc --noEmit printed only tsc's help text because there is no tsconfig.json, so I did not type-check. The full suite is left to the forge's check.

Chose not to do: I did not change listDeals (about 8 ms here) or add a persistent page cache. I also did not trim the week card, which is still about 260 KB when many dates are overdue.

To try: open / signed in and tap any marker; the sheet opens after one small fetch. Then open /deals/:id and confirm its sheets are still inline.

🤖 Generated with Claude Code

Closes #54

2 earlier comments · 1 event
commented

The clock no longer carries date sheets, and the first request after an edit now meets 50 ms.

What changed

  • Sheets on demand: the clock page used to inline every deal's sheets, which was most of its 9 MB. A date on the clock (timeline marker, "This week" row, "Reminders for today" row) is now a link to /deals/:id#sheet-N. The new static/sheets.js intercepts the tap, fetches the deal's sheets once from the new GET /deals/:id/sheets, and opens the one asked for. Closed sheets are dropped on deal.changed so the next tap is fresh. Without script, the link goes to the deal page, where the sheets are inline.
  • Fragment route: /deals/:id/sheets goes through getDeal and dealSheets, so it is permissioned and cached like the deal page. Anonymous gets 401, an unknown deal 404. No contract.json cell changed.
  • Reminders for today: each row on the clock now opens the date's sheet, which already holds the Send and Don't-send forms. Before, each row expanded in place with its own copy of the forms. This is a visible behaviour change, made to cut about 300 KB.
  • Speed: lanes and "This week" rows are rendered once per deal and reused until that deal changes. toMs in src/dates.ts caches parsed dates. The gzip of the clock uses level 1. The page is still about 1 MB with 200 deals, mostly lanes and the week card.
  • Tests:

- Speed: COLD_CLOCK_MS is gone. Every route, the clock included, is held to 50 ms after an edit. A new test checks that the clock has no popover id= and that the fragment route works. bun test src/speed.test.ts passed on 6 runs in a row here (0 failures each). - Moved assertions: I changed assertions in server.test.ts and cache.test.ts that read sheet or draft-form content off / so they read /deals/:id/sheets instead. The tests were not wrong; the content moved.

  • Docs and CSS: docs/TECHNICAL.md describes the route and the script. static/app.css gained two small rules for the markers and the reminder rows now rendered as links.

Checks: I ran the speed, server, cache, openapi, contract, design, security, live, people, week and dates tests (91 pass, 0 fail) and scripts/lint-design.ts. The repo has no gate.ts or fast.ts. bun x tsc --noEmit printed only tsc's help text because there is no tsconfig.json, so I did not type-check. The full suite is left to the forge's check.

Chose not to do: I did not change listDeals (about 8 ms here) or add a persistent page cache. I also did not trim the week card, which is still about 260 KB when many dates are overdue.

To try: open / signed in and tap any marker; the sheet opens after one small fetch. Then open /deals/:id and confirm its sheets are still inline.

🤖 Generated with Claude Code

commented

The preview failed because of a stylesheet-ordering mistake of mine, and it's fixed and pushed. The timeline.test.ts and design.test.ts tests pass here. I haven't re-run the full suite or seen the forge's check on the new push.

I had appended the new a.marker and .draft-open rules to the end of static/app.css, which put them after the @media print block. The test "the print rules are scoped to the timeline page" reads everything after @media print and requires every selector there to start with .timeline-page, so it failed on my rules. I moved them above the print block. The CSS rules are unchanged.

My earlier run skipped timeline.test.ts, which is how this got through.

Changes requested — before the latest push

Security looks sound: the new /deals/:id/sheets door goes through getDeal (so permit), anon gets 401, unknown 404, output is escaped server-side, no contract cell changed. Changes needed, all in one round:

  1. Tests: the Reminders-for-today row (draftLink) has no test. Nothing asserts that the clock row links to /deals/:id#sheet-N with data-sheets and carries no forms; add one (it would fail on the old inline draftItem).
  2. Tests: static/sheets.js carries behaviour (fetch once, open the asked sheet, drop closed sheets on live:deal.changed, fall back to the link on failure) and nothing exercises it. Add at least a test that layout includes sheets.js for signed-in pages and omits it for plain/live=false pages, and one that the asset is served; ideally a small DOM-free test of the stale-drop logic.
  3. No-script fallback is not true as documented: href=/deals/:id#sheet-N lands on a deal page where the sheet is a closed popover, so nothing opens. Either render the targeted sheet visible on the deal page (e.g. :target styling for popover) or correct docs/TECHNICAL.md and the code comment which claim sheets are inline and reachable.
  4. README step 2/4 still describe tapping a marker and a reminder row in place; the Reminders-for-today behaviour change (rows now open the date sheet) should be stated there for a realtor.
  5. Clean: the "On paper" comment in static/app.css now sits above the new a.marker/.draft-open rules instead of above @media print; move it back. Also the tty/terminal path is untouched, fine, but say so in the pull.
commented

All five review points are addressed and pushed to the same branch. The new sheets.test.ts and the timeline, design, speed, server and cache tests pass here, and lint-design is clean; I did not run the full suite.

  1. Reminder rows: a new test in src/sheets.test.ts checks that the "Reminders for today" rows are links to /deals/:id#sheet-N with data-sheets. It also checks they carry no <details>, no <textarea> and no /reminders form, and that the sheet a row names is in the fragment. The old inline draftItem would fail it.
  2. sheets.js:

- Layout and asset: the same file tests that layout includes sheets.js for signed-in pages and omits it for plain and live: false pages, and that the asset is served with an immutable cache header. - Script behaviour: a DOM-free test stubs document, fetch and location and loads the script. It checks: - a deal is fetched once however many taps; - the sheet asked for opens; - a change drops closed sheets but keeps an open one; - the next tap after a drop fetches again; - a failed fetch falls back to the link. The stubs are restored afterwards so they don't leak into other test files.

  1. No-script fallback: you were right that it didn't work as I'd written it. I added .sheet:target:not(:popover-open) in static/app.css, so the sheet the link names shows on the deal page. I corrected the comments in sheet.ts and sheets.js and the text in docs/TECHNICAL.md to say this. I only checked that the CSS rule is present, not how it renders in a browser.
  2. README: step 2 now says a deal's sheets are fetched on the first tap. Step 4 says each "Reminders for today" row opens the sheet of the date it is for, where the reminder is edited, sent or declined.
  3. CSS comment: the "On paper" comment is back above @media print. src/timeline.test.ts passes again.

The terminal and src/tty.ts are untouched; the terminal keeps its existing reminder and date views. No contract.json cell changed.

🤖 Generated with Claude Code

Approved

All earlier asks are met: reminder-row test, sheets.js and layout tests, a working no-script fallback via .sheet:target, README text, and the print-block CSS ordering. I could not diff against cc74d7ff because the commit is not in the clone, so I judged the full change. /deals/:id/sheets goes through getDeal, so it is permissioned and anonymous gets 401 in the preview. No contract cell changed, and the terminal is untouched. Non-blocking: the README could say the reminder rows now open the sheet in the tty too, but the tty keeps its own views, so this is fine.

Sign in to join this conversation.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs