fix: Register astro:after-swap listener unconditionally to support view transitions from non-mermaid pages#22
Merged
joesaby merged 1 commit intojoesaby:mainfrom Jan 18, 2026
Conversation
Refactor mermaid.js loading and initialization logic to improve performance and maintainability. Added support for dynamic theme switching and diagram rendering on view transitions.
✅ Deploy Preview for astro-mermaid-demo canceled.
|
✅ Deploy Preview for starlight-mermaid-demo canceled.
|
Closed
joesaby
approved these changes
Jan 18, 2026
joesaby
added a commit
that referenced
this pull request
Jan 18, 2026
This release includes: - Fix for view transitions when landing on non-mermaid pages (#22) - Improved mermaid loading with caching to prevent duplicate imports - Unconditional registration of astro:after-swap event listener Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
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.
This PR attempt resolve #11
Problem
The
astro:after-swapevent listener was only registered when the initial landing page contained mermaid diagrams. This caused mermaid diagrams to fail rendering when:The event listener was never registered in scenario 1, so diagrams on subsequent pages would not render.
Solution
astro:after-swapevent listener registration outside the conditional blockloadMermaid()function with caching to prevent duplicate importsChanges
loadMermaid()functionastro:after-swaplistener unconditionally at module scope