@@ -6,40 +6,26 @@ import { DERIVED, PROXY_PATH_SYMBOL, STATE_SYMBOL } from '#client/constants';
66import { effect_tracking } from '../reactivity/effects.js' ;
77import { active_reaction , captured_signals , set_captured_signals , untrack } from '../runtime.js' ;
88
9- /** @type { any } */
9+ /**
10+ * @typedef {{
11+ * traces: Error[];
12+ * }} TraceEntry
13+ */
14+
15+ /** @type {{ reaction: Reaction | null, entries: Map<Value, TraceEntry> } | null } */
1016export let tracing_expressions = null ;
1117
1218/**
13- * @param { Value } signal
14- * @param { { read: Error[] } } [entry]
19+ * @param {Value } signal
20+ * @param {TraceEntry } [entry]
1521 */
1622function log_entry ( signal , entry ) {
17- const debug = signal . debug ;
18- const value = signal . trace_need_increase ? signal . trace_v : signal . v ;
23+ const value = signal . v ;
1924
2025 if ( value === UNINITIALIZED ) {
2126 return ;
2227 }
2328
24- if ( debug ) {
25- var previous_captured_signals = captured_signals ;
26- var captured = new Set ( ) ;
27- set_captured_signals ( captured ) ;
28- try {
29- untrack ( ( ) => {
30- debug ( ) ;
31- } ) ;
32- } finally {
33- set_captured_signals ( previous_captured_signals ) ;
34- }
35- if ( captured . size > 0 ) {
36- for ( const dep of captured ) {
37- log_entry ( dep ) ;
38- }
39- return ;
40- }
41- }
42-
4329 const type = ( signal . f & DERIVED ) !== 0 ? '$derived' : '$state' ;
4430 const current_reaction = /** @type {Reaction } */ ( active_reaction ) ;
4531 const dirty = signal . wv > current_reaction . wv || current_reaction . wv === 0 ;
@@ -69,17 +55,15 @@ function log_entry(signal, entry) {
6955 console . log ( signal . created ) ;
7056 }
7157
72- if ( signal . updated ) {
58+ if ( dirty && signal . updated ) {
7359 // eslint-disable-next-line no-console
7460 console . log ( signal . updated ) ;
7561 }
7662
77- const read = entry ?. read ;
78-
79- if ( read && read . length > 0 ) {
80- for ( var stack of read ) {
63+ if ( entry ) {
64+ for ( var trace of entry . traces ) {
8165 // eslint-disable-next-line no-console
82- console . log ( stack ) ;
66+ console . log ( trace ) ;
8367 }
8468 }
8569
@@ -94,46 +78,40 @@ function log_entry(signal, entry) {
9478 */
9579export function trace ( label , fn ) {
9680 var previously_tracing_expressions = tracing_expressions ;
81+
9782 try {
9883 tracing_expressions = { entries : new Map ( ) , reaction : active_reaction } ;
9984
10085 var start = performance . now ( ) ;
10186 var value = fn ( ) ;
10287 var time = ( performance . now ( ) - start ) . toFixed ( 2 ) ;
10388
89+ var prefix = untrack ( label ) ;
90+
10491 if ( ! effect_tracking ( ) ) {
10592 // eslint-disable-next-line no-console
106- 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' ) ;
10794 } else if ( tracing_expressions . entries . size === 0 ) {
10895 // eslint-disable-next-line no-console
109- console . log ( `${ label ( ) } %cno reactive dependencies (${ time } ms)` , 'color: grey' ) ;
96+ console . log ( `${ prefix } %cno reactive dependencies (${ time } ms)` , 'color: grey' ) ;
11097 } else {
11198 // eslint-disable-next-line no-console
112- console . group ( `${ label ( ) } %c(${ time } ms)` , 'color: grey' ) ;
99+ console . group ( `${ prefix } %c(${ time } ms)` , 'color: grey' ) ;
113100
114101 var entries = tracing_expressions . entries ;
115102
103+ untrack ( ( ) => {
104+ for ( const [ signal , traces ] of entries ) {
105+ log_entry ( signal , traces ) ;
106+ }
107+ } ) ;
108+
116109 tracing_expressions = null ;
117110
118- for ( const [ signal , entry ] of entries ) {
119- log_entry ( signal , entry ) ;
120- }
121111 // eslint-disable-next-line no-console
122112 console . groupEnd ( ) ;
123113 }
124114
125- if ( previously_tracing_expressions !== null && tracing_expressions !== null ) {
126- for ( const [ signal , entry ] of tracing_expressions . entries ) {
127- var prev_entry = previously_tracing_expressions . get ( signal ) ;
128-
129- if ( prev_entry === undefined ) {
130- previously_tracing_expressions . set ( signal , entry ) ;
131- } else {
132- prev_entry . read . push ( ...entry . read ) ;
133- }
134- }
135- }
136-
137115 return value ;
138116 } finally {
139117 tracing_expressions = previously_tracing_expressions ;
0 commit comments