Skip to content

Fix duplicate "View source" links after client-side navigation - #1698

Merged
lsegal merged 1 commit into
lsegal:mainfrom
adam12:fix-duplicate-view-source-links
Jul 28, 2026
Merged

Fix duplicate "View source" links after client-side navigation#1698
lsegal merged 1 commit into
lsegal:mainfrom
adam12:fix-duplicate-view-source-links

Conversation

@adam12

@adam12 adam12 commented Jul 28, 2026

Copy link
Copy Markdown
Contributor

createSourceLinks() adds a [ View source ] toggle in front of every
.source_code table, but never checks if one's already there. The default
template's instant-nav feature (since 0.9.38) reruns the whole
window.__app() setup — including createSourceLinks() — every time it
swaps new content into #main, and if that fires without #main actually
being replaced first, you get two toggles per source block instead of
one.

I hit this on a site that serves YARD's static HTML output directly, with
no yard server in front — that reinit path ends up being the only
navigation mechanism in play there. Confirmed it with a small jsdom test:
loading a page once gives the expected one toggle per source_code table,
and calling window.__app() a second time without touching #main doubles
them.

Fix is a one-line guard: skip a source_code table if its previous sibling
already has the showSource class.

createSourceLinks() inserts a [ View source ] toggle before every
.source_code table with no check for whether one is already there. The
default template's instant-navigation code (introduced in 0.9.38) calls
window.__app() again each time it swaps #main's content, re-running
createSourceLinks() on top of markup that can still hold a previous
toggle, so every source block ends up with two.

Skip a source_code table that already has a showSource sibling.
@lsegal
lsegal merged commit 1f6bac2 into lsegal:main Jul 28, 2026
25 checks passed
@lsegal

lsegal commented Jul 28, 2026

Copy link
Copy Markdown
Owner

Looks super useful. Thanks for the fix!

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