Skip to content

Commit c50883e

Browse files
authored
fix: ensure transition errors are not swallowed (#11039)
* fix: ensure transition errors are not swallowed * feedback
1 parent b210fe3 commit c50883e

File tree

3 files changed

+21
-2
lines changed

3 files changed

+21
-2
lines changed

.changeset/new-brooms-grin.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"svelte": patch
3+
---
4+
5+
fix: ensure transition errors are not swallowed

packages/svelte/src/internal/client/dom/elements/transitions.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,17 @@ function animate(element, options, counterpart, t2, callback) {
301301
.then(() => {
302302
callback?.();
303303
})
304-
.catch(noop);
304+
.catch((e) => {
305+
// Error for DOMException: The user aborted a request. This results in two things:
306+
// - startTime is `null`
307+
// - currentTime is `null`
308+
// We can't use the existence of an AbortError as this error and error code is shared
309+
// with other Web APIs such as fetch().
310+
311+
if (animation.startTime !== null && animation.currentTime !== null) {
312+
throw e;
313+
}
314+
});
305315
} else {
306316
// Timer
307317
if (t1 === 0) {

packages/svelte/tests/animation-helpers.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ class Animation {
4242
#cancelled = () => {};
4343

4444
currentTime = 0;
45+
startTime = 0;
4546

4647
/**
4748
* @param {HTMLElement} target
@@ -122,7 +123,10 @@ class Animation {
122123
if (this.currentTime > 0 && this.currentTime < this.#duration) {
123124
this.#apply_keyframe(0);
124125
}
125-
126+
// @ts-ignore
127+
this.currentTime = null;
128+
// @ts-ignore
129+
this.startTime = null;
126130
this.#cancelled();
127131
raf.animations.delete(this);
128132
}

0 commit comments

Comments
 (0)