From f8cc504c8bd40c64029137a3d72be3f9b4dd47f0 Mon Sep 17 00:00:00 2001 From: James Briggs <35938317+jamescalam@users.noreply.github.com> Date: Sun, 15 Nov 2026 16:22:32 +0800 Subject: [PATCH 1/2] Sheets: a whole page pushed again with the same data draws the sheet again MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The platform's morph lays a pushed page's source over what the page's script drew wherever it can't tell them apart: the status line and the cell's address always, and with no earlier page to compare against, the grid, the tabs and the charts too. A page whose data block changed was read again and drawn; one whose data was the same (a save straight after a push of the same page, which happens whenever data.json keeps its saved_at, or a new description only) was left as the morph made it: "Loading…" in the status line, "A1" as the address, and in the worst case an empty grid. The "ss:live" listener now draws again, where the person is, after any whole page with the same data, and still applies a batch once. Co-authored-by: Pointman Co-authored-by: Claude --- sheets/references/sheet-template.html | 14 +++++++---- tests/live.js | 36 ++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 6 deletions(-) diff --git a/sheets/references/sheet-template.html b/sheets/references/sheet-template.html index 75d6399..473444f 100644 --- a/sheets/references/sheet-template.html +++ b/sheets/references/sheet-template.html @@ -1309,14 +1309,18 @@

SHEET TITLE

