Repository navigation
Description
Summary
When an editor is working in the SahajCloud live-preview iframe (/preview and /preview/embed), clicking any link inside the rendered content navigates the iframe away from the document being edited — breaking the live-preview session and forcing the editor to reopen the preview. We want preview mode to be read-only for navigation: every link on screen should be visually present but inert, so editors can scroll and read without accidentally leaving the previewed page.
Background
Preview routes render the same components as the live site — rich-text links and inline relationships go through the Link atom (RichText.tsx:120-166), and the full-chrome /preview route also renders nav/header/footer links via LayoutChrome. Because links come from many components (Link atom, Button-as-link, Breadcrumbs, social icons, cards), the robust fix is a single capture-phase click interceptor scoped to the preview tree, rather than threading a "disabled" prop through every component.
Proposed changes
1. Intercept anchor clicks within the preview subtree
Add a capture-phase click handler in the Preview component (covering both /preview and /preview/embed, which both render <Preview>). The handler finds the nearest <a> ancestor of the event target via event.target.closest('a') and, if one exists, calls event.preventDefault() so navigation is blocked. Middle-click / cmd-click open-in-new-tab should also be suppressed (handle via auxclick or by clearing on capture).
2. Keep the rest of the page interactive
Only <a> navigation is blocked. Buttons and media controls (meditation play/pause, captions, etc.) must keep working, since those drive the preview itself (e.g. PLAYBACK_TIME_UPDATE). Do not block <button> elements.
3. Allow same-page anchor links; block everything else
Same-page anchor links (href starting with #, e.g. table-of-contents jumps) must continue to work so editors can scroll within the document. Block every other <a> click — internal route links, external (target="_blank"), etc. Detect via the anchor's getAttribute('href') (or comparing pathname to the current location) so a #heading link is left alone while a real navigation is prevented.
Acceptance criteria
- In
/preview(full chrome), clicking a rich-text link, a nav link, a card, or a breadcrumb does not navigate; the URL bar / iframe stays on the preview document - In
/preview/embed, the same links are inert - Same-page anchor links (
href="#...") still scroll to their target within the preview - Cmd/Ctrl-click and middle-click on a (non-anchor) link do not open a new tab
- Buttons and media controls (play/pause, captions, embed button) still function
- The live
useLivePreviewcontent updates andpostMessageseek sync are unaffected - No effect on the normal site — non-preview routes navigate exactly as before
-
pnpm lint,pnpm exec tsc --noEmit,pnpm test:runall pass
Files affected
pages/preview/_components/Preview.tsx— add capture-phase click/auxclick interceptor (likely via a smalluseEffectwrapper or a<div onClickCapture>container)- (maybe)
pages/preview/_components/index.ts— if the interceptor is extracted to a small helper/hook
References
- Preview architecture: pages/preview/README.md
- Link atom: components/atoms/Link/Link.tsx
- Rich-text link rendering: RichText.tsx:120-166
Metadata
Metadata
Assignees
Labels
Type
Fields
Hold Until
Activity
feat(preview): block link navigation in live-preview routes (#49)