Repository navigation
feat(preview): block link navigation in live-preview routes - #49
Merged
Merged
Conversation
Editors working in the SahajCloud live-preview iframe lost their session whenever they clicked a link, because preview routes render the real site components (rich-text links, nav, cards, breadcrumbs) and every link is genuine navigation. Add a capture-phase click/auxclick guard, mounted only while <Preview> renders, that blocks anchor navigation across the whole preview tree — including the Header/Footer chrome LayoutChrome renders outside <Preview>. Same-page hash links (#heading) still scroll; buttons and media controls (play/pause, captions, embed dropdown) and the message-based live-preview / seek sync are untouched. Because Vike's client router listens in the bubble phase and ignores defaultPrevented, the guard runs in the capture phase and calls both preventDefault() and stopPropagation(). Refs #46 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Refs #46 Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
Deploying wemeditate-design with
|
| Latest commit: |
e4d3dff
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://fd1dfbe8.wm-design.pages.dev |
| Branch Preview URL: | https://feat-preview-block-link-navi.wm-design.pages.dev |
Deploying with
|
| Status | Name | Latest Commit | Preview URL | Updated (UTC) |
|---|---|---|---|---|
| ✅ Deployment successful! View logs |
wemeditate-web | e4d3dff | Commit Preview URL Branch Preview URL |
Jun 30 2026, 10:29 AM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
/previewand/preview/embed) inert so editors don't navigate the SahajCloud preview iframe away from the document they're editing.#heading) still scroll;<button>and media controls (play/pause, captions, embed dropdown) and the message-based live-preview/seek sync are untouched.<Preview>renders.Changes
pages/preview/_components/previewNavigation.ts(new) —shouldBlockPreviewLink(href)predicate (block everything except#hash/href-less anchors) +usePreviewLinkGuard()hook that installs capture-phaseclick/auxclicklisteners onwindowand callspreventDefault()+stopPropagation()on blocked anchors.pages/preview/_components/Preview.tsx— callsusePreviewLinkGuard()once at the top of the sharedPreviewcomponent (rendered by both preview routes).pages/preview/_components/previewNavigation.test.ts(new) — unit tests for the decision logic.Why a
window-capture listener +stopPropagation()Vike's client router listens for link clicks on
documentin the bubble phase and does not checkevent.defaultPrevented(initOnLinkClick.js). SopreventDefault()alone wouldn't stop Vike's client-side navigation. A capture-phase listener onwindowis the first node in the event path, sostopPropagation()there halts all further propagation and the event never reaches Vike'sdocumenthandler;preventDefault()additionally blocks native navigation and middle-click/modifier "open in new tab" (viaauxclick). A single document-level interceptor also covers the Header/Footer nav thatLayoutChromerenders outside<Preview>, without threading adisabledprop through every link-rendering component.Test Results
pnpm lint)pnpm exec tsc --noEmit)pnpm test:run)pnpm build)Manual verification
Open the SahajCloud live preview for a page, a meditation, and a lecture, in both
/previewand/preview/embed:#headinglink → still scrolls within the document.Notes for reviewer
shouldBlockPreviewLinkdecision logic. The DOM wiring (capture phase,auxclick, Vike interaction) isn't unit-tested because the project runs Vitest innodewith no jsdom — it's covered by the manual steps above./simplifypass suggested moving the hook into a dedicated preview layout. Kept it inline inPreviewbecause this repo's layouts are config-driven (Layout:in+config.ts) with a deliberate(full)vsembedchrome split; a guard layout would add routing machinery/risk for a one-line effect, andPreviewis the single shared mount point both routes already render.stopPropagation(), clicking an<a>inside an open dropdown won't auto-close that dropdown in preview (Floating UI's outside-press dismiss never sees the click). Navigation is still correctly blocked, the EmbedButton dropdown has no anchors so it's unaffected, and clicking elsewhere still closes it. Not worth complicating the guard.Closes #46
🤖 Generated with Claude Code