Skip to content

Commit c609abe

Browse files
committed
Log when reactive values change during an update
sveltejs#5365
1 parent ebbbc0d commit c609abe

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

src/runtime/internal/Component.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ interface Fragment {
1919
/* outro */ o: (local: any) => void;
2020
/* destroy */ d: (detaching: 0|1) => void;
2121
}
22+
2223
interface T$$ {
24+
phase: number /* 0: init, 1: idle, 2: update, 3: beforeUpdate, 4: p, 5: afterUpdate */
2325
dirty: number[];
2426
ctx: null|any;
2527
bound: any;
@@ -121,25 +123,28 @@ export function init(component, options, instance, create_fragment, not_equal, p
121123

122124
// everything else
123125
callbacks: blank_object(),
126+
phase: 0,
124127
dirty,
125128
skip_bound: false
126129
};
127130

128-
let ready = false;
129-
130131
$$.ctx = instance
131132
? instance(component, prop_values, (i, ret, ...rest) => {
132133
const value = rest.length ? rest[0] : ret;
133134
if ($$.ctx && not_equal($$.ctx[i], $$.ctx[i] = value)) {
134135
if (!$$.skip_bound && $$.bound[i]) $$.bound[i](value);
135-
if (ready) make_dirty(component, i);
136+
if ($$.phase >= 1) make_dirty(component, i);
137+
if ($$.phase === 2) console.warn('$$invalidate called during reactive statements');
138+
if ($$.phase === 3) console.warn('$$invalidate called during beforeUpdate');
139+
if ($$.phase === 4) console.warn('$$invalidate called during processing');
140+
if ($$.phase === 5) console.warn('$$invalidate called during afterUpdate');
136141
}
137142
return ret;
138143
})
139144
: [];
140145

141146
$$.update();
142-
ready = true;
147+
$$.phase = 1;
143148
run_all($$.before_update);
144149

145150
// `false` as a special case of no DOM component

src/runtime/internal/scheduler.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,16 @@ export function flush() {
7979

8080
function update($$) {
8181
if ($$.fragment !== null) {
82+
$$.phase = 2;
8283
$$.update();
84+
$$.phase = 3;
8385
run_all($$.before_update);
8486
const dirty = $$.dirty;
8587
$$.dirty = [-1];
88+
$$.phase = 4;
8689
$$.fragment && $$.fragment.p($$.ctx, dirty);
87-
90+
$$.phase = 5;
8891
$$.after_update.forEach(add_render_callback);
92+
$$.phase = 1;
8993
}
9094
}

0 commit comments

Comments
 (0)