Skip to content

fix: enable linked doc navigation in annotate mode#276

Merged
backnotprop merged 1 commit intobacknotprop:mainfrom
dgrissen2:fix/linked-doc-annotate-mode
Mar 12, 2026
Merged

fix: enable linked doc navigation in annotate mode#276
backnotprop merged 1 commit intobacknotprop:mainfrom
dgrissen2:fix/linked-doc-annotate-mode

Conversation

@dgrissen2
Copy link
Contributor

Summary

  • Bug: Clicking .md links in annotated files (e.g., [37% IQM](comparison_iqm_37.md)) showed "Failed to connect to server" because the annotate server had no /api/doc endpoint — requests fell through to the SPA catch-all, returning HTML instead of JSON.
  • Root cause: The /api/doc handler (handleDoc) was only registered in the plan server (packages/server/index.ts), not the annotate server (packages/server/annotate.ts).
  • Fix: Three targeted changes:
    1. annotate.ts — Add /api/doc route, auto-injecting the source file's parent directory as ?base= so relative sibling links (e.g., comparison_iqm_37.md from plots/gamma_segments/comparison_iqm_35.md) resolve from the correct location
    2. reference-handlers.tshandleDoc() now accepts an optional ?base= query param and tries resolving relative to it before falling back to the project-root glob search
    3. App.tsxhandleOpenLinkedDoc passes the current file's directory as ?base= when navigating linked-doc → linked-doc, so chained relative links also resolve correctly

Test plan

  • plannotator annotate a markdown file that contains relative .md links to sibling files
  • Click a .md link — linked doc should load in-place with back button
  • From the linked doc, click another .md link — should resolve relative to that doc's directory
  • Click back — should return to the original annotated file
  • Plan server linked doc navigation still works (no regression)

🤖 Generated with Claude Code

The annotate server was missing the /api/doc endpoint, so clicking
.md links (e.g., [see other](sibling.md)) in annotated files showed
"Failed to connect to server" — the request fell through to the SPA
catch-all and returned HTML instead of JSON.

Three changes:

1. annotate.ts — Add /api/doc route, auto-injecting the source
   file's parent directory as ?base= so relative links resolve
   from the correct location.

2. reference-handlers.ts — handleDoc() now accepts an optional
   ?base= query param and tries resolving relative paths against
   it before falling back to the project-root glob search.

3. App.tsx — handleOpenLinkedDoc passes the current file's
   directory as ?base= when navigating linked-doc → linked-doc,
   so chained relative links resolve correctly.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@backnotprop
Copy link
Owner

Code review

Found 1 issue:

  1. imageBaseDir is referenced but never defined in App.tsx. It is not declared as state, a prop, an import, or a constant anywhere in the file. This will cause a ReferenceError at runtime when a user clicks a relative .md link in annotate mode and linkedDocHook.filepath is null (i.e., the first navigation from the root annotated file). The fallback imageBaseDir is always undefined, so if (baseDir) is false, and the code falls through to linkedDocHook.open(docPath) without any ?base= param — defeating the relative path resolution for the initial hop. It appears the intent was to capture filePath from the /api/plan response (which annotate.ts already sends at line 121) into component state, but that wiring is missing.

} else {
// Pass the current file's directory as base for relative path resolution
const baseDir = linkedDocHook.filepath
? linkedDocHook.filepath.replace(/\/[^/]+$/, '')
: imageBaseDir;
if (baseDir) {
linkedDocHook.open(docPath, (path) =>
`/api/doc?path=${encodeURIComponent(path)}&base=${encodeURIComponent(baseDir)}`
);
} else {
linkedDocHook.open(docPath);
}
}
}, [vaultBrowser.activeFile, vaultPath, linkedDocHook, buildVaultDocUrl, imageBaseDir]);

🤖 Generated with Claude Code

- If this code review was useful, please react with 👍. Otherwise, react with 👎.

@backnotprop backnotprop force-pushed the fix/linked-doc-annotate-mode branch from 4aa71a9 to 0477ae3 Compare March 12, 2026 06:09
@backnotprop backnotprop merged commit 59724b7 into backnotprop:main Mar 12, 2026
8 checks passed
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