Skip to content

Conversation

@liamcmitchell
Copy link
Contributor

Re: #2069 (comment)

The sidebar-list is lazy-rendered so will always be called after the first exdoc:loaded event.

I re-arranged a few lines and added some comments to make it more obvious that it's not the standard exdoc:loaded -> init() pattern.

@github-actions
Copy link


// Keep updated with future changes.
window.addEventListener('hashchange', markCurrentHashInSidebar)
window.addEventListener('exdoc:loaded', markCurrentHashInSidebar)
Copy link
Member

Choose a reason for hiding this comment

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

Doesn't this mean markCurrentHashInSidebar will be invoked two times on boot? One here and another on DOMContentLoaded? Or is that fine?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Calling multiple times is fine but I don't think it should happen.
On page load this would be called by the sidebar init fn which is now triggered by ex doc:loaded, meaning the event has already fired at this point and won't fire again until SWUP nav.
That's why it broke when you tried it. Adding the listener here is too late for the first render.

Copy link
Member

Choose a reason for hiding this comment

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

Got it! Thanks for clarifying and sorry for being a slowpoke!

@josevalim josevalim merged commit 66d7f17 into elixir-lang:main Jan 26, 2025
4 checks passed
@josevalim
Copy link
Member

💚 💙 💜 💛 ❤️

@liamcmitchell liamcmitchell deleted the exdoc-loaded branch January 26, 2025 07:50
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