Skip to content

Fix Sandpack navigation for internal markdown links - #9

Merged
emilio-balda merged 1 commit into
mainfrom
fix/internal-links
Sep 7, 2026
Merged

emilio-balda merged 1 commit into
mainfrom
fix/internal-links

Conversation

@emilio-balda

Copy link
Copy Markdown
Collaborator

Problem

Internal concept links rendered from markdown bodies (e.g. [agent second brain](/projects/second-brain.md)) worked in normal Vite rendering but broke in the Sandpack viewer: clicking them navigated to a https://bundler.sandbox.animaapp.com/<path> URL instead of switching the in-app selection.

The "Cited by" backlinks worked fine in both environments because they're rendered as <button> elements with no href.

Root cause

Detail.jsx's MarkdownLink rendered internal links as <a href={href} onClick={...preventDefault...}>. In normal rendering preventDefault() is sufficient. Inside Sandpack's preview iframe, the sandbox's own runtime intercepts anchor clicks and resolves the anchor's real href against its own bundler origin, independent of our preventDefault() call — producing the broken bundler URL.

Fix

Internal (resolved) links now use href="#" instead of the real markdown path, mirroring the already-working hrefless <button> pattern used for backlinks. onSelect() still drives navigation via the onClick handler; the sandbox now has no real path to intercept and navigate to. External links are unaffected.

Testing

  • npm test (22/22 passing), including an updated assertion in Detail.test.js for the new href="#" internal link markup.

Made with Cursor

Sandpack's preview iframe intercepts real anchor clicks and resolves
the href against its own bundler origin, even though the onClick
handler already calls preventDefault(). Internal concept links now
use href="#" (matching the hrefless <button> pattern already used
for backlinks) so the sandbox has nothing real to navigate to, while
onSelect() still drives in-app navigation.

Co-authored-by: Cursor <cursoragent@cursor.com>
Copilot AI lite review requested due to automatic review settings September 7, 2026 08:44
@emilio-balda emilio-balda self-assigned this Sep 7, 2026
@emilio-balda
emilio-balda merged commit 2b811fa into main Sep 7, 2026
1 check passed

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

The change is narrowly scoped to internal link rendering, aligns with the stated Sandpack root cause, and includes an updated test assertion covering the new markup.

Pull request overview

This PR fixes internal markdown link navigation inside the Sandpack preview by preventing Sandpack from resolving “real” internal href values against its bundler origin, while still allowing in-app navigation via onSelect().

Changes:

  • Render resolved internal markdown links with href="#" (instead of the markdown path) and keep navigation driven by the click handler.
  • Update the Detail rendering test assertion to match the new internal link markup.
File summaries
File Description
src/Detail.jsx Changes internal markdown link rendering to use href="#" to avoid Sandpack iframe navigation interception while still calling onSelect(target).
src/Detail.test.js Updates expected HTML to assert the new internal link href="#" output.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants