File tree 5 files changed +49
-4
lines changed
5 files changed +49
-4
lines changed Original file line number Diff line number Diff line change
1
+ ---
2
+ ' svelte ' : patch
3
+ ---
4
+
5
+ fix: set deriveds as ` CLEAN ` if they are assigned to
Original file line number Diff line number Diff line change @@ -131,7 +131,7 @@ function get_derived_parent_effect(derived) {
131
131
* @param {Derived } derived
132
132
* @returns {T }
133
133
*/
134
- function execute_derived ( derived ) {
134
+ export function execute_derived ( derived ) {
135
135
var value ;
136
136
var prev_active_effect = active_effect ;
137
137
Original file line number Diff line number Diff line change @@ -28,14 +28,14 @@ import {
28
28
UNOWNED ,
29
29
MAYBE_DIRTY ,
30
30
BLOCK_EFFECT ,
31
- ROOT_EFFECT ,
32
- EFFECT_IS_UPDATING
31
+ ROOT_EFFECT
33
32
} from '../constants.js' ;
34
33
import * as e from '../errors.js' ;
35
34
import { legacy_mode_flag , tracing_mode_flag } from '../../flags/index.js' ;
36
35
import { get_stack } from '../dev/tracing.js' ;
37
36
import { component_context , is_runes } from '../context.js' ;
38
37
import { proxy } from '../proxy.js' ;
38
+ import { execute_derived } from './deriveds.js' ;
39
39
40
40
export let inspect_effects = new Set ( ) ;
41
41
export const old_values = new Map ( ) ;
@@ -172,6 +172,14 @@ export function internal_set(source, value) {
172
172
}
173
173
}
174
174
175
+ if ( ( source . f & DERIVED ) !== 0 ) {
176
+ // if we are assigning to a dirty derived we set it to clean/maybe dirty but we also eagerly execute it to track the dependencies
177
+ if ( ( source . f & DIRTY ) !== 0 ) {
178
+ execute_derived ( /** @type {Derived } */ ( source ) ) ;
179
+ }
180
+ set_signal_status ( source , ( source . f & UNOWNED ) === 0 ? CLEAN : MAYBE_DIRTY ) ;
181
+ }
182
+
175
183
mark_reactions ( source , DIRTY ) ;
176
184
177
185
// It's possible that the current reaction might not have up-to-date dependencies
Original file line number Diff line number Diff line change @@ -27,7 +27,7 @@ import {
27
27
} from './constants.js' ;
28
28
import { flush_tasks } from './dom/task.js' ;
29
29
import { internal_set , old_values } from './reactivity/sources.js' ;
30
- import { destroy_derived_effects , update_derived } from './reactivity/deriveds.js' ;
30
+ import { destroy_derived_effects , execute_derived , update_derived } from './reactivity/deriveds.js' ;
31
31
import * as e from './errors.js' ;
32
32
import { FILENAME } from '../../constants.js' ;
33
33
import { tracing_mode_flag } from '../flags/index.js' ;
Original file line number Diff line number Diff line change @@ -1080,6 +1080,38 @@ describe('signals', () => {
1080
1080
} ;
1081
1081
} ) ;
1082
1082
1083
+ test ( "deriveds set after they are DIRTY doesn't get updated on get" , ( ) => {
1084
+ return ( ) => {
1085
+ const a = state ( 0 ) ;
1086
+ const b = derived ( ( ) => $ . get ( a ) ) ;
1087
+
1088
+ set ( b , 1 ) ;
1089
+ assert . equal ( $ . get ( b ) , 1 ) ;
1090
+
1091
+ set ( a , 2 ) ;
1092
+ assert . equal ( $ . get ( b ) , 2 ) ;
1093
+ set ( b , 3 ) ;
1094
+
1095
+ assert . equal ( $ . get ( b ) , 3 ) ;
1096
+ } ;
1097
+ } ) ;
1098
+
1099
+ test ( "unowned deriveds set after they are DIRTY doesn't get updated on get" , ( ) => {
1100
+ return ( ) => {
1101
+ const a = state ( 0 ) ;
1102
+ const b = derived ( ( ) => $ . get ( a ) ) ;
1103
+ const c = derived ( ( ) => $ . get ( b ) ) ;
1104
+
1105
+ set ( b , 1 ) ;
1106
+ assert . equal ( $ . get ( c ) , 1 ) ;
1107
+
1108
+ set ( a , 2 ) ;
1109
+
1110
+ assert . equal ( $ . get ( b ) , 2 ) ;
1111
+ assert . equal ( $ . get ( c ) , 2 ) ;
1112
+ } ;
1113
+ } ) ;
1114
+
1083
1115
test ( 'deriveds containing effects work correctly when used with untrack' , ( ) => {
1084
1116
return ( ) => {
1085
1117
let a = render_effect ( ( ) => { } ) ;
You can’t perform that action at this time.
0 commit comments