From 3d89eb311866a52a24075d201c0d4b4724e128db Mon Sep 17 00:00:00 2001 From: ngqile Date: Thu, 3 Dec 2026 20:06:57 +0800 Subject: [PATCH] fix(pages): a short Custom HTML block shrinks to its content height scrollHeight inside the frame never drops below the frame's own 600 px start height, so a top bar left a large blank gap. The frame script now reports the content box height. Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs --- solvway-admin-portal/app/lib/frameHtml.anchor.test.ts | 11 +++++++++++ solvway-admin-portal/app/lib/frameHtml.ts | 4 ++-- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/solvway-admin-portal/app/lib/frameHtml.anchor.test.ts b/solvway-admin-portal/app/lib/frameHtml.anchor.test.ts index 0cbd446..0e2b925 100644 --- a/solvway-admin-portal/app/lib/frameHtml.anchor.test.ts +++ b/solvway-admin-portal/app/lib/frameHtml.anchor.test.ts @@ -37,3 +37,14 @@ describe("frame script: same-page links", () => { expect(post.mock.calls.filter(([d]) => (d as { type: string }).type === "colite-frame-anchor")).toHaveLength(0); }); }); + +describe("frame script: height report", () => { + it("reports the content's height, not the frame's own, so a short block can shrink below its start height", () => { + const post = vi.spyOn(window.parent, "postMessage").mockImplementation(() => {}); + const root = document.documentElement; + vi.spyOn(root, "scrollHeight", "get").mockReturnValue(600); + vi.spyOn(root, "getBoundingClientRect").mockReturnValue({ height: 69.4 } as DOMRect); + runFrameScript("
Top bar
"); + expect(post).toHaveBeenCalledWith({ type: "colite-frame-height", height: 70 }, "*"); + }); +}); diff --git a/solvway-admin-portal/app/lib/frameHtml.ts b/solvway-admin-portal/app/lib/frameHtml.ts index 22808d6..04307d8 100644 --- a/solvway-admin-portal/app/lib/frameHtml.ts +++ b/solvway-admin-portal/app/lib/frameHtml.ts @@ -15,10 +15,10 @@ export const FRAME_ANCHOR_MESSAGE = "colite-frame-anchor"; const ANCHOR_SOURCE = "^(?!reg-)[a-z0-9][a-z0-9-]{0,39}$"; const ANCHOR = new RegExp(ANCHOR_SOURCE); -// Posts the document height to the parent page on load and whenever it changes. A click on a #name link +// Posts the content height (not scrollHeight, which never drops below the frame itself) to the parent page on load and whenever it changes. A click on a #name link // (add-page-anchor-links) asks the page to scroll instead: the frame is as tall as its content and never scrolls. const FRAME_SCRIPT = - `