1+ /** @import { Reaction } from '#client' */
12import { describe , assert , it } from 'vitest' ;
23import { flushSync } from '../../src/index-client' ;
34import * as $ from '../../src/internal/client/runtime' ;
@@ -18,6 +19,7 @@ import { SvelteSet } from '../../src/reactivity/set';
1819import { DESTROYED } from '../../src/internal/client/constants' ;
1920import { noop } from 'svelte/internal/client' ;
2021import { disable_async_mode_flag , enable_async_mode_flag } from '../../src/internal/flags' ;
22+ import { branch } from '../../src/internal/client/reactivity/effects' ;
2123
2224/**
2325 * @param runes runes mode
@@ -1493,4 +1495,33 @@ describe('signals', () => {
14931495 assert . deepEqual ( log , [ 'inner destroyed' , 'inner destroyed' ] ) ;
14941496 } ;
14951497 } ) ;
1498+
1499+ // reproduces conditions leading to https://github.com/sveltejs/kit/issues/15059
1500+ test ( 'derived read inside branch effect should be reconnected even when effect_tracking is false' , ( ) => {
1501+ let count = state ( 0 ) ;
1502+ let d : Derived < number > | null = null ;
1503+
1504+ render_effect ( ( ) => {
1505+ branch ( ( ) => {
1506+ if ( ! d ) {
1507+ d = derived ( ( ) => $ . get ( count ) * 2 ) ;
1508+ }
1509+
1510+ $ . get ( d ) ;
1511+ } ) ;
1512+ } ) ;
1513+
1514+ return ( ) => {
1515+ flushSync ( ) ;
1516+
1517+ const isConnected = ( d ! . f & ( 1 << 9 ) ) !== 0 ; // CONNECTED = 1 << 9 = 512
1518+ assert . ok (
1519+ isConnected ,
1520+ 'derived should be CONNECTED after being read inside branch during effect update'
1521+ ) ;
1522+
1523+ const countReactions = count . reactions || [ ] ;
1524+ assert . ok ( d && countReactions . includes ( d ) , 'derived should be in source reactions' ) ;
1525+ } ;
1526+ } ) ;
14961527} ) ;
0 commit comments