File tree Expand file tree Collapse file tree 4 files changed +59
-1
lines changed
tests/runtime-runes/samples/derived-dependencies Expand file tree Collapse file tree 4 files changed +59
-1
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' svelte ' : patch
3
+ ---
4
+
5
+ fix: avoid duplicate signal dependencies
Original file line number Diff line number Diff line change @@ -774,7 +774,10 @@ export function get(signal) {
774
774
) {
775
775
if ( current_dependencies === null ) {
776
776
current_dependencies = [ signal ] ;
777
- } else if ( current_dependencies [ current_dependencies . length - 1 ] !== signal ) {
777
+ } else if (
778
+ current_dependencies [ current_dependencies . length - 1 ] !== signal &&
779
+ ! current_dependencies . includes ( signal )
780
+ ) {
778
781
current_dependencies . push ( signal ) ;
779
782
}
780
783
}
Original file line number Diff line number Diff line change
1
+ import { flushSync } from 'svelte' ;
2
+ import { test } from '../../test' ;
3
+
4
+ export default test ( {
5
+ async test ( { assert, target } ) {
6
+ let [ btn1 , btn2 ] = target . querySelectorAll ( 'button' ) ;
7
+
8
+ flushSync ( ( ) => {
9
+ btn1 ?. click ( ) ;
10
+ } ) ;
11
+
12
+ assert . htmlEqual ( target . innerHTML , `<button>hide</button><button>show</button` ) ;
13
+
14
+ flushSync ( ( ) => {
15
+ btn2 ?. click ( ) ;
16
+ } ) ;
17
+
18
+ assert . htmlEqual (
19
+ target . innerHTML ,
20
+ `<h1>John Doe</h1><p>Body</p><button>hide</button><button>show</button>`
21
+ ) ;
22
+ }
23
+ } ) ;
Original file line number Diff line number Diff line change
1
+ <script >
2
+ let data = $state ({
3
+ event : {
4
+ author: ' John Doe' ,
5
+ body: ' Body'
6
+ }
7
+ });
8
+ const { event } = $derived (data);
9
+ </script >
10
+
11
+ {#if event }
12
+ <h1 >{event .author }</h1 >
13
+ <p >{event .body }</p >
14
+ {/if }
15
+
16
+ <button onclick ={() => {
17
+ data = {}
18
+ }}>hide</button >
19
+
20
+ <button onclick ={() => {
21
+ data = {
22
+ event: {
23
+ author: ' John Doe' ,
24
+ body: ' Body'
25
+ }
26
+ }
27
+ }}>show</button >
You can’t perform that action at this time.
0 commit comments