Skip to main content
GoodFirstPicks
DashboardIssuesReposLeaderboard

GoodFirstPicks by Leaveitblank © 2026

CreatorRequest a RepoPrivacy PolicyTerms of Service
Svelte breaks vitest mocks/hoists with top-level await | GoodFirstPicks

Svelte breaks vitest mocks/hoists with top-level await

sveltejs/svelte 1 comments 1mo ago
View on GitHub
mediumopenScope: somewhat clearSkill match: maybeTest focusedSvelteTypeScript

Why this is a good first issue

The issue involves complex interaction between Svelte's compilation and Vitest's mocking system.

AI Summary

The problem involves Svelte's compilation output breaking Vitest's hoisting functionality when using top-level await. The fix would need to modify Svelte's compilation output to preserve Vitest's expected syntax while maintaining reactivity tracking. The main challenge is understanding both systems' transformation pipelines.

Issue Description

Describe the bug

See https://github.com/vitest-dev/vitest/issues/9424

In short:

When using Vitest, one can use vi.hoisted() to execute code before top-level imports (which Vitest transforms into await import()s placed after the hoisted declaration). However, for this to work, vi.hoisted needs to be used as part of a top-level variable declaration, like

const num = vi.hoisted(() => 123)
const num2 = await vi.hoisted(async () => 456)

However, this code is first transformed by Svelte into

const num = vi.hoisted(() => 123)
const num2 = (await $.track_reactivity_loss(vi.hoisted(async () => 456)))()

which Vitest cannot process.

In the end, it is impossible to use await vi.hoisted() together with Svelte tests.

Reproduction

https://github.com/rChaoz/svelte-vitest-hoisted-bug-repro

Severity

blocking an upgrade

Want to work on this?

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

Risk Flags

  • requires understanding of both Svelte and Vitest internals
  • potential interaction between two complex systems
Loading labels...

Details

Points10 pts
Difficultymedium
Scopesomewhat clear
Skill Matchmaybe
Test Focusedyes