Skip to content

Commit 47f90d0

Browse files
committed
Don't throw and catch useless errors in flush()
Inside flush(), we don't care if there is a current component or not, we just want to save and restore it if there is one. Rather than throwing and catching an error that would happen often, we'll just create another version of get_current_component() that doesn't throw.
1 parent 83e9cc5 commit 47f90d0

File tree

2 files changed

+6
-7
lines changed

2 files changed

+6
-7
lines changed

src/runtime/internal/lifecycle.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ export function get_current_component() {
1111
return current_component;
1212
}
1313

14+
export function maybe_get_current_component() {
15+
return current_component;
16+
}
17+
1418
export function beforeUpdate(fn: () => any) {
1519
get_current_component().$$.before_update.push(fn);
1620
}

src/runtime/internal/scheduler.ts

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { run_all } from './utils';
2-
import { get_current_component, set_current_component } from './lifecycle';
2+
import { maybe_get_current_component, set_current_component } from './lifecycle';
33

44
export const dirty_components = [];
55
export const intros = { enabled: false };
@@ -35,12 +35,7 @@ const seen_callbacks = new Set();
3535
let flushidx = 0; // Do *not* move this inside the flush() function
3636
export function flush() {
3737

38-
let current_component = null;
39-
try {
40-
current_component = get_current_component();
41-
} catch {
42-
// no current component, so leave it as null
43-
}
38+
let current_component = maybe_get_current_component();
4439

4540
do {
4641
// first, call beforeUpdate functions

0 commit comments

Comments
 (0)