#why image viewtransition not working in astro v4
4 messages · Page 1 of 1 (latest)
Hi @unreal spoke. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:
Based on the information provided in the extracts, there could be several reasons why the image view transition is not working in Astro v4. Here are a few possibilities:
- Directives only work in
.astrofiles: According to a comment (https://github.com/withastro/astro/issues/8983) on GitHub, thetransition:directives (and all directives, such asclient:) only work inside of.astrofiles. If you're trying to use these directives in a.jsxfile, they won't work. Instead, you can use CSS to create a shared class name for the transition.
.my-image {
view-transition-name: noenemies2;
}
- Dynamic
view-transition-name: If theview-transition-nameneeds to be dynamic (such as for multiple images on the page), this is not supported via shared CSS classes. In this case, a dynamicview-transition-namecan be added via an inline style property, to ensure unique transition name keys.
<img
{src}
{width}
style={`view-transition-name: ${src.replace(/[^a-z0-9]/gi, '')}`}
/>
-
Issues with
<ViewTransitions />: There have been reported issues (https://github.com/withastro/astro/issues/9368) with the<ViewTransitions />component causing errors. If you're using this component, it could be the source of the problem. -
Discrepancies between dev and prod: There have been reports (https://discord.com/channels/830184174198718474/1151397066212388924) of view transitions working in development but not in production. This could be due to differences in the environments or configurations.