@@ -7,15 +7,15 @@ import type { ComputationSignal } from '../../src/internal/client/types';
77 * @param fn A function that returns a function because we first need to setup all the signals
88 * and then execute the test in order to simulate a real component
99 */
10- function run_test ( runes : boolean , fn : ( ) => ( ) => void ) {
10+ function run_test ( runes : boolean , fn : ( runes : boolean ) => ( ) => void ) {
1111 return ( ) => {
1212 // Create a component context to test runes vs legacy mode
1313 $ . push ( { } , runes ) ;
1414 // Create a render context so that effect validations etc don't fail
1515 let execute : any ;
1616 const signal = $ . render_effect (
1717 ( ) => {
18- execute = fn ( ) ;
18+ execute = fn ( runes ) ;
1919 } ,
2020 null ,
2121 true ,
@@ -27,7 +27,7 @@ function run_test(runes: boolean, fn: () => () => void) {
2727 } ;
2828}
2929
30- function test ( text : string , fn : ( ) => any ) {
30+ function test ( text : string , fn : ( runes : boolean ) => any ) {
3131 it ( `${ text } (legacy mode)` , run_test ( false , fn ) ) ;
3232 it ( `${ text } (runes mode)` , run_test ( true , fn ) ) ;
3333}
@@ -262,4 +262,25 @@ describe('signals', () => {
262262 assert . deepEqual ( count . c , null ) ;
263263 } ;
264264 } ) ;
265+
266+ test ( 'schedules rerun when writing to signal before reading it' , ( runes ) => {
267+ if ( ! runes ) return ( ) => { } ;
268+
269+ const value = $ . source ( { count : 0 } ) ;
270+ $ . user_effect ( ( ) => {
271+ $ . set ( value , { count : 0 } ) ;
272+ $ . get ( value ) ;
273+ } ) ;
274+
275+ return ( ) => {
276+ let errored = false ;
277+ try {
278+ $ . flushSync ( ) ;
279+ } catch ( e : any ) {
280+ assert . include ( e . message , 'ERR_SVELTE_TOO_MANY_UPDATES' ) ;
281+ errored = true ;
282+ }
283+ assert . equal ( errored , true ) ;
284+ } ;
285+ } ) ;
265286} ) ;
0 commit comments