fix: same-page transclusions with diff sections

When a page embeds two different sections from the same note (e.g.,
`![[Note#Section A]]` and `![[Note#Section B]]`), the second transclusion
is incorrectly flagged as circular. This happens because the `visited` set
in `renderTranscludes` tracks targets by slug alone, so the second embed
of the same file is treated as a cycle even though it references a
different section.

Include the block/section reference (`dataBlock`) in the visited key so
that different sections of the same page are treated as distinct
transclusion targets. Full-page transclusions (no section reference) still
use the slug alone, preserving circular reference detection for actual
cycles.
This commit is contained in:
Andrew Kwon 2026-02-18 19:53:35 -08:00
parent ec00a40aef
commit fc5a1f4987

View File

@ -78,7 +78,11 @@ function renderTranscludes(
if (classNames.includes("transclude")) {
const inner = node.children[0] as Element
const transcludeTarget = (inner.properties["data-slug"] ?? slug) as FullSlug
if (visited.has(transcludeTarget)) {
const dataBlock = node.properties.dataBlock as string | undefined
const visitedKey = dataBlock
? (`${transcludeTarget}${dataBlock}` as FullSlug)
: transcludeTarget
if (visited.has(visitedKey)) {
console.warn(
styleText(
"yellow",
@ -100,7 +104,7 @@ function renderTranscludes(
]
return
}
visited.add(transcludeTarget)
visited.add(visitedKey)
const page = componentData.allFiles.find((f) => f.slug === transcludeTarget)
if (!page) {