Skip to content

Commit 8410b12

Browse files
committed
perf: avoid unnecessary activeSub access
1 parent 425a633 commit 8410b12

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

src/index.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,10 @@ export function effect(fn: () => void): () => void {
138138
depsTail: undefined,
139139
flags: 2 satisfies ReactiveFlags.Watching,
140140
};
141-
const sub = activeSub;
142-
if (sub !== undefined) {
143-
link(e, sub, 0);
144-
}
145141
const prevSub = setActiveSub(e);
142+
if (prevSub !== undefined) {
143+
link(e, prevSub, 0);
144+
}
146145
try {
147146
e.fn();
148147
} finally {
@@ -159,11 +158,10 @@ export function effectScope(fn: () => void): () => void {
159158
subsTail: undefined,
160159
flags: 0 satisfies ReactiveFlags.None,
161160
};
162-
const sub = activeSub;
163-
if (sub !== undefined) {
164-
link(e, sub, 0);
165-
}
166161
const prevSub = setActiveSub(e);
162+
if (prevSub !== undefined) {
163+
link(e, prevSub, 0);
164+
}
167165
try {
168166
fn();
169167
} finally {

0 commit comments

Comments
 (0)