Skip to content

Commit 36d73ca

Browse files
fix: correctly highlight first rerun of $inspect.trace (#14734)
1 parent e0e9990 commit 36d73ca

File tree

4 files changed

+72
-7
lines changed

4 files changed

+72
-7
lines changed

.changeset/tame-eggs-work.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'svelte': patch
3+
---
4+
5+
fix: correctly highlight first rerun of `$inspect.trace`

packages/svelte/src/internal/client/runtime.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,8 @@ export function set_untracked_writes(value) {
127127
untracked_writes = value;
128128
}
129129

130-
/** @type {number} Used by sources and deriveds for handling updates to unowned deriveds */
131-
let current_version = 0;
130+
/** @type {number} Used by sources and deriveds for handling updates to unowned deriveds it starts from 1 to differentiate between a created effect and a run one for tracing */
131+
let current_version = 1;
132132

133133
// If we are working with a get() chain that has no active container,
134134
// to prevent memory leaks, we skip adding the reaction.

packages/svelte/tests/runtime-runes/samples/inspect-trace/_config.js

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,15 @@ function normalise_trace_logs(logs) {
1111

1212
if (typeof log === 'string' && log.includes('%c')) {
1313
const split = log.split('%c');
14-
normalised.push((split[0].length !== 0 ? split[0] : split[1]).trim());
14+
normalised.push({
15+
log: (split[0].length !== 0 ? split[0] : split[1]).trim(),
16+
highlighted: logs[i + 1] === 'color: CornflowerBlue; font-weight: bold'
17+
});
1518
i++;
1619
} else if (log instanceof Error) {
1720
continue;
1821
} else {
19-
normalised.push(log);
22+
normalised.push({ log });
2023
}
2124
}
2225
return normalised;
@@ -28,14 +31,67 @@ export default test({
2831
},
2932

3033
test({ assert, target, logs }) {
31-
assert.deepEqual(normalise_trace_logs(logs), ['effect', '$derived', 0, '$state', 0]);
34+
// initial log, everything is highlighted
35+
36+
assert.deepEqual(normalise_trace_logs(logs), [
37+
{ log: 'effect', highlighted: false },
38+
{ log: '$derived', highlighted: true },
39+
{ log: 0 },
40+
{ log: '$state', highlighted: true },
41+
{ log: 0 },
42+
{ log: '$state', highlighted: true },
43+
{ log: false }
44+
]);
3245

3346
logs.length = 0;
3447

3548
const button = target.querySelector('button');
3649
button?.click();
3750
flushSync();
3851

39-
assert.deepEqual(normalise_trace_logs(logs), ['effect', '$derived', 2, '$state', 1]);
52+
// count changed, derived and state are highlighted, last state is not
53+
54+
assert.deepEqual(normalise_trace_logs(logs), [
55+
{ log: 'effect', highlighted: false },
56+
{ log: '$derived', highlighted: true },
57+
{ log: 2 },
58+
{ log: '$state', highlighted: true },
59+
{ log: 1 },
60+
{ log: '$state', highlighted: false },
61+
{ log: false }
62+
]);
63+
64+
logs.length = 0;
65+
66+
const input = target.querySelector('input');
67+
input?.click();
68+
flushSync();
69+
70+
// checked changed, last state is highlighted, first two are not
71+
72+
assert.deepEqual(normalise_trace_logs(logs), [
73+
{ log: 'effect', highlighted: false },
74+
{ log: '$derived', highlighted: false },
75+
{ log: 2 },
76+
{ log: '$state', highlighted: false },
77+
{ log: 1 },
78+
{ log: '$state', highlighted: true },
79+
{ log: true }
80+
]);
81+
82+
logs.length = 0;
83+
84+
button?.click();
85+
flushSync();
86+
87+
// count change and derived it's >=4, checked is not in the dependencies anymore
88+
89+
assert.deepEqual(normalise_trace_logs(logs), [
90+
{ log: 'effect', highlighted: false },
91+
{ log: '$derived', highlighted: true },
92+
{ log: 4 },
93+
{ log: '$state', highlighted: true },
94+
{ log: 2 }
95+
]);
4096
}
4197
});

packages/svelte/tests/runtime-runes/samples/inspect-trace/main.svelte

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,15 @@
22
let count = $state(0);
33
let double = $derived(count * 2);
44
5+
let checked = $state(false);
6+
57
$effect(() => {
68
$inspect.trace('effect');
79
810
double;
9-
})
11+
double >= 4 || checked;
12+
});
1013
</script>
1114

1215
<button onclick={() => count++}>{double}</button>
16+
<input type="checkbox" bind:checked />

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy