fix: duplicate view-transition-name when posts share the same title#662
Open
WXY-V1hZ wants to merge 1 commit into
Open
fix: duplicate view-transition-name when posts share the same title#662WXY-V1hZ wants to merge 1 commit into
WXY-V1hZ wants to merge 1 commit into
Conversation
Two posts with identical frontmatter title cause duplicate view-transition-name values on the listing page, silently breaking Astro's View Transitions. Use the content collection id (unique file path) instead of title to generate transition names, both in Card.astro (listing) and [...slug]/index.astro (detail page).
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.
Description
When two posts have the same frontmatter
title, the listing page (Card.astro) generates duplicateview-transition-namevalues for the article cards. The browser's View Transition API requires unique transition names within a page — duplicates cause the API to silently abort, falling back to a hard (non-animated) navigation.This can be confusing for users: the page transition animation simply disappears without any error message, making it feel like a browser issue.
Root cause:
toTransitionName(title)is called with the post title, which is not guaranteed to be unique. When two posts share a title (e.g., two articles named "Getting Started"), both<h2>elements on the listing page end up with the sameview-transition-name.Fix: Replace
titlewith the content collectionid(the unique file path) when generating transition names. Theidis inherently unique since no two articles can share the same file path.This fix applies to both places where transition names are set:
src/components/Card.astro(listing page cards)src/pages/posts/[...slug]/index.astro(detail page heading)Both must be updated together — if only one side is changed, the heading won't animate smoothly during navigation.
Types of changes
Checklist
Further comments
This is a minimal 2-line fix. An alternative approach would be to use a combination of
idandtitle, but sinceidalready provides uniqueness, addingtitleis redundant.Related Issue
No existing issue — found during personal use.