`$inspect` can cause an error in `$derived` based on `data`
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 20.8k
- Forks
- 2.3k
- Avg merge
- 1d 16h
- Merged PRs (30d)
- 156
Description
Describe the bug
$inspect can somehow cause a $derived to operate on data belonging to the next page when navigating. When the $inspect is removed, the problem disappears.
Reproduction
Code
// /some-route/+page.server.js
export function load() {
return {
items: [
{ id: 1, name: 'Item 1' },
{ id: 2, name: 'Item 2' },
{ id: 3, name: 'Item 3' },
{ id: 4, name: 'Item 4' },
{ id: 5, name: 'Item 5' },
],
};
}
<!-- /some-route/+page.svelte -->
<script lang="ts">
import List from './list.svelte';
let { data } = $props();
const { items } = $derived(data);
const even = $derived(items.filter((item) => item.id % 2 === 0));
</script>
<List items={even} />
<!-- /some-route/list.svelte -->
<script lang="ts">
const { items } = $props();
$inspect(items); // <- remove this
</script>
{#each items as item}
<div>
<a href="/">{item.id}</a>
</div>
{/each}
Logs
+page.svelte:13 Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'filter')
in <unknown>
in layout.svelte
in root.svelte
at +page.svelte:13:49
at update_reaction (chunk-DJJYHU3C.js?v=ad8341b0:2754:23)
at execute_derived (chunk-DJJYHU3C.js?v=ad8341b0:1240:15)
at update_derived (chunk-DJJYHU3C.js?v=ad8341b0:1257:15)
at is_dirty (chunk-DJJYHU3C.js?v=ad8341b0:2681:11)
at flush_inspect_effects (chunk-DJJYHU3C.js?v=ad8341b0:1398:9)
at internal_set (chunk-DJJYHU3C.js?v=ad8341b0:1386:7)
at set (chunk-DJJYHU3C.js?v=ad8341b0:1337:10)
at Object.set (chunk-SRUB5KV5.js?v=ad8341b0:829:11)
at Object.assign (<anonymous>)
System Info
(StackBlitz)
System:
OS: Linux 5.0 undefined
CPU: (8) x64 Intel(R) Core(TM) i9-9880H CPU @ 2.30GHz
Memory: 0 Bytes / 0 Bytes
Shell: 1.0 - /bin/jsh
Binaries:
Node: 20.19.1 - /usr/local/bin/node
Yarn: 1.22.19 - /usr/local/bin/yarn
npm: 10.8.2 - /usr/local/bin/npm
pnpm: 8.15.6 - /usr/local/bin/pnpm
npmPackages:
@sveltejs/adapter-auto: ^6.0.0 => 6.0.1
@sveltejs/kit: ^2.22.0 => 2.25.1
@sveltejs/vite-plugin-svelte: ^6.0.0 => 6.1.0
svelte: ^5.25.0 => 5.36.13
vite: ^7.0.4 => 7.0.5
Severity
annoyance
Additional Information
This seems like more of a Svelte issue, but I was unable to create a clean reproduction showing the difference between having the $inspect and not having it without SvelteKit.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the linked StackBlitz reproduction and inspect +page.server.js, +page.svelte, and list.svelte, comparing navigation with and without $inspect(items). Trace why the $derived value receives missing data during navigation. Done means the reproduction no longer throws and the rendered list uses the current page's data.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- frontend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100