mirror of https://github.com/sveltejs/svelte
fix: avoid NaN keyframe values in slide transition (#18430)
Fixes #14205 When a `slide` transition runs on an element without a layout box, for example inside a `display: none` parent, `getComputedStyle` returns values like `auto` for the animated dimensions. These were passed through `parseFloat` unguarded, so the generated css contained `height: NaNpx` and the browser rejected the keyframe property with an "Invalid keyframe value" warning on every transition. Fix it by omitting properties if they have unparseable numbers - it's the same outcome but you don't see a warning. --------- Co-authored-by: Simon Holthausen <simon.holthausen@vercel.com>pull/17306/merge
parent
3405b5e735
commit
3b559bbf96
@ -0,0 +1,5 @@
|
||||
---
|
||||
'svelte': patch
|
||||
---
|
||||
|
||||
fix: avoid `NaN` keyframe values in `slide` transition for elements without a layout box
|
||||
@ -0,0 +1,27 @@
|
||||
import { ok, test } from '../../assert';
|
||||
|
||||
export default test({
|
||||
async test({ assert, window }) {
|
||||
window.document.querySelector('button')?.click();
|
||||
await new Promise((r) => setTimeout(r, 100));
|
||||
|
||||
const p = window.document.querySelector('p');
|
||||
const animations = /** @type {HTMLElement} */ (p).getAnimations();
|
||||
assert.equal(animations.length, 1);
|
||||
|
||||
// when the element has no layout box, computed dimensions resolve to 'auto',
|
||||
// which must not end up as NaN values that the browser rejects (#14205)
|
||||
const effect = /** @type {KeyframeEffect} */ (animations[0].effect);
|
||||
const keyframes = effect.getKeyframes();
|
||||
ok(keyframes.length > 0);
|
||||
assert.equal(effect.getTiming().duration, 400);
|
||||
|
||||
for (const keyframe of keyframes) {
|
||||
ok(!('height' in keyframe), 'unresolved height should be omitted');
|
||||
|
||||
for (const value of Object.values(keyframe)) {
|
||||
ok(!String(value).includes('NaN'), `unexpected NaN in keyframe: ${value}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
@ -0,0 +1,13 @@
|
||||
<script>
|
||||
import { slide } from 'svelte/transition';
|
||||
|
||||
let visible = $state(false);
|
||||
</script>
|
||||
|
||||
<button onclick={() => (visible = !visible)}>toggle</button>
|
||||
|
||||
<div style="display: none">
|
||||
{#if visible}
|
||||
<p transition:slide>hello</p>
|
||||
{/if}
|
||||
</div>
|
||||
Loading…
Reference in new issue