Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions packages/reactivity/src/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,8 @@ function cleanupDeps(sub: Subscriber) {
// The new head is the last node seen which wasn't removed
// from the doubly-linked list
head = link
// Sync link version to maintain consistency for future dirty checks
link.version = link.dep.version
}

// restore previous active link if any
Expand Down Expand Up @@ -378,6 +380,36 @@ export function refreshComputed(computed: ComputedRefImpl): undefined {
}
computed.globalVersion = globalVersion

// Enhanced dependency check for development mode to ensure consistent behavior
// with production mode by avoiding unnecessary recomputations due to version lag
if (__DEV__ && computed.flags & EffectFlags.EVALUATED && computed.deps) {
let actuallyDirty = false
let link: Link | undefined = computed.deps
while (link) {
// Refresh nested computed dependencies first
if (link.dep.computed && link.dep.computed !== computed) {
refreshComputed(link.dep.computed)
}

// Conservative dirty check: only consider dirty if version difference > 1
// This accounts for the cleanup lag and prevents false positives
const versionDiff = link.dep.version - link.version
if (versionDiff > 1) {
actuallyDirty = true
break
} else if (versionDiff === 1) {
// Sync version to prevent accumulating lag
link.version = link.dep.version
}

link = link.nextDep
}

if (!actuallyDirty) {
return
}
}

// In SSR there will be no render effect, so the computed has no subscriber
// and therefore tracks no deps, thus we cannot rely on the dirty check.
// Instead, computed always re-evaluate and relies on the globalVersion
Expand Down