Fix duplicate "View source" links after client-side navigation - #1698
Merged
Conversation
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.
Owner
|
Looks super useful. Thanks for the fix! |
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.
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 serverin front — that reinit path ends up being the onlynavigation 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.