Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EFUzfiCVCgCVJZq4NDEqZs
2.5 KiB
2.5 KiB
Context
See docs/superpowers/specs/2026-12-03-page-anchor-links-design.md. Blocks are one JSON column on cms_page; services-counter validates them; mobile-api passes them through as maps; the portal renders them. Custom HTML runs in an opaque-origin frame (allow-scripts allow-popups allow-popups-to-escape-sandbox) whose injected script already posts height reports, which HtmlFrame accepts only from its own contentWindow.
Goals / Non-Goals
Goals: named block targets; #name links from buttons, rich text and Custom HTML.
Non-Goals: automatic ids; any new frame permission; scroll offsets for a sticky header (the public page has none).
Decisions
- Field
anchoron the block, pattern^[a-z0-9][a-z0-9-]{0,39}$, unique per page. Stored in the blocks JSON, so no DDL. Refusal codes:PagesBadAnchor,PagesAnchorTaken. - Link rule.
#plus the same pattern is a safe link everywhere a link is checked:CmsBlockValidator.safeLink,isSafeLink, the editor'sSAFE_LINK, and the sanitiser (sanitize-html already keeps scheme-less hrefs; a test pins it). - Ids. The block wrapper in
CmsBlocksgetsid={anchor}for every type, the HTML frame included. Rendered only when the name matches the pattern, so rows written another way cannot inject odd ids. - Frame bridge. The injected script adds one click listener: for
a[href^="#"]with a valid name it prevents the default and posts{type:"colite-frame-anchor", name, y}, whereyis the in-frame element's document offset ornull.HtmlFramechecks the source window as for heights, validates the message in a pureframeAnchor()helper, then scrolls the window toframe top + y, or todocument.getElementById(name), else ignores it. Smooth scroll. - Messages are data only. The page never navigates or evaluates anything from a frame message; it only scrolls.
Risks / Trade-offs
- A frame script could post anchor requests at will → it can only scroll its own page, which it could already make tall. Accepted.
- A link name equal to an id the portal already uses on that page (e.g.
main) would clash → the public page renders no ids of its own apart from block anchors; the preview shell may, so only behaviour on the public page is specified. - Pages saved by an older release lose link names → only on rollback; noted in the proposal.
Migration Plan
Deploy services-counter and the portal; run sql/01-anchor-labels.sql. Rollback: previous images and sql/99-rollback.sql.