Skip to content

Commit 66635c5

Browse files
committed
change behaviour of tick() to be requestAnimationFrame-based
1 parent 6b9f860 commit 66635c5

File tree

3 files changed

+6
-2
lines changed

3 files changed

+6
-2
lines changed

packages/svelte/src/internal/client/runtime.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -744,6 +744,10 @@ export function flushSync(fn) {
744744
* @returns {Promise<void>}
745745
*/
746746
export async function tick() {
747+
if (async_mode_flag) {
748+
return new Promise((f) => requestAnimationFrame(() => f()));
749+
}
750+
747751
await Promise.resolve();
748752
// By calling flushSync we guarantee that any pending state changes are applied after one tick.
749753
// TODO look into whether we can make flushing subsequent updates synchronously in the future.

packages/svelte/src/reactivity/create-subscriber.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ export function createSubscriber(start) {
6969
subscribers += 1;
7070

7171
return () => {
72-
tick().then(() => {
72+
queueMicrotask(() => {
7373
// Only count down after timeout, else we would reach 0 before our own render effect reruns,
7474
// but reach 1 again when the tick callback of the prior teardown runs. That would mean we
7575
// re-subcribe unnecessarily and create a memory leak because the old subscription is never cleaned up.

packages/svelte/tests/runtime-runes/samples/async-attribute/_config.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ export default test({
99
<p>pending</p>
1010
`,
1111

12-
async test({ assert, target, component }) {
12+
async test({ assert, target }) {
1313
const [cool, neat, reset] = target.querySelectorAll('button');
1414

1515
flushSync(() => cool.click());

0 commit comments

Comments
 (0)