Skip to content

Commit e35334c

Browse files
committed
improve label for derived cached
1 parent 602a919 commit e35334c

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import { captured_signals, set_captured_signals } from '../runtime.js';
66
export const NOT_REACTIVE = 0;
77
export const REACTIVE_UNCHANGED = 1;
88
export const REACTIVE_CHANGED = 2;
9+
export const REACTIVE_CHANGED_CACHED = 3;
910

1011
/** @type { { changed: boolean, label: string, time: number, sub: any, stacks: any[], value: any }[] | null } */
1112
export let tracing_expressions = null;
12-
/** @type { 0 | 1 | 2 } */
13+
/** @type { 0 | 1 | 2 | 3 } */
1314
export let tracing_expression_reactive = NOT_REACTIVE;
1415

1516
/**
@@ -136,8 +137,10 @@ export function trace(fn, label, computed) {
136137
tracing_expressions = [];
137138
}
138139
tracing_expressions.push({
139-
changed: tracing_expression_reactive === REACTIVE_CHANGED,
140-
label,
140+
changed:
141+
tracing_expression_reactive === REACTIVE_CHANGED ||
142+
tracing_expression_reactive === REACTIVE_CHANGED_CACHED,
143+
label: label + (tracing_expression_reactive === REACTIVE_CHANGED_CACHED ? ' [cached derived]' : ''),
141144
value,
142145
time,
143146
stacks: set_stack ? [read_stack, set_stack] : [read_stack],
@@ -168,7 +171,7 @@ export function trace(fn, label, computed) {
168171
}
169172

170173
/**
171-
* @param {0 | 1 | 2} value
174+
* @param {0 | 1 | 2 | 3} value
172175
*/
173176
export function set_tracing_expression_reactive(value) {
174177
tracing_expression_reactive = value;

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ import {
3939
set_tracing_expression_reactive,
4040
REACTIVE_UNCHANGED,
4141
REACTIVE_CHANGED,
42-
tracing_expression_reactive
42+
tracing_expression_reactive,
43+
REACTIVE_CHANGED_CACHED
4344
} from './dev/tracing.js';
4445

4546
const FLUSH_MICROTASK = 0;
@@ -785,10 +786,13 @@ export function get(signal) {
785786
}
786787
}
787788

789+
var updated = false;
790+
788791
if (is_derived) {
789792
derived = /** @type {Derived} */ (signal);
790793

791794
if (check_dirtiness(derived)) {
795+
updated = true;
792796
update_derived(derived);
793797
}
794798
}
@@ -801,7 +805,9 @@ export function get(signal) {
801805
) {
802806
set_tracing_expression_reactive(
803807
signal.version > active_reaction.version || active_reaction.version === current_version
804-
? REACTIVE_CHANGED
808+
? updated
809+
? REACTIVE_CHANGED_CACHED
810+
: REACTIVE_CHANGED
805811
: REACTIVE_UNCHANGED
806812
);
807813
}

0 commit comments

Comments
 (0)