Skip to content

Commit 281b972

Browse files
committed
ok it works now
1 parent 35783c3 commit 281b972

File tree

6 files changed

+74
-24
lines changed

6 files changed

+74
-24
lines changed

packages/svelte/src/internal/client/dev/tracing.js

Lines changed: 12 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -26,23 +26,6 @@ function log_entry(signal, entry) {
2626
return;
2727
}
2828

29-
if (signal.trace) {
30-
var previous_captured_signals = captured_signals;
31-
var captured = new Set();
32-
set_captured_signals(captured);
33-
34-
try {
35-
untrack(signal.trace);
36-
} finally {
37-
set_captured_signals(previous_captured_signals);
38-
}
39-
40-
if (captured.size > 0) {
41-
for (const dep of captured) log_entry(dep);
42-
return;
43-
}
44-
}
45-
4629
const type = (signal.f & DERIVED) !== 0 ? '$derived' : '$state';
4730
const current_reaction = /** @type {Reaction} */ (active_reaction);
4831
const dirty = signal.wv > current_reaction.wv || current_reaction.wv === 0;
@@ -103,19 +86,25 @@ export function trace(label, fn) {
10386
var value = fn();
10487
var time = (performance.now() - start).toFixed(2);
10588

89+
var prefix = untrack(label);
90+
10691
if (!effect_tracking()) {
10792
// eslint-disable-next-line no-console
108-
console.log(`${label()} %cran outside of an effect (${time}ms)`, 'color: grey');
93+
console.log(`${prefix} %cran outside of an effect (${time}ms)`, 'color: grey');
10994
} else if (tracing_expressions.entries.size === 0) {
11095
// eslint-disable-next-line no-console
111-
console.log(`${label()} %cno reactive dependencies (${time}ms)`, 'color: grey');
96+
console.log(`${prefix} %cno reactive dependencies (${time}ms)`, 'color: grey');
11297
} else {
11398
// eslint-disable-next-line no-console
114-
console.group(`${label()} %c(${time}ms)`, 'color: grey');
99+
console.group(`${prefix} %c(${time}ms)`, 'color: grey');
115100

116-
for (const [signal, traces] of tracing_expressions.entries) {
117-
log_entry(signal, traces);
118-
}
101+
var entries = tracing_expressions.entries;
102+
103+
untrack(() => {
104+
for (const [signal, traces] of entries) {
105+
log_entry(signal, traces);
106+
}
107+
});
119108

120109
tracing_expressions = null;
121110

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
set_dev_current_component_function
4040
} from './context.js';
4141
import { handle_error, invoke_error_boundary } from './error-handling.js';
42+
import { snapshot } from '../shared/clone.js';
4243

4344
let is_flushing = false;
4445

@@ -769,6 +770,7 @@ export function get(signal) {
769770
if (
770771
DEV &&
771772
tracing_mode_flag &&
773+
!untracking &&
772774
tracing_expressions !== null &&
773775
active_reaction !== null &&
774776
tracing_expressions.reaction === active_reaction

packages/svelte/tests/runtime-legacy/shared.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { setImmediate } from 'node:timers/promises';
33
import { globSync } from 'tinyglobby';
44
import { createClassComponent } from 'svelte/legacy';
55
import { proxy } from 'svelte/internal/client';
6-
import { flushSync, hydrate, mount, unmount } from 'svelte';
6+
import { flushSync, hydrate, mount, unmount, untrack } from 'svelte';
77
import { render } from 'svelte/server';
88
import { afterAll, assert, beforeAll } from 'vitest';
99
import { compile_directory, fragments } from '../helpers.js';
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<script>
2+
let { entry } = $props();
3+
4+
$effect(() => {
5+
$inspect.trace('effect');
6+
entry;
7+
});
8+
</script>
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import { flushSync } from 'svelte';
2+
import { test } from '../../test';
3+
import { normalise_trace_logs } from '../../../helpers.js';
4+
5+
export default test({
6+
compileOptions: {
7+
dev: true
8+
},
9+
10+
test({ assert, target, logs }) {
11+
assert.deepEqual(normalise_trace_logs(logs), [
12+
{ log: 'effect' },
13+
{ log: '$state', highlighted: true },
14+
{ log: 'array', highlighted: false },
15+
{ log: [{ id: 1, hi: true }] },
16+
// this _doesn't_ appear in the browser, but it does appear during tests
17+
// and i cannot for the life of me figure out why. this does at least
18+
// test that we don't log `array[0].id` etc
19+
{ log: '$state', highlighted: true },
20+
{ log: 'array[0]', highlighted: false },
21+
{ log: { id: 1, hi: true } }
22+
]);
23+
24+
logs.length = 0;
25+
26+
const button = target.querySelector('button');
27+
button?.click();
28+
flushSync();
29+
30+
assert.deepEqual(normalise_trace_logs(logs), [
31+
{ log: 'effect' },
32+
{ log: '$state', highlighted: true },
33+
{ log: 'array', highlighted: false },
34+
{ log: [{ id: 1, hi: false }] },
35+
{ log: '$state', highlighted: false },
36+
{ log: 'array[0]', highlighted: false },
37+
{ log: { id: 1, hi: false } }
38+
]);
39+
}
40+
});
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<script>
2+
import Entry from './Entry.svelte';
3+
4+
let array = $state([{ id: 1, hi: true }]);
5+
</script>
6+
7+
<button onclick={() => array = [{ id: 1, hi: false}]}>update</button>
8+
9+
{#each array as entry (entry.id)}
10+
<Entry {entry} />
11+
{/each}

0 commit comments

Comments
 (0)