fix: allow multiple same-page transclusions with different sections#2311
Open
andweeb wants to merge 1 commit intojackyzha0:v4from
Open
fix: allow multiple same-page transclusions with different sections#2311andweeb wants to merge 1 commit intojackyzha0:v4from
andweeb wants to merge 1 commit intojackyzha0:v4from
Conversation
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.
built with Refined Cloudflare Pages Action⚡ Cloudflare Pages Deployment
|
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.
Description
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 thevisitedset inrenderTranscludestracks targets by slug alone, so the second embed of the same file is treated as a cycle even though it references a different section.The fix here includes 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.FYI there are still edge cases where non-circular transclusions are falsely flagged. For example, embedding the same section twice on one page, or diamond patterns where two different transclusions both embed the same target. That seemed like a lot more work to fix (and maybe even unrealistic/invalid use cases), so this PR is just scoped to addressing my personal scenario :)
Example
Here is an instance in which I've observed this occurring for

Mexico-Trip.mdin my Obsidian vault (notice the "Circular transclusion detected" error at the bottom):Here's the underlying relevant markdown snippet:
I inspected the logs and found this:
After applying the fix in this PR, I'm able to correctly render the two sections:
