Skip to main content
GoodFirstPicks
DashboardIssuesReposLeaderboard

GoodFirstPicks by Leaveitblank © 2026

CreatorRequest a RepoPrivacy PolicyTerms of Service
Async Svelte crash in certain situations when destructuring awaited derived value in a @const | GoodFirstPicks

Async Svelte crash in certain situations when destructuring awaited derived value in a @const

sveltejs/svelte 1 comments 3d ago
View on GitHub
mediumopenScope: somewhat clearSkill match: maybeSvelteTypeScript

Why this is a good first issue

The issue involves complex async behavior and template destructuring in Svelte.

AI Summary

The issue occurs when destructuring an awaited derived value in a `@const` statement within a Svelte template, causing a crash. The problem seems related to how Svelte handles async values and destructuring in templates. The scope is somewhat clear, but understanding Svelte's internal handling of async and derived values is required.

Issue Description

Describe the bug

This seems to happen when you have:

First, an awaited query, and a derived expression from that query

import { getIt } from './query.remote.ts';
let d = $derived(await getIt());
// For some reason this additional derived is required to reproduce
let showFetchCta = $derived(d.hasData)

In the template, a @const statement that destructures the awaited value.

{#if d}
	{@const {data, hasData} = d}

	{#if hasData}
		<p>The Data: {data}</p>
	{:else if showFetchCta} <!-- reference the derived so it doesn't get thrown away -->
		<p>Fetch now</p>
	{:else}
		<p>No data</p>
	{/if}
{/if}

Causes the error

 TypeError: Cannot read properties of undefined (reading 'f')

In Module.get where it reads signal.f (signal is apparently still undefined).

If you remove the @const destructuring and just reference the values as d.data and so on, then it works fine.

Reproduction

https://www.sveltelab.dev/38gut2mu4bw9p4d

Note you might have to run with the inspector open to really see the crash. Otherwise it's not totally obvious all the time.

Logs

Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'f')

	in <unknown>
	in +page.svelte
	in +layout.svelte
	in root.svelte
	in undefined

    at Module.get (chunk-O3RU4Q5E.js?v=4ba18bce:4157:23)
    at +page.svelte?t=1774689309840:99:13
    at chunk-GMPPHB2E.js?v=4ba18bce:798:5
    at update_reaction (chunk-O3RU4Q5E.js?v=4ba18bce:3983:18)
    at update_effect (chunk-O3RU4Q5E.js?v=4ba18bce:4122:21)
    at create_effect (chunk-O3RU4Q5E.js?v=4ba18bce:3466:7)
    at block (chunk-O3RU4Q5E.js?v=4ba18bce:3632:17)
    at Module.if_block (chunk-GMPPHB2E.js?v=4ba18bce:796:3)
    at +page.svelte?t=1774689309840:98:16
    at Module.add_svelte_meta (chunk-O3RU4Q5E.js?v=4ba18bce:600:12)

System Info

SvelteLab, also reproduced locally with latest Svelte and SvelteKit

Severity

annoyance

Want to work on this?

Claim this issue to let others know you're working on it. You'll earn 20 points when you complete it!

Risk Flags

  • async behavior
  • destructuring in templates
  • derived values
Loading labels...

Details

Points20 pts
Difficultymedium
Scopesomewhat clear
Skill Matchmaybe
Test Focusedno