File tree Expand file tree Collapse file tree 3 files changed +19
-9
lines changed Expand file tree Collapse file tree 3 files changed +19
-9
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ " @sjsf/form " : patch
3
+ ---
4
+
5
+ Refactor async logic in file fields
Original file line number Diff line number Diff line change 7
7
</script >
8
8
9
9
<script lang =" ts" >
10
+ import { untrack } from " svelte" ;
11
+
10
12
import { fileToDataURL } from " @/lib/file.js" ;
11
13
import { abortPrevious , createAction } from " @/lib/action.svelte.js" ;
12
14
import {
44
46
async execute(
45
47
signal ,
46
48
files : FileList | undefined
47
- ): Promise < string | undefined > {
49
+ ) {
48
50
return files === undefined || files .length === 0
49
51
? undefined
50
52
: fileToDataURL (signal , files [0 ]! );
74
76
if (value === lastValueUpdate ) {
75
77
return ;
76
78
}
77
- toValue .abort ();
78
- toFiles .run (value );
79
+ untrack (() => {
80
+ toValue .abort ();
81
+ toFiles .run (value );
82
+ });
79
83
});
80
84
81
85
const errors = $derived (getErrors (ctx , config .id ));
Original file line number Diff line number Diff line change 7
7
</script >
8
8
9
9
<script lang =" ts" >
10
+ import { untrack } from " svelte" ;
11
+
10
12
import { fileToDataURL } from " @/lib/file.js" ;
11
13
import { abortPrevious , createAction } from " @/lib/action.svelte.js" ;
12
14
import {
41
43
let lastValueUpdate: string [] | undefined ;
42
44
const toValue = createAction ({
43
45
combinator: abortPrevious ,
44
- async execute(
45
- signal ,
46
- files : FileList | undefined
47
- ): Promise <string [] | undefined > {
46
+ async execute(signal , files : FileList | undefined ) {
48
47
if (files === undefined ) {
49
48
return undefined ;
50
49
}
82
81
) {
83
82
return ;
84
83
}
85
- toValue .abort ();
86
- toFiles .run (value );
84
+ untrack (() => {
85
+ toValue .abort ();
86
+ toFiles .run (value );
87
+ });
87
88
});
88
89
89
90
const errors = $derived (getErrors (ctx , config .id ));
You can’t perform that action at this time.
0 commit comments