Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/quiet-foxes-point.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'astro': patch
---

Fixes custom View Transition direction names that are not valid CSS identifiers, such as names starting with a digit or containing spaces. These directions now match their animations correctly.
4 changes: 3 additions & 1 deletion packages/astro/src/runtime/server/transition.ts
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ export class ViewTransitionStyleSheet {
? `[data-astro-transition=back]`
: direction === 'forwards'
? ''
: `[data-astro-transition=${direction}]`;
: // Quote custom direction names so values that are not valid CSS identifiers
// (e.g. names starting with a digit or containing spaces) still match.
`[data-astro-transition=${cssesc(direction, { quotes: 'double', wrap: true })}]`;
this.addRule('modern', `${prefix}::view-transition-${image}(${name}) { ${animation} }`);
this.addRule(
'fallback',
Expand Down
25 changes: 25 additions & 0 deletions packages/astro/test/units/render/transitions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,31 @@ describe('ViewTransitionStyleSheet', () => {
);
});

it('addAnimationPair() quotes custom direction names in the selector', () => {
const sheet = new ViewTransitionStyleSheet('astro-xyz-1', 'banner');
sheet.addAnimationPair('downward', 'old', { name: 'slide-out' });
const css = sheet.toString();
assert.ok(
css.includes('[data-astro-transition="downward"]::view-transition-old(banner)'),
`expected quoted custom direction prefix: ${css}`,
);
});

it('addAnimationPair() supports custom direction names that are not CSS identifiers', () => {
const sheet = new ViewTransitionStyleSheet('astro-xyz-1', 'banner');
sheet.addAnimationPair('2nd step', 'new', { name: 'slide-in' });
sheet.addAnimationPair('a"b]c{d}', 'old', { name: 'slide-out' });
const css = sheet.toString();
assert.ok(
css.includes('[data-astro-transition="2nd step"]::view-transition-new(banner)'),
`expected quoted custom direction prefix: ${css}`,
);
assert.ok(
css.includes('[data-astro-transition="a\\"b]c{d}"]::view-transition-old(banner)'),
`expected punctuation in custom direction to be escaped: ${css}`,
);
});

it('addAnimationRaw() adds same rule to both modern and fallback', () => {
const sheet = new ViewTransitionStyleSheet('astro-abc-1', 'hero');
sheet.addAnimationRaw('new', 'animation: none; mix-blend-mode: normal;');
Expand Down
Loading