Merge branch 'main' into experiment_s

experiment_s
Dominic Gannaway 2 days ago
commit a4bf5e3981

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: ensure resume effects are scheduled in topological order

@ -0,0 +1,5 @@
---
'svelte': patch
---
fix: remove listener on `bind_current_time` teardown

@ -52,7 +52,10 @@ export function bind_current_time(media, get, set = get) {
} }
}); });
teardown(() => cancelAnimationFrame(raf_id)); teardown(() => {
cancelAnimationFrame(raf_id);
media.removeEventListener('timeupdate', callback);
});
} }
/** /**

@ -0,0 +1,26 @@
import { flushSync } from 'svelte';
import { ok, test } from '../../test';
export default test({
async test({ assert, target, logs }) {
const audio = target.querySelector('audio');
const btn = target.querySelector('button');
ok(audio);
flushSync(() => {
audio.currentTime = 10;
audio.dispatchEvent(new Event('timeupdate'));
});
assert.deepEqual(logs, ['event']);
flushSync(() => {
btn?.click();
});
flushSync(() => {
audio.currentTime = 20;
audio.dispatchEvent(new Event('timeupdate'));
});
assert.deepEqual(logs, ['event']);
}
});

@ -0,0 +1,12 @@
<script>
let show = $state(true);
let time = $state(0);
</script>
<button onclick={()=> show = false}></button>
{#if show}
<audio bind:currentTime={()=>time,(new_time)=>{
console.log("event");
time = new_time;
}}></audio>
{/if}

@ -0,0 +1,35 @@
import { flushSync } from '../../../../src/index-client.js';
import { test } from '../../test';
export default test({
async test({ assert, raf, target, logs }) {
assert.htmlEqual(
target.innerHTML,
'<button>Toggle</button><div><div>1</div><div>2</div><div>3</div></div>'
);
const btn1 = target.querySelector('button');
btn1?.click();
flushSync();
raf.tick(250);
assert.htmlEqual(
target.innerHTML,
'<button>Toggle</button><div style="opacity: 0.5;"><div>1</div><div>2</div><div>3</div></div>'
);
logs.length = 0;
await Promise.resolve();
flushSync();
raf.tick(500);
assert.htmlEqual(
target.innerHTML,
'<button>Toggle</button><div style=""><div>3</div><div>4</div></div>'
);
assert.deepEqual(logs, ['$effect.pre', '$effect.pre', '$effect', '$effect']);
}
});

@ -0,0 +1,39 @@
<script>
function fade(_) {
return {
duration: 500,
css: t => `opacity: ${t}`,
}
}
let toggle = $state(true);
let items = $state([ 1, 2, 3 ]);
const handle_toggle = async () => {
toggle = false;
await Promise.resolve();
items = [3, 4];
toggle = true;
};
</script>
<button onclick={handle_toggle}>Toggle</button>
{#if toggle}
<div transition:fade>
{#each items as item (item)}
{(() => {
$effect(() => {
items;
console.log('$effect');
});
$effect.pre(() => {
items;
console.log('$effect.pre');
});
})()}
<div>{item}</div>
{/each}
</div>
{/if}
Loading…
Cancel
Save