Skip to content

fix(links): strip subpaths when resolving link targets - #738

Merged
michaelpporter merged 2 commits into
mainfrom
734-bug-tree-view-fails-for-links-with-block-references
Jul 25, 2026
Merged

fix(links): strip subpaths when resolving link targets#738
michaelpporter merged 2 commits into
mainfrom
734-bug-tree-view-fails-for-links-with-block-references

Conversation

@michaelpporter

@michaelpporter michaelpporter commented Jul 25, 2026

Copy link
Copy Markdown
Owner

Refs #734 — intentionally not an auto-closing keyword; the issue is closed when the fix ships in a release.

Stacked on #737 — this PR targets the #731 branch, so its diff shows only the subpath change. GitHub will retarget it to main automatically once #737 merges.

Problem

down:: [[2#^71f2d9]] in 1.md resolved to a phantom 2#^71f2d9.md node. Node identity in the WASM graph is the resolved path string, so 2.md and 2#^71f2d9.md are two different nodes — the downup transitive rule hung the reverse edge off the phantom.

That produces exactly the asymmetry reported: 1.md's tree renders fine, while 2.md never shows 1.md as its parent.

Root cause: resolve_relative_target_path passed the raw link text to getFirstLinkpathDest, which rejects anything carrying a #subpath, so the link fell through to the unresolved-path fallback.

Fix

Strip everything from the first # before resolving. # is illegal in vault filenames, so the first one always starts a subpath.

This is a single chokepoint — it fixes both typed_link passes (frontmatter and inline) and list_note, which had the same latent bug, and works regardless of which folders the notes live in.

A subpath-only link ([[#^71f2d9]]) points into the source note itself, so it now yields no edge rather than a self-loop.

Tests

bun run build && bun run test pass (379 tests, 0 type errors).

New tests/utils/obsidian.test.ts. The mock's getFirstLinkpathDest returns null for anything containing #, matching the real API — that's what makes these tests meaningful rather than tautological. Covers: block ref, heading ref, cross-folder block ref, block ref to a non-existent note, subpath-only link, and .canvas#group.

@michaelpporter
michaelpporter force-pushed the 731-bug-inline-dataview-creates-unintended-self-loop-edge branch from c3b318e to 2bbfac9 Compare July 25, 2026 15:28
@michaelpporter
michaelpporter force-pushed the 734-bug-tree-view-fails-for-links-with-block-references branch from 9387c66 to 3bd6d01 Compare July 25, 2026 15:28
Base automatically changed from 731-bug-inline-dataview-creates-unintended-self-loop-edge to main July 25, 2026 15:49
`down:: [[2#^71f2d9]]` in 1.md resolved to a phantom "2#^71f2d9.md"
node, so 1.md's tree rendered but 2.md never gained the reverse `up`
edge — node identity in the graph is the resolved path string, and the
transitive rule attached the reverse to the phantom.

resolve_relative_target_path now drops everything from the first `#`
before resolving (`#` is illegal in vault filenames), fixing the
frontmatter and inline typed_link passes plus list_note in one place.
A subpath-only link ([[#^71f2d9]]) targets the source note itself, so
it now yields no edge instead of a self-loop.

Refs #734
The button asked for `absolute bottom-2 right-2`, but src/styles.css
imports only `tailwindcss/utilities` — in Tailwind v4 the numeric
spacing scale lives in the theme layer, so `bottom-2`, `right-2` and
the `pr-10` content padding all compiled to nothing. An absolutely
positioned element with no insets sits at its static position, putting
the button over the first row's collapse arrow.

Positions the button (and the row padding that keeps note flair clear
of it) with plain CSS against Obsidian's --size-4-* variables, so it no
longer depends on the missing Tailwind scale.

Scoped to the tree codeblock. The wider problem — 99 spacing utilities
across 15 files silently compiling to nothing — is left untouched here.

Refs #736
@michaelpporter
michaelpporter force-pushed the 734-bug-tree-view-fails-for-links-with-block-references branch from 219d60a to ccb9690 Compare July 25, 2026 15:51
@michaelpporter
michaelpporter merged commit 18b80d5 into main Jul 25, 2026
1 check failed
@michaelpporter
michaelpporter deleted the 734-bug-tree-view-fails-for-links-with-block-references branch July 25, 2026 15:52
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.

1 participant