placing = true; render(); select(state.sel); if (i >= 0) putBack(p); if (drafting()) { state.refocus = true; renderBar(); } placing = false; keepPlace(); } + // A whole page with the same data (a save straight after a push, a new description) still lays the page's source + // over what this script drew: the status line and the cell's address, and with no earlier page to compare against, + // the grid, tabs and charts too. So it's all drawn again, where the person is. + function redraw() { var p = kept; placing = true; render(); select(state.sel); if (p) putBack(p); placing = false; keepPlace(); } // A batch the agent pushes while it builds replaces #sheet-delta, and the page's "ss:live" event names // it. It lands outlined, on its own tab unless the person picked one. document.addEventListener("ss:live", function (e) { - var ids = (e.detail && e.detail.ids) || []; - if (ids.indexOf("sheet-data") >= 0 && text("sheet-data") !== dataText) return retake(); - if (ids.indexOf("sheet-delta") < 0 || text("sheet-delta") === deltaText) return; - deltaText = text("sheet-delta"); - if (/^\s*(\{\s*\})?\s*$/.test(deltaText)) return; // emptied by a whole-page update: nothing to draw + var ids = (e.detail && e.detail.ids) || [], whole = ids.indexOf("sheet-data") >= 0; // a whole page names every block + if (whole && text("sheet-data") !== dataText) return retake(); + var batch = ids.indexOf("sheet-delta") >= 0 && text("sheet-delta") !== deltaText; + if (batch) deltaText = text("sheet-delta"); + if (!batch || /^\s*(\{\s*\})?\s*$/.test(deltaText)) { if (whole) redraw(); return; } // no new batch (one a whole page emptied included) var r = E.applyDelta(data, deltaText); if (!r.ok) { var st = document.getElementById("status"); st.textContent = "A batch of cells wasn't shown: " + r.why + "."; st.className = "status err"; return; } var now = Date.now(), tn = r.tab.toLowerCase(); diff --git a/tests/live.js b/tests/live.js index 3ad7fbd..77685dd 100644 --- a/tests/live.js +++ b/tests/live.js @@ -73,10 +73,44 @@ module.exports = function ({ E, test, script, PAGE, ROOT }) { const ui = script("sheet-ui"); assert.match(ui, /function text\(id\) \{ var n = document\.getElementById\(id\); return n \? n\.textContent : ""; \}/); assert.match(ui, /data = JSON\.parse\(dataText\)/); - assert.match(ui, /if \(ids\.indexOf\("sheet-data"\) >= 0 && text\("sheet-data"\) !== dataText\) return retake\(\);/); + assert.match(ui, /whole = ids\.indexOf\("sheet-data"\) >= 0;/); + assert.match(ui, /if \(whole && text\("sheet-data"\) !== dataText\) return retake\(\);/); for (const id of ["sheet-engine", "sheet-ui"]) assert.doesNotMatch(script(id), /innerHTML|outerHTML|insertAdjacentHTML|document\.write|new Function|\beval\(/, id); assert.doesNotMatch(PAGE.match(/]*>/)[0], /disabled/); // a whole-page update never disables the bar someone types in }); + // Wherever the morph can't tell the pushed page's source from what the page's script drew, it puts the source back: + // always the status line and the cell's address; also the grid, tabs and charts when it has no earlier page to + // compare against. So a whole page with the same data (a save straight after a push of the same page) must still + // make the page draw again. This runs the page's own "ss:live" listener with the blocks as each kind of update + // leaves them. + test("after a whole page with the same data, the page draws again where the person is", () => { + const ui = script("sheet-ui"); + const src = /document\.addEventListener\("ss:live", (function \(e\) \{[\s\S]*?\n \})\);/.exec(ui)[1]; + const DATA = JSON.stringify(sheet()), ALL = ["title", "lede", "what-changed", "sheet-data", "sheet-delta"]; + function live(blocks, detail, was = { data: DATA, delta: "{}" }) { + const calls = [], d = JSON.parse(DATA), state = { ver: 0, sel: "B3", picked: true, draft: null, tab: 1 }; + const on = new Function("text", "retake", "redraw", "render", "select", "E", "data", "state", "stamps", "dataText", "deltaText", "savedAt", "return " + src)( + (id) => blocks[id], () => calls.push("retake"), () => calls.push("redraw"), () => calls.push("render"), () => {}, E, d, state, {}, was.data, was.delta, 0); + on({ detail }); + return { calls, d }; + } + const same = { "sheet-data": DATA, "sheet-delta": "{}" }; + // the save of the very page the last push drew, or a page with only a new description: drawn again + assert.deepStrictEqual(live(same, { mode: "morph", ids: ALL }).calls, ["redraw"]); + assert.deepStrictEqual(live(same, { mode: "stream", ids: ALL }).calls, ["redraw"]); + // a whole page that empties a batch block the page had drawn: drawn again, the batch not applied twice + assert.deepStrictEqual(live(same, { mode: "morph", ids: ALL }, { data: DATA, delta: '{"tab":"Budget","cells":{"A2":"x"}}' }).calls, ["redraw"]); + // a whole page with new data: read again (which draws) + const moved = JSON.parse(DATA); moved.tabs[0].cells.B2 = 5; + assert.deepStrictEqual(live({ "sheet-data": JSON.stringify(moved), "sheet-delta": "{}" }, { mode: "morph", ids: ALL }).calls, ["retake"]); + // a batch: applied and drawn once, not drawn again on top + const b = live({ "sheet-data": DATA, "sheet-delta": JSON.stringify({ tab: "Budget", cells: { A2: "Rent", B2: 1200 } }) }, { mode: "patch", ids: ["sheet-delta"] }); + assert.deepStrictEqual(b.calls, ["render"]); + assert.strictEqual(b.d.tabs[0].cells.B2, 1200); + // an update that names neither block (a save that changed only the title), or a batch already drawn: nothing drawn + assert.deepStrictEqual(live(same, { mode: "diff", ids: ["title"] }).calls, []); + assert.deepStrictEqual(live(same, { mode: "patch", ids: ["sheet-delta"] }).calls, []); + }); test("a person's typing and place outlast a batch, a rewrite and a reload", () => { const ui = script("sheet-ui"); From 497b732c556c9aa73274f62a3d65dd886493ea4b Mon Sep 17 00:00:00 2001 From: James Briggs <35938317+jamescalam@users.noreply.github.com> Date: Sun, 15 Nov 2026 16:33:24 +0800 Subject: [PATCH 2/2] Changelog: v2.0.2 Co-authored-by: Pointman Co-authored-by: Claude --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index f4eac8a..538b570 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ Each release is a heading with its tag. The release workflow uses the words under it as the release's notes. +## v2.0.2 + +- A sheet that's open while it's built ends showing the right status line and cell. Before, when the last push and the save sent the same page, the status line went back to "Loading…" and the cell's address to A1. The same happened after a push that changed only the description, and in a tab that had nothing to compare the page with, the grid, tabs and charts emptied. The page now draws again, where the person is, after every whole page. +- The folder's hash is `4d046be9c48c`. + ## v2.0.1 - On a phone the sheet starts on the first screen. The description folds to two lines with "more", and the two downloads sit under one Download button.