Skip to content

Fix swup cross build navigation#2246

Merged
josevalim merged 1 commit into
elixir-lang:mainfrom
garazdawi:fix-swup-cross-build-navigation
Jun 9, 2026
Merged

Fix swup cross build navigation#2246
josevalim merged 1 commit into
elixir-lang:mainfrom
garazdawi:fix-swup-cross-build-navigation

Conversation

@garazdawi

Copy link
Copy Markdown
Contributor

This PR fixes two things with SWUP.

  1. It fixes so that links between apps do not have to be absolute in order to disable swup transitions. We have relative paths between apps in erlang.org and I think it makes sense for swup to only be used within a single path.
  2. It fixes a bug introduced in a66397f that disables swup on any link that has an anchor.

@github-actions

github-actions Bot commented Jun 9, 2026

Copy link
Copy Markdown

@josevalim

Copy link
Copy Markdown
Member

@garazdawi couldn't the check be simpler and instead we only use swup if there is no / in the path?

Comment thread assets/js/swup.js Outdated
// like `Foo.html#fun/1`, sidebar entries — on the SWUP path, which a plain
// `[href$=".html"]` (matching only hrefs that *end* in .html) would drop.
export const LINK_SELECTOR =
'a[href]:not([href^="/"]):not([href^="http"]):is([href$=".html"], [href*=".html#"])'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we only accept things that do not have a / in it:

Suggested change
'a[href]:not([href^="/"]):not([href^="http"]):is([href$=".html"], [href*=".html#"])'
'a[href]:not([href*="/"]):is([href$=".html"], [href*=".html#"])'

@garazdawi

Copy link
Copy Markdown
Contributor Author

Anchors contain / (for example https://www.erlang.org/doc/apps/kernel/file.html#list_dir/1), so that breaks local anchors.

@garazdawi

Copy link
Copy Markdown
Contributor Author

Though having thought a bit more, maybe that is not an issue as swup is not enabled for local anchors anyway, right?

@josevalim

Copy link
Copy Markdown
Member

Good call!

No SWUP for local anchors but we can refer to anchors across files... and we still want SWUP. So I guess we keep the LINK_SELECTOR as it is, but, when validating later, we could check that it doesn't include / instead of checking for cross build?

const href = link.getAttribute('href')
const path = href.split('#', 1)[0]
!path.includes('/')

@garazdawi garazdawi force-pushed the fix-swup-cross-build-navigation branch from a6e76a7 to c58be6f Compare June 9, 2026 13:21
Comment thread assets/js/swup.js Outdated

window.addEventListener('DOMContentLoaded', emitExdocLoaded)

export const LINK_SELECTOR = 'a[href]:not([href^="http"]):not([href*="/"]):is([href$=".html"], [href*=".html#"], [href^="#"])'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I think there was some confusion. I am afraid we cannot do this because then it won't use SWUP when navigating from Float.html to Integer.html#foo/2?

So I think we need to have the code we have before, the difference is that isCrossBuild can be replaced by something like "noUnderscoreBeforeFragment" or similar?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I noticed as much myself. I'm working on a new fix. I thought I had it working with the pushed solution, but that turned out to be due to a stale build of Erlang/OTP docs...

We force a full reload if there is a  anywhere in the path.

Fix issue introduced in a66397f where anchors are not swupped.
@garazdawi garazdawi force-pushed the fix-swup-cross-build-navigation branch from c58be6f to 6d47096 Compare June 9, 2026 14:02
@garazdawi

Copy link
Copy Markdown
Contributor Author

Should be fixed now. Tested it on a local Erlang/OTP docs build.

@josevalim josevalim merged commit 79890d4 into elixir-lang:main Jun 9, 2026
6 checks passed
@josevalim

Copy link
Copy Markdown
Member

💚 💙 💜 💛 ❤️

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants