File tree Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Expand file tree Collapse file tree 2 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -341,4 +341,31 @@ describe('reactivity/computed', () => {
341
341
expect ( c1Spy ) . toHaveBeenCalledTimes ( 104 )
342
342
expect ( c2Spy ) . toHaveBeenCalledTimes ( 2 )
343
343
} )
344
+
345
+ it ( 'chained computed value urgent assessment edge case' , ( ) => {
346
+ const cSpy = vi . fn ( )
347
+
348
+ const a = ref < null | { v : number } > ( {
349
+ v : 1
350
+ } )
351
+ const b = computed ( ( ) => {
352
+ return a . value
353
+ } )
354
+ const c = computed ( ( ) => {
355
+ cSpy ( )
356
+ return b . value ?. v
357
+ } )
358
+ const d = computed ( ( ) => {
359
+ if ( b . value ) {
360
+ return c . value
361
+ }
362
+ return 0
363
+ } )
364
+
365
+ d . value
366
+ a . value ! . v = 2
367
+ a . value = null
368
+ d . value
369
+ expect ( cSpy ) . toHaveBeenCalledTimes ( 1 )
370
+ } )
344
371
} )
Original file line number Diff line number Diff line change @@ -72,6 +72,13 @@ export class ComputedRefImpl<T> {
72
72
const self = toRaw ( this )
73
73
if ( ! self . _dirty && self . _computedsToAskDirty . length ) {
74
74
pauseTracking ( )
75
+ if ( self . _computedsToAskDirty . length >= 2 ) {
76
+ self . _computedsToAskDirty = self . _computedsToAskDirty . sort ( ( a , b ) => {
77
+ const aIndex = self . effect . deps . indexOf ( a . dep ! )
78
+ const bIndex = self . effect . deps . indexOf ( b . dep ! )
79
+ return aIndex - bIndex
80
+ } )
81
+ }
75
82
for ( const computedToAskDirty of self . _computedsToAskDirty ) {
76
83
computedToAskDirty . value
77
84
if ( self . _dirty ) {
You can’t perform that action at this time.
0 commit comments