Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 1 addition & 1 deletion packages/reactivity/src/baseHandlers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ class MutableReactiveHandler extends BaseReactiveHandler {

has(target: Record<string | symbol, unknown>, key: string | symbol): boolean {
const result = Reflect.has(target, key)
if (!isSymbol(key) || !builtInSymbols.has(key)) {
if (result && (!isSymbol(key) || !builtInSymbols.has(key))) {
track(target, TrackOpTypes.HAS, key)
}
return result
Expand Down
12 changes: 11 additions & 1 deletion packages/reactivity/src/dep.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { extend, isArray, isIntegerKey, isMap, isSymbol } from '@vue/shared'
import type { ComputedRefImpl } from './computed'
import { type TrackOpTypes, TriggerOpTypes } from './constants'
import { TrackOpTypes, TriggerOpTypes } from './constants'
import {
type DebuggerEventExtraInfo,
EffectFlags,
Expand Down Expand Up @@ -93,6 +93,12 @@ export class Dep {
*/
sc: number = 0

/**
* Indicates whether this Dep instance can be deleted
* When set to true, the Dep should be preserved
*/
permanent: boolean = false

constructor(public computed?: ComputedRefImpl | undefined) {
if (__DEV__) {
this.subsHead = undefined
Expand Down Expand Up @@ -264,6 +270,10 @@ export function track(target: object, type: TrackOpTypes, key: unknown): void {
depsMap.set(key, (dep = new Dep()))
dep.map = depsMap
dep.key = key

if (type === TrackOpTypes.HAS) {
dep.permanent = true
}
}
if (__DEV__) {
dep.track({
Expand Down
5 changes: 3 additions & 2 deletions packages/reactivity/src/effect.ts
Original file line number Diff line number Diff line change
Expand Up @@ -316,10 +316,11 @@ function cleanupDeps(sub: Subscriber) {
let link = tail
while (link) {
const prev = link.prevDep
if (link.version === -1) {
const isPermanentDep = link.dep.permanent
if (link.version === -1 && !isPermanentDep) {
if (link === tail) tail = prev
// unused - remove it from the dep's subscribing effect list
removeSub(link)
removeSub(link, isPermanentDep)
// also remove it from this effect's dep list
removeDep(link)
} else {
Expand Down