Skip to content

Conversation

@elohmeier
Copy link
Contributor

🎯 Changes

$effect doesn't run during server-side rendering, so internalData and state remained empty even when the collection was populated with initial data via sync config.

This adds synchronous initialization of state and internalData from the collection immediately after $state declarations, ensuring data is available for SSR before effects run on the client.

Changes:

  • Add synchronous initialization block in useLiveQuery.svelte.ts
  • Add unit tests to verify SSR behavior (data available before flushSync)

✅ Checklist

  • I have followed the steps in the Contributing guide.
  • I have tested this code locally with pnpm test:pr.

🚀 Release Impact

  • This change affects published code, and I have generated a changeset.
  • This change is docs/CI/dev-only (no release).

$effect doesn't run during SSR, so internalData remained empty during
server-side rendering even when the collection was populated with initial
data via sync config.

This adds synchronous initialization of state and internalData from the
collection immediately after $state declarations, ensuring data is
available for SSR before effects run on the client.
@changeset-bot
Copy link

changeset-bot bot commented Jan 29, 2026

🦋 Changeset detected

Latest commit: 21dfb4b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@tanstack/svelte-db Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@pkg-pr-new
Copy link

pkg-pr-new bot commented Jan 29, 2026

More templates

@tanstack/angular-db

npm i https://pkg.pr.new/@tanstack/angular-db@1196

@tanstack/db

npm i https://pkg.pr.new/@tanstack/db@1196

@tanstack/db-ivm

npm i https://pkg.pr.new/@tanstack/db-ivm@1196

@tanstack/electric-db-collection

npm i https://pkg.pr.new/@tanstack/electric-db-collection@1196

@tanstack/offline-transactions

npm i https://pkg.pr.new/@tanstack/offline-transactions@1196

@tanstack/powersync-db-collection

npm i https://pkg.pr.new/@tanstack/powersync-db-collection@1196

@tanstack/query-db-collection

npm i https://pkg.pr.new/@tanstack/query-db-collection@1196

@tanstack/react-db

npm i https://pkg.pr.new/@tanstack/react-db@1196

@tanstack/rxdb-db-collection

npm i https://pkg.pr.new/@tanstack/rxdb-db-collection@1196

@tanstack/solid-db

npm i https://pkg.pr.new/@tanstack/solid-db@1196

@tanstack/svelte-db

npm i https://pkg.pr.new/@tanstack/svelte-db@1196

@tanstack/trailbase-db-collection

npm i https://pkg.pr.new/@tanstack/trailbase-db-collection@1196

@tanstack/vue-db

npm i https://pkg.pr.new/@tanstack/vue-db@1196

commit: 21dfb4b

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