Skip to content

fix: prevent server-side Svelte code in client bundle - #11

Merged
jgordijn merged 1 commit into
mainfrom
fix/vite-resolve-conditions
Mar 4, 2026
Merged

jgordijn merged 1 commit into
mainfrom
fix/vite-resolve-conditions

Conversation

@jgordijn

@jgordijn jgordijn commented Mar 4, 2026

Copy link
Copy Markdown
Owner

Problem

The resolve.conditions config added in #9 (test coverage improvements) set conditions to [] for production builds. In Vite 7, this removed the browser resolve condition, causing Svelte's server-side onDestroy (ssr_context.r.on_destroy) to be bundled into the client.

Result: blank page on load with:

TypeError: Cannot read properties of null (reading 'r')

Fix

Only set resolve.conditions when VITEST is active:

...(process.env.VITEST ? { resolve: { conditions: ['browser'] } } : {})

This keeps the browser condition for Vitest/jsdom while leaving Vite's default resolution untouched for production builds.

The resolve.conditions config added for Vitest support set
conditions to [] for production builds, which removed the
'browser' condition in Vite 7. This caused Svelte's server-side
onDestroy (ssr_context.r.on_destroy) to be bundled into the
client, crashing on page load with:
  TypeError: Cannot read properties of null (reading 'r')

Fix: only set resolve.conditions when VITEST is active.
@jgordijn
jgordijn enabled auto-merge (squash) March 4, 2026 11:11
@jgordijn
jgordijn merged commit 42402dc into main Mar 4, 2026
1 check passed
@jgordijn
jgordijn deleted the fix/vite-resolve-conditions branch March 4, 2026 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant