From c2d5673d9be00b78fddf491e4932d714622f8473 Mon Sep 17 00:00:00 2001 From: "prompt.ac/@jeffrey" Date: Mon, 7 Sep 2026 20:16:58 -0400 Subject: [PATCH] confessional margins: the comment button learns which page it is on MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The comment prefill fell back to the feed index — which counts pages and questions together — whenever the lazy page cache had no entry, so the ref pointed at the wrong page. Read the feed item map instead, which is built whole at boot with the true page and question numbers. And a leftover bare ref from an earlier open now gets replaced by the page in view; only a real typed draft survives. Claude-Session: https://claude.ai/code/session_01FryvSZ4bmGcpc7q13FNaCj --- system/netlify/functions/sotce-net.mjs | 33 +++++++++++++++++++------- 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/system/netlify/functions/sotce-net.mjs b/system/netlify/functions/sotce-net.mjs index e323d0afcd..8a84a24543 100644 --- a/system/netlify/functions/sotce-net.mjs +++ b/system/netlify/functions/sotce-net.mjs @@ -5382,12 +5382,16 @@ export const handler = async (event, context) => { // Trigger layout update for canvas/editors setTimeout(() => computePageLayout?.(), 50); // Opening from the button reads as commenting on the page in - // view — prefill its reference, as if its number was tapped. - // An explicit prefill (page number, @mention) or a typed - // draft wins over the default. + // view — always prefill its reference, as if its number was + // tapped. A leftover bare ref from an earlier open gets + // replaced; only a real typed draft survives. An explicit + // prefill (tapped page number, @mention) still wins. if (!suppressAutoRef) { const ref = currentPageRef?.(); - if (ref && !chatInput.value.trim()) prefillChatInput(ref); + const existing = chatInput.value.trim(); + if (ref && (existing === "" || /^[pq]\\d+$/.test(existing))) { + prefillChatInput(ref); + } } suppressAutoRef = false; }; @@ -8665,12 +8669,23 @@ export const handler = async (event, context) => { }; currentPageRef = function () { - const pageData = pageCache.get(displayedPageIndex); - const isQuestion = pageData?.type === "question"; + // feedItemMap is built whole at boot with true page and + // question numbers; pageCache holds lazily fetched raw + // docs that may lack them. Falling back to the feed index + // was wrong — it counts pages and questions together. + const item = + feedItemMap.get(currentPageIndex) || + pageCache.get(currentPageIndex); + if (!item) return "p" + currentPageIndex + " "; + const isQuestion = item.type === "question"; const displayNum = isQuestion - ? pageData?.questionNumber || displayedPageIndex - : pageData?.pageNumber || displayedPageIndex; - return (isQuestion ? "q" : "p") + displayNum + " "; + ? item.questionNumber + : item.pageNumber; + return ( + (isQuestion ? "q" : "p") + + (displayNum || currentPageIndex) + + " " + ); }; canvas.style.touchAction = "none"; -- 2.51.2