Skip to content

Commit 85f3099

Browse files
committed
fix: improved $inspect handling of reactive Map/Set/Date
1 parent 7e9b109 commit 85f3099

File tree

3 files changed

+22
-1
lines changed

3 files changed

+22
-1
lines changed

.changeset/empty-coins-build.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: improved $inspect handling of reactive Map/Set/Date

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

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1+
import { DEV } from 'esm-env';
12
import { snapshot } from '../proxy.js';
23
import { render_effect, validate_effect } from '../reactivity/effects.js';
3-
import { current_effect, deep_read, untrack } from '../runtime.js';
4+
import { deep_read, untrack } from '../runtime.js';
45
import { array_prototype, get_prototype_of, object_prototype } from '../utils.js';
56

67
/** @type {Function | null} */
@@ -61,6 +62,16 @@ export function inspect(get_value, inspector = console.log) {
6162
*/
6263
function deep_snapshot(value, visited = new Map()) {
6364
if (typeof value === 'object' && value !== null && !visited.has(value)) {
65+
if (DEV) {
66+
// When dealing with ReactiveMap or ReactiveSet, return normal versions
67+
// so that console.log provides better output versions
68+
if (value instanceof Map && value.constructor !== Map) {
69+
return new Map(value);
70+
}
71+
if (value instanceof Set && value.constructor !== Set) {
72+
return new Set(value);
73+
}
74+
}
6475
const unstated = snapshot(value);
6576

6677
if (unstated !== value) {

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1215,6 +1215,11 @@ export function deep_read(value, visited = new Set()) {
12151215
!visited.has(value)
12161216
) {
12171217
visited.add(value);
1218+
// When working with a possible ReactiveDate, this
1219+
// will ensure we capture changes to it.
1220+
if (value instanceof Date) {
1221+
value.getTime();
1222+
}
12181223
for (let key in value) {
12191224
try {
12201225
deep_read(value[key], visited);

0 commit comments

Comments
 (0)