From 9723c25adac1cffce1dad17e85a7179a130c2330 Mon Sep 17 00:00:00 2001 From: Kris Jenkins Date: Wed, 18 Nov 2026 10:56:31 +0000 Subject: [PATCH 01/15] Stop 'spacetime init' copying a broken generate script into TypeScript projects. Say you scaffold a project with 'spacetime init --template react-ts' (or any of the twelve TypeScript client templates), change your module, and want fresh bindings. package.json has an obvious-looking 'generate' script, so you run 'npm run generate'. It fails: "generate": "pnpm --dir spacetimedb install && cargo run -p gen-bindings -- --out-dir src/module_bindings --module-path spacetimedb && prettier --write src/module_bindings" gen-bindings is a tool in the SpacetimeDB repository's Cargo workspace. The templates use it to regenerate their checked-in bindings, and the repo's own CI calls it through this script ('pnpm generate' in chat-react-ts, and in react-ts via bindings-typescript). Outside the repo there is no such crate, and usually no Cargo at all. The script that actually works for users, 'spacetime:generate', sits a line below it, but the broken one has the name people reach for. Nobody caught it because it works for everyone who maintains the templates: inside the monorepo the script runs fine. 'spacetime init' copies each template's package.json unchanged apart from the name and the spacetimedb version, and the template smoketests only install and publish. Renaming the script in every template would mean changing the repo's CI and SDK scripts that call it. Instead, update_package_json, which already rewrites each template's package.json during init, now drops any script that invokes gen-bindings. The monorepo keeps its workflow, and scaffolded projects get only scripts that can run. A new test runs update_package_json over every embedded template's package.json. It checks that each gen-bindings script is removed and every other script is kept unchanged. It also fails if no template uses gen-bindings any more, so the marker can't go stale silently. Removing the call makes it fail, naming money-exchange-react-ts. Scaffolding svelte-ts with the rebuilt CLI produces a package.json without 'generate' and with its other scripts intact. --- crates/cli/src/subcommands/init.rs | 79 ++++++++++++++++++++++++++++++ 1 file changed, 79 insertions(+) diff --git a/crates/cli/src/subcommands/init.rs b/crates/cli/src/subcommands/init.rs index 0411393788f..0d9643a409d 100644 --- a/crates/cli/src/subcommands/init.rs +++ b/crates/cli/src/subcommands/init.rs @@ -1093,6 +1093,23 @@ fn to_major_minor_patch_wildcard(version: &str) -> String { } } +/// Templates keep a `generate` script that regenerates their checked-in +/// bindings with `cargo run -p gen-bindings`. That tool only exists inside the +/// SpacetimeDB repository, so in a user's project the script can only fail. +/// Users regenerate bindings with `spacetime generate` (or the template's +/// `spacetime:generate` script) instead. +const MONOREPO_ONLY_SCRIPT_MARKER: &str = "gen-bindings"; + +fn remove_monorepo_only_scripts(package: &mut serde_json::Value) { + if let Some(scripts) = package.get_mut("scripts").and_then(|s| s.as_object_mut()) { + scripts.retain(|_, command| { + !command + .as_str() + .is_some_and(|command| command.contains(MONOREPO_ONLY_SCRIPT_MARKER)) + }); + } +} + fn update_package_json(dir: &Path, package_name: &str) -> anyhow::Result<()> { let package_path = dir.join("package.json"); if !package_path.exists() { @@ -1111,6 +1128,8 @@ fn update_package_json(dir: &Path, package_name: &str) -> anyhow::Result<()> { deps["spacetimedb"] = json!(to_major_minor_patch_wildcard(get_spacetimedb_typescript_version())); } + remove_monorepo_only_scripts(&mut package); + let updated_content = serde_json::to_string_pretty(&package)?; fs::write(package_path, updated_content)?; @@ -2471,6 +2490,66 @@ mod tests { ); } + #[test] + fn test_update_package_json_removes_monorepo_only_scripts_from_every_template() { + let mut templates_with_monorepo_scripts = 0; + for (source, files) in embedded::get_template_files() { + let Some(original) = files.get("package.json") else { + continue; + }; + let original: serde_json::Value = serde_json::from_str(original).unwrap(); + let original_scripts = original["scripts"].as_object().cloned().unwrap_or_default(); + if original_scripts + .values() + .any(|command| command.as_str().unwrap_or("").contains("gen-bindings")) + { + templates_with_monorepo_scripts += 1; + } + + let temp = tempfile::TempDir::new().unwrap(); + let package_json = temp.path().join("package.json"); + std::fs::write(&package_json, serde_json::to_string(&original).unwrap()).unwrap(); + update_package_json(temp.path(), "my-app").unwrap(); + let updated: serde_json::Value = + serde_json::from_str(&std::fs::read_to_string(&package_json).unwrap()).unwrap(); + let updated_scripts = updated["scripts"].as_object().cloned().unwrap_or_default(); + + for (name, command) in &original_scripts { + let command = command.as_str().unwrap_or(""); + if command.contains("gen-bindings") { + assert!( + !updated_scripts.contains_key(name), + "{source}: script `{name}` needs the SpacetimeDB repo but was kept" + ); + } else { + assert_eq!( + updated_scripts.get(name).and_then(|c| c.as_str()), + Some(command), + "{source}: script `{name}` should be kept unchanged" + ); + } + } + } + // Guard against the marker going stale: if no template uses it any + // more, this test no longer checks anything. + assert!( + templates_with_monorepo_scripts > 0, + "no embedded template has a gen-bindings script; update MONOREPO_ONLY_SCRIPT_MARKER" + ); + } + + #[test] + fn test_update_package_json_keeps_package_without_scripts() { + let temp = tempfile::TempDir::new().unwrap(); + let package_json = temp.path().join("package.json"); + std::fs::write(&package_json, r#"{ "name": "old-name" }"#).unwrap(); + + update_package_json(temp.path(), "new-name").unwrap(); + + let parsed: serde_json::Value = serde_json::from_str(&std::fs::read_to_string(package_json).unwrap()).unwrap(); + assert_eq!(parsed, serde_json::json!({ "name": "new-name" })); + } + #[test] fn test_update_cargo_toml_rewrites_spacetimedb_deps_to_patch_wildcards() { let temp = tempfile::TempDir::new().unwrap(); From 7e3334ca55667aa3d38ccab6290c60a0b4a1cc9f Mon Sep 17 00:00:00 2001 From: Kris Jenkins Date: Wed, 18 Nov 2026 12:00:10 +0000 Subject: [PATCH 02/15] Build each TypeScript template's client in the template smoketests. Suppose someone changes the TypeScript SDK in a way that breaks a client template: a hook's return type changes, say, so the Vue template's App.vue no longer type-checks. CI runs a smoketest for every template, so surely that template's test fails? It doesn't. For TypeScript templates the test publishes the server module, runs 'pnpm install' for the client, and stops: // TODO: some templates don't pass tsc yet, re-enable once they're fixed. // run_pnpm(&["exec", "tsc", "--noEmit"], project_path)?; So no client code is ever compiled. That isn't hypothetical: building every TypeScript template the way the smoketest scaffolds it shows that vue-ts already doesn't type-check (vue-tsc rejects three expressions in App.vue), tanstack-ts's build can't find an entry module, and bun-ts's build can't start. All three are green in CI today. Users meet these on their first 'npm run build'. The commented-out tsc call wouldn't have caught all of them anyway. Plain tsc doesn't understand .vue or .svelte files, so it can't check the frameworks where type errors hide in templates. The test now runs each template's own build script ('pnpm run --if-present build'). That uses whatever checker the template's framework uses (tsc -b, vue-tsc, svelte-check, ng build, next build), and --if-present covers deno-ts, which has no build script. The three templates that fail today are listed in TYPESCRIPT_CLIENT_BUILD_KNOWN_FAILURES with the reason for each. Their builds are skipped, with a log line, until someone fixes them and deletes the entry. A new unit test fails if an entry no longer names a TypeScript template, so the list can't quietly outlive a rename. Checked by scaffolding all 19 TypeScript templates with the CLI, pointing them at the local SDK and running their builds: 15 build, deno-ts has no build script, and the three listed fail. Then, with the real smoketests: svelte-ts passes with its build running; vue-ts passes with its build skipped; deno-ts passes via --if-present; and with vue-ts removed from the list its smoketest fails, quoting vue-tsc's errors. --- crates/smoketests/tests/cluster/templates.rs | 53 ++++++++++++++++++-- 1 file changed, 49 insertions(+), 4 deletions(-) diff --git a/crates/smoketests/tests/cluster/templates.rs b/crates/smoketests/tests/cluster/templates.rs index 8bc30631734..7c344f76b8a 100644 --- a/crates/smoketests/tests/cluster/templates.rs +++ b/crates/smoketests/tests/cluster/templates.rs @@ -815,7 +815,7 @@ fn test_rust_template(test: &Smoketest, template: &Template, project_path: &Path Ok(()) } -/// Publishes a TypeScript server module and verifies the TypeScript client type-checks. +/// Publishes a TypeScript server module and verifies the TypeScript client builds. fn test_typescript_template(test: &Smoketest, template: &Template, project_path: &Path) -> Result<()> { // Server let server_path = project_path.join("spacetimedb"); @@ -840,18 +840,63 @@ fn test_typescript_template(test: &Smoketest, template: &Template, project_path: })?; let _ = test.spacetime(&["delete", "--server", &test.server_url, "--yes", &domain]); - // Client type-check (only if there's a client package.json in the project root) + // Client build (only if there's a client package.json in the project root) let client_package_json = project_path.join("package.json"); if client_package_json.exists() { setup_typescript_sdk_in_package_json(&client_package_json)?; run_pnpm(&["install"], project_path)?; - // TODO: some templates don't pass tsc yet, re-enable once they're fixed. - // run_pnpm(&["exec", "tsc", "--noEmit"], project_path)?; + if let Some(reason) = typescript_client_build_known_failure(&template.id) { + eprintln!( + "[TEMPLATES] Skipping client build for {}: known failure: {reason}", + template.id + ); + } else { + // Each template's own `build` script, which type-checks where the + // framework's tooling does (tsc, vue-tsc, svelte-check, ...). + run_pnpm(&["run", "--if-present", "build"], project_path) + .with_context(|| format!("Client build failed for template {}", template.id))?; + } } Ok(()) } +/// TypeScript templates whose client `build` script currently fails, and why. +/// Remove an entry as soon as its template is fixed, so the build is checked again. +const TYPESCRIPT_CLIENT_BUILD_KNOWN_FAILURES: &[(&str, &str)] = &[ + ( + "bun-ts", + "pnpm doesn't run the `bun` package's postinstall, so `bun build` can't start", + ), + ("tanstack-ts", "`vite build` can't resolve an entry module (index.html)"), + ( + "vue-ts", + "vue-tsc doesn't unwrap the `Readonly>` that useTable returns in App.vue", + ), +]; + +fn typescript_client_build_known_failure(template_id: &str) -> Option<&'static str> { + TYPESCRIPT_CLIENT_BUILD_KNOWN_FAILURES + .iter() + .find(|(id, _)| *id == template_id) + .map(|(_, reason)| *reason) +} + +#[test] +fn test_typescript_client_build_known_failures_name_real_templates() { + let typescript_templates: Vec = get_templates() + .into_iter() + .filter(|template| template.server_lang.as_deref() == Some("typescript")) + .map(|template| template.id) + .collect(); + for (id, _) in TYPESCRIPT_CLIENT_BUILD_KNOWN_FAILURES { + assert!( + typescript_templates.iter().any(|template| template == id), + "known-failure entry {id} is not a TypeScript template; remove it" + ); + } +} + /// Publishes a C# server module and verifies the C# client builds. fn test_csharp_template(test: &Smoketest, template: &Template) -> Result<()> { for dotnet_version in ["8", "10"] { From 43448453636af29853af6e9a6e65a929f95ae1be Mon Sep 17 00:00:00 2001 From: Kris Jenkins Date: Wed, 18 Nov 2026 12:31:38 +0000 Subject: [PATCH 03/15] Install the local SDK into template smoketests as an injected dependency. The template smoketest now builds each TypeScript template's client, and vue-ts was on its known-failures list because vue-tsc rejected App.vue: src/App.vue(52,29): error TS2339: Property 'length' does not exist on type 'Readonly>'. That reads like a bug in the template, or in the Vue bindings' useTable types. If so, every Vue user would hit it on their first build. They don't: the same template type-checks cleanly inside the repo, and the error only appears in the project the smoketest scaffolds. The difference is how that project gets the SDK. The smoketest points 'spacetimedb' at crates/bindings-typescript, and pnpm symlinks a local directory dependency. The SDK's type declarations then resolve their optional framework peers from the monorepo's node_modules, so in the scaffolded vue-ts project the SDK sees vue 3.5.26 while the app has its own fresh vue 3.5.45. Vue brands Ref with a unique symbol, so a Ref declared against one copy isn't recognised as a Ref by the other, and vue-tsc can't unwrap 'people' in the template. A user installing the published package gets one copy of vue, resolved from their project. So the smoketest wasn't testing what users get. It now also sets dependenciesMeta.spacetimedb.injected, which makes pnpm copy the SDK into the project and resolve its peers there, as a registry install would. The helper comment explains why. vue-ts comes off the known-failures list. Injecting the SDK also turns an old race into a reliable failure. Every TypeScript test called build_typescript_sdk(), which runs pnpm install and pnpm build in crates/bindings-typescript, and the local runner runs 16 tests at once. One test's build clears dist while another test's pnpm install is copying it, so a parallel run fails at random: pnpm reports missing files under dist, or a template can't import spacetimedb/server. With a symlink the race was easy to miss, because a project only read dist once the build had finished. CI's partitions run with -j 1, so CI never saw it. So the runner now builds the SDK once, before any test starts, both for a local run and for CI's run-archive, and sets SPACETIME_SMOKETEST_TS_SDK_PREBUILT for the tests, which makes build_typescript_sdk() return early. templates.rs drops its own copy of that build and uses the library's. A test run directly with cargo test still builds the SDK itself, as before. - The runner finds pnpm with which, so Windows resolves pnpm.cmd. - It builds relative to the current directory rather than the library's workspace_root(), which is fixed at compile time, because CI runs the runner in a different job from the one that built it. Checked with the template smoketests for all 19 TypeScript templates, one at a time as CI runs them (-j 1): all pass, vue-ts now builds its client, and only bun-ts and tanstack-ts are still skipped. With the runner's default of -j 16, the whole templates:: suite (less the C++ and C# templates, which can't run on this machine) also passes: 23 tests in 69s, where before the fix six TypeScript templates failed. --- Cargo.lock | 1 + crates/smoketests/src/lib.rs | 19 +++++- crates/smoketests/tests/cluster/templates.rs | 56 +++++++++++----- tools/ci/commands/smoketests/Cargo.toml | 1 + tools/ci/commands/smoketests/src/main.rs | 67 ++++++++++++++++++-- 5 files changed, 123 insertions(+), 21 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 879e940a32a..a8252003541 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1180,6 +1180,7 @@ dependencies = [ "duct", "spacetimedb-guard", "tempfile", + "which 8.0.0", ] [[package]] diff --git a/crates/smoketests/src/lib.rs b/crates/smoketests/src/lib.rs index 2b9285dcab7..cb56a6513d3 100644 --- a/crates/smoketests/src/lib.rs +++ b/crates/smoketests/src/lib.rs @@ -410,8 +410,25 @@ pub fn pnpm(args: &[&str], cwd: &Path) -> Result { Ok(String::from_utf8_lossy(&output.stdout).to_string()) } -/// Builds the local TypeScript bindings package. +/// Set by the smoketest runner once it has built the TypeScript SDK, so that +/// tests skip rebuilding it. +pub const TYPESCRIPT_SDK_PREBUILT_ENV: &str = "SPACETIME_SMOKETEST_TS_SDK_PREBUILT"; + +/// Builds the local TypeScript bindings package, unless the runner has already +/// built it. +/// +/// Tests run in parallel and share one copy of the SDK. Rebuilding it clears +/// `dist/` while other tests may be copying it into their projects, so the +/// runner builds it once up front, and tests only build it when run directly. pub fn build_typescript_sdk() -> Result<()> { + if std::env::var_os(TYPESCRIPT_SDK_PREBUILT_ENV).is_some() { + return Ok(()); + } + prebuild_typescript_sdk() +} + +/// Builds the local TypeScript bindings package unconditionally. +pub fn prebuild_typescript_sdk() -> Result<()> { let workspace = workspace_root(); let ts_bindings = workspace.join("crates/bindings-typescript"); pnpm(&["--filter", "spacetimedb", "install"], &ts_bindings)?; diff --git a/crates/smoketests/tests/cluster/templates.rs b/crates/smoketests/tests/cluster/templates.rs index 7c344f76b8a..647763df5b5 100644 --- a/crates/smoketests/tests/cluster/templates.rs +++ b/crates/smoketests/tests/cluster/templates.rs @@ -12,7 +12,7 @@ use anyhow::{bail, Context, Result}; use regex::Regex; use serde_json::Value; -use spacetimedb_smoketests::{pnpm, random_string, workspace_root, Smoketest}; +use spacetimedb_smoketests::{build_typescript_sdk, pnpm, random_string, workspace_root, Smoketest}; use std::env; use std::fs; use std::path::{Path, PathBuf}; @@ -590,22 +590,12 @@ fn pin_csharp_client_sdk_package_version(project_path: &Path) -> Result<()> { Ok(()) } -/// Builds the TypeScript SDK (`crates/bindings-typescript`). -/// -/// Should be called once before testing any TypeScript templates. -fn build_typescript_sdk() -> Result<()> { - let sdk_path = workspace_root().join("crates/bindings-typescript"); - eprintln!("[TEMPLATES] Building TypeScript SDK at {:?}", sdk_path); - run_pnpm(&["--filter", "spacetimedb", "install"], &sdk_path)?; - run_pnpm(&["build"], &sdk_path)?; - Ok(()) -} - /// Points the `spacetimedb` entry in `package.json` at the local TypeScript /// SDK and removes the template's lockfile so pnpm re-resolves dependencies. fn setup_typescript_sdk_in_package_json(package_json_path: &Path) -> Result<()> { let sdk_path = workspace_root().join("crates/bindings-typescript"); update_package_json_dependency(package_json_path, "spacetimedb", &sdk_path)?; + inject_package_json_dependency(package_json_path, "spacetimedb")?; // Remove the template's lockfile; the dependency changed. let lockfile = package_json_path.parent().unwrap().join("pnpm-lock.yaml"); @@ -615,6 +605,44 @@ fn setup_typescript_sdk_in_package_json(package_json_path: &Path) -> Result<()> Ok(()) } +/// Marks a local-path dependency as injected (`dependenciesMeta..injected`). +/// +/// By default pnpm symlinks a local directory dependency, so the SDK resolves +/// its own imports, including the type declarations of its optional framework +/// peers (vue, react, svelte, ...), from the monorepo's `node_modules` rather +/// than the project's. The project then sees two copies of, for example, Vue's +/// types, and Vue brands `Ref` with a `unique symbol`, so a `Ref` from one copy +/// isn't recognised by the other. Injecting copies the SDK into the project and +/// resolves its peers there, as installing the published package would. +fn inject_package_json_dependency(package_json_path: &Path, package_name: &str) -> Result<()> { + let content = + fs::read_to_string(package_json_path).with_context(|| format!("Failed to read {:?}", package_json_path))?; + let mut data: Value = + serde_json::from_str(&content).with_context(|| format!("Failed to parse {:?}", package_json_path))?; + + let has_dependency = data + .get("dependencies") + .is_some_and(|deps| deps.get(package_name).is_some()); + if !has_dependency { + return Ok(()); + } + let Some(package) = data.as_object_mut() else { + bail!("{:?} is not a JSON object", package_json_path); + }; + let meta = package + .entry("dependenciesMeta") + .or_insert_with(|| Value::Object(Default::default())); + let Some(meta) = meta.as_object_mut() else { + bail!("dependenciesMeta in {:?} is not a JSON object", package_json_path); + }; + meta.insert(package_name.to_string(), serde_json::json!({ "injected": true })); + + let new_content = + serde_json::to_string_pretty(&data).with_context(|| format!("Failed to serialize {:?}", package_json_path))?; + fs::write(package_json_path, new_content).with_context(|| format!("Failed to write {:?}", package_json_path))?; + Ok(()) +} + /// Rewires the Rust server module's `spacetimedb` dependency to the local /// `crates/bindings` path. /// @@ -869,10 +897,6 @@ const TYPESCRIPT_CLIENT_BUILD_KNOWN_FAILURES: &[(&str, &str)] = &[ "pnpm doesn't run the `bun` package's postinstall, so `bun build` can't start", ), ("tanstack-ts", "`vite build` can't resolve an entry module (index.html)"), - ( - "vue-ts", - "vue-tsc doesn't unwrap the `Readonly>` that useTable returns in App.vue", - ), ]; fn typescript_client_build_known_failure(template_id: &str) -> Option<&'static str> { diff --git a/tools/ci/commands/smoketests/Cargo.toml b/tools/ci/commands/smoketests/Cargo.toml index f161fe64586..7f0b5c2d1a2 100644 --- a/tools/ci/commands/smoketests/Cargo.toml +++ b/tools/ci/commands/smoketests/Cargo.toml @@ -9,4 +9,5 @@ duct.workspace = true clap.workspace = true tempfile.workspace = true spacetimedb-guard.workspace = true +which = "8.0.0" ci-common = { path = "../../common" } diff --git a/tools/ci/commands/smoketests/src/main.rs b/tools/ci/commands/smoketests/src/main.rs index 869a75532d2..a6f42e9e5dd 100644 --- a/tools/ci/commands/smoketests/src/main.rs +++ b/tools/ci/commands/smoketests/src/main.rs @@ -193,6 +193,37 @@ fn build_precompiled_modules() -> Result<()> { Ok(()) } +/// Tells test processes the TypeScript SDK is already built. Must match +/// `spacetimedb_smoketests::TYPESCRIPT_SDK_PREBUILT_ENV`. +const TYPESCRIPT_SDK_PREBUILT_ENV: &str = "SPACETIME_SMOKETEST_TS_SDK_PREBUILT"; + +/// Builds the TypeScript SDK (`crates/bindings-typescript`) that the TypeScript +/// smoketests install into their projects. +/// +/// Tests run in parallel and share this one copy of the SDK. If each test built +/// it, one test's build would clear `dist/` while another was copying it into +/// its project. Returns whether the SDK was built; without pnpm the TypeScript +/// tests skip themselves, so there is nothing to build. +fn build_typescript_sdk(workspace_root: &Path) -> Result { + let Ok(pnpm) = which::which("pnpm") else { + eprintln!("Skipping TypeScript SDK build (pnpm not found).\n"); + return Ok(false); + }; + let sdk_dir = workspace_root.join("crates/bindings-typescript"); + + eprintln!("Building TypeScript SDK..."); + for args in [&["--filter", "spacetimedb", "install"][..], &["build"]] { + let status = Command::new(&pnpm).args(args).current_dir(&sdk_dir).status()?; + ensure!( + status.success(), + "Failed to build TypeScript SDK: pnpm {}", + args.join(" ") + ); + } + eprintln!("TypeScript SDK built.\n"); + Ok(true) +} + fn archive_smoketests(archive_file: &Path, suite: SmoketestSuite) -> Result<()> { build_precompiled_modules()?; @@ -220,9 +251,10 @@ fn run_smoketest_archive(archive_file: &Path, args: Vec) -> Result<()> { let cli_path = ensure_binaries_built(); let base_config_dir = prepare_base_config(&cli_path, None, None)?; let base_config_path = base_config_dir.path().join("config.toml"); + let typescript_sdk_prebuilt = build_typescript_sdk(&workspace_root)?; let mut cmd = Command::new("cargo"); - set_env(&mut cmd, None, true, false, &base_config_path); + set_env(&mut cmd, None, true, false, &base_config_path, typescript_sdk_prebuilt); cmd.args(["nextest", "run", "--archive-file"]) .arg(archive_file) .args(["--workspace-remap"]) @@ -266,6 +298,9 @@ fn run_smoketest( // 2. Build pre-compiled modules (this also warms the WASM dependency cache) build_precompiled_modules()?; + // 3. Build the TypeScript SDK once, rather than in every test that uses it + let typescript_sdk_prebuilt = build_typescript_sdk(&env::current_dir()?)?; + let cli_path = ensure_binaries_built(); let base_config_dir = prepare_base_config(&cli_path, server.as_deref(), auth_host)?; let base_config_path = base_config_dir.path().join("config.toml"); @@ -287,7 +322,14 @@ fn run_smoketest( let mut cmd = if use_nextest { eprintln!("Running smoketests with cargo nextest...\n"); let mut cmd = Command::new("cargo"); - set_env(&mut cmd, server, dotnet, auth_host.is_some(), &base_config_path); + set_env( + &mut cmd, + server, + dotnet, + auth_host.is_some(), + &base_config_path, + typescript_sdk_prebuilt, + ); cmd.args(["nextest", "run", "--release", "-p", "spacetimedb-smoketests"]) .args(suite.cargo_args()) .arg("--no-fail-fast"); @@ -304,7 +346,14 @@ fn run_smoketest( } else { eprintln!("Running smoketests with cargo test...\n"); let mut cmd = Command::new("cargo"); - set_env(&mut cmd, server, dotnet, auth_host.is_some(), &base_config_path); + set_env( + &mut cmd, + server, + dotnet, + auth_host.is_some(), + &base_config_path, + typescript_sdk_prebuilt, + ); cmd.args(["test", "--release", "-p", "spacetimedb-smoketests"]) .args(suite.cargo_args()); cmd @@ -385,7 +434,17 @@ fn prepare_base_config(cli_path: &Path, server: Option<&str>, auth_host: Option< Ok(temp_dir) } -fn set_env(cmd: &mut Command, server: Option, dotnet: bool, auth_host: bool, base_config_path: &Path) { +fn set_env( + cmd: &mut Command, + server: Option, + dotnet: bool, + auth_host: bool, + base_config_path: &Path, + typescript_sdk_prebuilt: bool, +) { + if typescript_sdk_prebuilt { + cmd.env(TYPESCRIPT_SDK_PREBUILT_ENV, "1"); + } if let Some(ref server_url) = server { cmd.env("SPACETIME_REMOTE_SERVER", server_url); } From 7952591804851b36e834a1e981661281d74bc302 Mon Sep 17 00:00:00 2001 From: Kris Jenkins Date: Wed, 18 Nov 2026 14:25:31 +0000 Subject: [PATCH 04/15] Check the tanstack-ts template's client build in the template smoketest again. The template smoketest builds each TypeScript template's client, but it has been skipping tanstack-ts as a known failure: ("tanstack-ts", "`vite build` can't resolve an entry module (index.html)"), That failure came from the template asking for Vite 7 while @tanstack/react-start 1.169.0 and later need Vite 8. On Vite 7, TanStack Start's plugin doesn't register its build environments, so Vite falls back to looking for an index.html the template was never meant to have. Master's dependency update (25567d1961) has since moved the template to vite ^8.3.8, @vitejs/plugin-react ^6.3.0 and react-start ^1.169.7, which fixes the build. But nothing told the smoketest, so it would go on skipping a build that now works, and a future regression would go unnoticed. This removes tanstack-ts from TYPESCRIPT_CLIENT_BUILD_KNOWN_FAILURES, leaving only bun-ts. Verified: in-repo, `pnpm run build` in templates/tanstack-ts succeeds on Vite 8. --- crates/smoketests/tests/cluster/templates.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/crates/smoketests/tests/cluster/templates.rs b/crates/smoketests/tests/cluster/templates.rs index 647763df5b5..f2f9c8522d9 100644 --- a/crates/smoketests/tests/cluster/templates.rs +++ b/crates/smoketests/tests/cluster/templates.rs @@ -891,13 +891,10 @@ fn test_typescript_template(test: &Smoketest, template: &Template, project_path: /// TypeScript templates whose client `build` script currently fails, and why. /// Remove an entry as soon as its template is fixed, so the build is checked again. -const TYPESCRIPT_CLIENT_BUILD_KNOWN_FAILURES: &[(&str, &str)] = &[ - ( - "bun-ts", - "pnpm doesn't run the `bun` package's postinstall, so `bun build` can't start", - ), - ("tanstack-ts", "`vite build` can't resolve an entry module (index.html)"), -]; +const TYPESCRIPT_CLIENT_BUILD_KNOWN_FAILURES: &[(&str, &str)] = &[( + "bun-ts", + "pnpm doesn't run the `bun` package's postinstall, so `bun build` can't start", +)]; fn typescript_client_build_known_failure(template_id: &str) -> Option<&'static str> { TYPESCRIPT_CLIENT_BUILD_KNOWN_FAILURES From e29e7159d4143f7da1df142a192f1b67dfc3e47d Mon Sep 17 00:00:00 2001 From: Kris Jenkins Date: Wed, 18 Nov 2026 09:38:32 +0000 Subject: [PATCH 05/15] Add useProcedure to the Svelte bindings. The React, Vue and Solid bindings all export a useProcedure hook, and the TypeScript client reference says the Svelte integration 'provides the same hooks as React'. It didn't: spacetimedb/svelte exported useTable and useReducer but nothing for procedures. A Svelte app that wanted to call a procedure had to reach into useSpacetimeDB(), call getConnection(), handle the null case itself before the socket was up, and look the procedure up by accessor name by hand. That is exactly the boilerplate the hooks exist to remove, and nothing pointed Svelte users at the gap. The new hook mirrors useReducer in the same package: calls made before a connection exists are queued and flushed (resolving with the procedure's return value) as soon as the connection store reports one, and the store subscription is dropped in onDestroy so an unmounted component stops flushing. --- .../bindings-typescript/src/svelte/index.ts | 1 + .../src/svelte/useProcedure.ts | 57 +++++++++++++++++++ 2 files changed, 58 insertions(+) create mode 100644 crates/bindings-typescript/src/svelte/useProcedure.ts diff --git a/crates/bindings-typescript/src/svelte/index.ts b/crates/bindings-typescript/src/svelte/index.ts index b32fbdf4b80..3b3e64aba48 100644 --- a/crates/bindings-typescript/src/svelte/index.ts +++ b/crates/bindings-typescript/src/svelte/index.ts @@ -2,3 +2,4 @@ export * from './SpacetimeDBProvider.ts'; export { useSpacetimeDB } from './useSpacetimeDB.ts'; export { useTable } from './useTable.ts'; export { useReducer } from './useReducer.ts'; +export { useProcedure } from './useProcedure.ts'; diff --git a/crates/bindings-typescript/src/svelte/useProcedure.ts b/crates/bindings-typescript/src/svelte/useProcedure.ts new file mode 100644 index 00000000000..001dfc0a8de --- /dev/null +++ b/crates/bindings-typescript/src/svelte/useProcedure.ts @@ -0,0 +1,57 @@ +import { getByAccessorPath } from '../lib/accessor_path.ts'; +import { onDestroy } from 'svelte'; +import { get } from 'svelte/store'; +import type { UntypedProcedureDef } from '../sdk/procedures.ts'; +import { useSpacetimeDB } from './useSpacetimeDB.ts'; +import type { + ProcedureParamsType, + ProcedureReturnType, +} from '../sdk/type_utils.ts'; + +export function useProcedure( + procedureDef: ProcedureDef +): ( + ...params: ProcedureParamsType +) => Promise> { + const connectionStore = useSpacetimeDB(); + const procedureName = procedureDef.accessorName; + + // Holds calls made before the connection exists + const queue: { + params: ProcedureParamsType; + resolve: (val: ProcedureReturnType) => void; + reject: (err: unknown) => void; + }[] = []; + + // Flush when we finally have a connection + const unsubscribe = connectionStore.subscribe(state => { + const conn = state.getConnection(); + if (!conn || !queue.length) return; + + const fn = getByAccessorPath(conn.procedures, procedureName) as ( + ...p: ProcedureParamsType + ) => Promise>; + for (const item of queue.splice(0)) { + fn(...item.params).then(item.resolve, item.reject); + } + }); + + onDestroy(() => { + unsubscribe(); + }); + + return (...params: ProcedureParamsType) => { + const conn = get(connectionStore).getConnection(); + if (!conn) { + return new Promise>( + (resolve, reject) => { + queue.push({ params, resolve, reject }); + } + ); + } + const fn = getByAccessorPath(conn.procedures, procedureName) as ( + ...p: ProcedureParamsType + ) => Promise>; + return fn(...params); + }; +} From b81b822c71cc001e597b89c742021c9ca68ac225 Mon Sep 17 00:00:00 2001 From: Kris Jenkins Date: Wed, 18 Nov 2026 09:43:38 +0000 Subject: [PATCH 06/15] Tighten up the Svelte bindings' store handling. Three small problems in spacetimedb/svelte, each found by putting it next to the React bindings it was ported from. First, createSpacetimeDBProvider() and useSpacetimeDB() returned a Writable store. Nothing in the bindings ever expected anyone but the ConnectionManager to write it, but the type invited it: a component could write const conn = useSpacetimeDB(); $conn = { ...$conn, isActive: true }; and every useTable/useReducer under that provider would believe the connection was live until the manager's next update overwrote the lie. The store is now exposed through svelte/store's readonly(), so the type is Readable and that assignment no longer compiles. readonly() has been in svelte/store since 3.56, so the declared ^4 || ^5 peer range still holds. Code that only reads $conn, which is all the template and docs do, is unaffected. Second, useTable called get(connectionStore) every time it recomputed rows, which happens once per transaction touching the table. The Svelte docs warn against get() on hot paths because each call subscribes and immediately unsubscribes. useTable already holds a live subscription to that store, so it now keeps the latest state from that subscription and reads it directly. Third, useTable decided whether a row callback belonged to a transaction it had already re-rendered for by comparing event objects by identity, while React compares event.id. The SDK creates one event object per transaction, so the two are equivalent today; the Svelte code now uses the id, like React, so it doesn't silently depend on that. Also, useReducer carried a private copy of the ParamsType helper; it now imports the one in sdk/type_utils.ts, like React's useReducer and the new Svelte useProcedure. The cross-framework reconnect tests in tests/framework_table_reconnect.test.ts still pass against useTable. The changes were also checked with a scratch harness that mounts real Svelte 5 components under jsdom against a fake connection: rows recompute once per transaction id, onInsert fires per row, swapping the connection drops the old listeners and subscription and rebinds to the new one, and unmounting removes all listeners. svelte-check and vite build of templates/svelte-ts pass against the rebuilt package. --- .../src/svelte/SpacetimeDBProvider.ts | 11 +++-- .../src/svelte/useReducer.ts | 10 +---- .../src/svelte/useSpacetimeDB.ts | 6 +-- .../src/svelte/useTable.ts | 42 ++++++++----------- 4 files changed, 29 insertions(+), 40 deletions(-) diff --git a/crates/bindings-typescript/src/svelte/SpacetimeDBProvider.ts b/crates/bindings-typescript/src/svelte/SpacetimeDBProvider.ts index 20480c500ef..740af1030b9 100644 --- a/crates/bindings-typescript/src/svelte/SpacetimeDBProvider.ts +++ b/crates/bindings-typescript/src/svelte/SpacetimeDBProvider.ts @@ -1,5 +1,5 @@ import { setContext, onDestroy } from 'svelte'; -import { writable, type Writable } from 'svelte/store'; +import { readonly, writable, type Readable } from 'svelte/store'; import { DbConnectionBuilder, type DbConnectionImpl, @@ -32,7 +32,7 @@ export function createSpacetimeDBProvider< DbConnection extends DbConnectionImpl, >( connectionBuilder: DbConnectionBuilder -): Writable { +): Readable { const key = ConnectionManager.getKey( connectionBuilder.getUri(), connectionBuilder.getModuleName() @@ -72,6 +72,9 @@ export function createSpacetimeDBProvider< ConnectionManager.release(key); }); - setContext(SPACETIMEDB_CONTEXT_KEY, store); - return store; + // Hand out a read-only view: the state is owned by the ConnectionManager, so + // writes from components would only be overwritten (or worse, believed). + const readable = readonly(store); + setContext(SPACETIMEDB_CONTEXT_KEY, readable); + return readable; } diff --git a/crates/bindings-typescript/src/svelte/useReducer.ts b/crates/bindings-typescript/src/svelte/useReducer.ts index f574932674a..8bdff9d8852 100644 --- a/crates/bindings-typescript/src/svelte/useReducer.ts +++ b/crates/bindings-typescript/src/svelte/useReducer.ts @@ -1,17 +1,9 @@ import { getByAccessorPath } from '../lib/accessor_path.ts'; import { onDestroy } from 'svelte'; import { get } from 'svelte/store'; -import type { InferTypeOfParams } from '../lib/type_builders.ts'; import type { UntypedReducerDef } from '../sdk/reducers.ts'; +import type { ParamsType } from '../sdk/type_utils.ts'; import { useSpacetimeDB } from './useSpacetimeDB.ts'; -import type { Prettify } from '../lib/type_util.ts'; - -type IsEmptyObject = [keyof T] extends [never] ? true : false; -type MaybeParams = IsEmptyObject extends true ? [] : [params: T]; - -type ParamsType = MaybeParams< - Prettify> ->; export function useReducer( reducerDef: ReducerDef diff --git a/crates/bindings-typescript/src/svelte/useSpacetimeDB.ts b/crates/bindings-typescript/src/svelte/useSpacetimeDB.ts index af74990e85c..7f525e1d6db 100644 --- a/crates/bindings-typescript/src/svelte/useSpacetimeDB.ts +++ b/crates/bindings-typescript/src/svelte/useSpacetimeDB.ts @@ -1,13 +1,13 @@ import { getContext } from 'svelte'; -import type { Writable } from 'svelte/store'; +import type { Readable } from 'svelte/store'; import { SPACETIMEDB_CONTEXT_KEY, type ConnectionState, } from './connection_state.ts'; // Throws an error if used outside of a SpacetimeDBProvider -export function useSpacetimeDB(): Writable { - const context = getContext | undefined>( +export function useSpacetimeDB(): Readable { + const context = getContext | undefined>( SPACETIMEDB_CONTEXT_KEY ); diff --git a/crates/bindings-typescript/src/svelte/useTable.ts b/crates/bindings-typescript/src/svelte/useTable.ts index 24fb55d9350..742cf4c4665 100644 --- a/crates/bindings-typescript/src/svelte/useTable.ts +++ b/crates/bindings-typescript/src/svelte/useTable.ts @@ -1,7 +1,7 @@ import type { UntypedClientTable } from '../sdk/client_table.ts'; import { getByAccessorPath } from '../lib/accessor_path.ts'; import { onDestroy } from 'svelte'; -import { writable, get, type Readable } from 'svelte/store'; +import { writable, type Readable } from 'svelte/store'; import { useSpacetimeDB } from './useSpacetimeDB.ts'; import type { ConnectionState } from './connection_state.ts'; import type { EventContextInterface } from '../sdk/db_connection_impl.ts'; @@ -75,13 +75,17 @@ export function useTable( let appliedConnectionId: string | null = null; let subscribedConnection: ReturnType = null; - let latestTransactionEvent: any = null; + // The latest connection state, kept current by the store subscription below. + // Reading it here instead of calling `get(connectionStore)` avoids a + // subscribe/unsubscribe round trip on every transaction. + let currentState: ConnectionState | undefined; + + let latestTransactionEventId: string | null = null; let unsubscribeFromTable: (() => void) | null = null; let subscriptionHandle: { unsubscribe: () => void } | null = null; const computeFilteredRows = (): readonly Prettify[] => { - const state = get(connectionStore); - const connection = state.getConnection(); + const connection = currentState?.getConnection(); if (!connection) return []; const table = getByAccessorPath( @@ -100,8 +104,7 @@ export function useTable( }; const setupTableListeners = () => { - const state = get(connectionStore); - const connection = state.getConnection(); + const connection = currentState?.getConnection(); if (!connection) return; const table = getByAccessorPath( @@ -117,11 +120,8 @@ export function useTable( if (whereExpr && !evaluateBooleanExpr(whereExpr, row)) return; callbacks?.onInsert?.(row); - if ( - eventCtx.event !== latestTransactionEvent || - !latestTransactionEvent - ) { - latestTransactionEvent = eventCtx.event; + if (eventCtx.event.id !== latestTransactionEventId) { + latestTransactionEventId = eventCtx.event.id; rows.set(computeFilteredRows()); } }; @@ -133,11 +133,8 @@ export function useTable( if (whereExpr && !evaluateBooleanExpr(whereExpr, row)) return; callbacks?.onDelete?.(row); - if ( - eventCtx.event !== latestTransactionEvent || - !latestTransactionEvent - ) { - latestTransactionEvent = eventCtx.event; + if (eventCtx.event.id !== latestTransactionEventId) { + latestTransactionEventId = eventCtx.event.id; rows.set(computeFilteredRows()); } }; @@ -163,11 +160,8 @@ export function useTable( return; } - if ( - eventCtx.event !== latestTransactionEvent || - !latestTransactionEvent - ) { - latestTransactionEvent = eventCtx.event; + if (eventCtx.event.id !== latestTransactionEventId) { + latestTransactionEventId = eventCtx.event.id; rows.set(computeFilteredRows()); } }; @@ -184,8 +178,7 @@ export function useTable( }; const setupSubscription = () => { - const state = get(connectionStore); - const connection = state.getConnection(); + const connection = currentState?.getConnection(); if (!connection) return; subscriptionHandle = connection @@ -203,6 +196,7 @@ export function useTable( }; const unsubscribeConnection = connectionStore.subscribe(state => { + currentState = state; const connection = state.getConnection(); isReady.set( state.isActive && appliedConnectionId === state.connectionId.toHexString() @@ -235,7 +229,7 @@ export function useTable( unsubscribeConnection(); unsubscribeFromTable?.(); subscriptionHandle?.unsubscribe(); - latestTransactionEvent = null; + latestTransactionEventId = null; }); return [{ subscribe: rows.subscribe }, { subscribe: isReady.subscribe }]; From b74b3cade79a184ff911fe2956ab36f76c046ec6 Mon Sep 17 00:00:00 2001 From: Kris Jenkins Date: Wed, 18 Nov 2026 09:45:39 +0000 Subject: [PATCH 07/15] Fix the Svelte section of the TypeScript client reference. Someone setting up a Svelte client from the reference would copy its first line: import { SpacetimeDBProvider, useSpacetimeDB, useTable, useReducer } from 'spacetimedb/svelte'; and get a compile error, because spacetimedb/svelte has no SpacetimeDBProvider. Svelte has no component-wrapping provider like React's; the export is createSpacetimeDBProvider(), a function you call in a root component's + + +``` + +#### `useSpacetimeDB()` + +Returns a readable store of the current connection state. Besides `getConnection()`, the state includes `reconnect(builder)`, which tears down the connection and reconnects with a new builder, for example to apply a new token after sign-in. Table hooks re-subscribe automatically. + +```svelte + + +

{$conn.isActive ? 'Connected' : 'Disconnected'}

+``` + +#### `useTable(query, callbacks?)` + +Returns `[Readable, Readable]`. It accepts the same queries and `onInsert`, `onDelete` and `onUpdate` callbacks as React. The query is read once when the component initializes, so to change it, re-create the component (for example with `{#key}`): ```svelte {#if $isReady} - {#each $users as user} + {#each $users as user (user.identity.toHexString())}
{user.name}
{/each} {/if} ``` + +#### `useReducer(reducer)` and `useProcedure(procedure)` + +Return functions that call a reducer or procedure. Calls made before the connection is ready are queued and sent once connected: + +```svelte + + + +``` From 2b283cf77d1ae099bc1b8a518927f5f69103fa8f Mon Sep 17 00:00:00 2001 From: Kris Jenkins Date: Wed, 18 Nov 2026 10:19:52 +0000 Subject: [PATCH 08/15] Make the svelte-ts template type-check its build, and update its tooling. Picture someone who has just run 'spacetime dev --template svelte-ts'. They rename a column in their module, regenerate bindings, and run the build to see what broke. With the React template, 'tsc -b && vite build' would list every stale reference. With the Svelte template the build passes: its build script was plain 'vite build', which strips TypeScript without checking it. svelte-check was in devDependencies, but no script ever ran it. The errors only surface at runtime, in the browser, as undefined fields. Nothing failed in CI either, because the template smoketest installs and publishes but doesn't type-check client code. So the template had a type checker and never used it. The rest of the tooling had drifted from current Svelte practice too: - vite was on ^6.4.1 while React and most other templates are on ^7.1.5, with @sveltejs/vite-plugin-svelte ^5 to match. - svelte.config.js ran vitePreprocess(). Since Svelte 5, type-only TypeScript compiles without a preprocessor, and Vite's own svelte-ts scaffold ships an empty config. - tsconfig.json lacked verbatimModuleSyntax, which the Svelte TypeScript docs recommend, and didn't load Svelte's ambient types. - .gitignore listed .svelte-kit, though this isn't a SvelteKit project. This adds a 'check' script and makes 'build' run svelte-check first. It calls svelte-check directly rather than via 'pnpm run' so the script still works for anyone who scaffolds the template with npm. It also: - bumps vite to ^7.1.5, @sveltejs/vite-plugin-svelte to ^6.2.4 (the newest line that supports vite 7) and svelte-check to ^4.7.8. svelte's floor moves to ^5.46.4, the version already locked; 5.58.0 is inside the repo's minimum release age. - empties svelte.config.js. - turns on verbatimModuleSyntax and adds 'svelte' to types. The generated module_bindings already comply. - drops .svelte-kit from .gitignore. The lockfile was updated with an install filtered to this template. Besides the template's own upgrades, pnpm deduplicated vitest's vite peer onto the 7.3.2 already in the lockfile and bumped magic-string a patch. Verified with svelte-check (0 errors), vite build, the vite dev server, and by planting errors: a type error now fails the build, and a non-type import of a type-only export is now rejected. The bindings-typescript unit tests pass apart from the two wasm test files, which need a wasm artefact that isn't built locally. --- pnpm-lock.yaml | 126 +++++++++++++-------------- templates/svelte-ts/.gitignore | 1 - templates/svelte-ts/package.json | 11 +-- templates/svelte-ts/svelte.config.js | 7 +- templates/svelte-ts/tsconfig.json | 3 +- 5 files changed, 69 insertions(+), 79 deletions(-) diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index a724ddce8e2..2b98d82a7fc 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -145,7 +145,7 @@ importers: version: 8.40.0(eslint@9.39.5(jiti@2.7.0))(typescript@5.9.3) '@vitest/coverage-v8': specifier: ^3.2.6 - version: 3.2.7(vitest@3.2.7(@types/debug@4.1.13)(@types/node@24.3.0)(jiti@2.7.0)(jsdom@26.1.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1)) + version: 3.2.7(vitest@3.2.7(@types/debug@4.1.13)(@types/node@22.18.0)(jiti@2.7.0)(jsdom@26.1.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1)) brotli-size-cli: specifier: ^1.0.0 version: 1.0.0 @@ -175,7 +175,7 @@ importers: version: 5.43.1 ts-node: specifier: ^10.9.2 - version: 10.9.2(@types/node@24.3.0)(typescript@5.9.3) + version: 10.9.2(@types/node@22.18.0)(typescript@5.9.3) tsup: specifier: ^8.1.0 version: 8.5.1(jiti@2.7.0)(postcss@8.5.33)(tsx@4.23.15)(typescript@5.9.3)(yaml@2.9.1) @@ -187,10 +187,10 @@ importers: version: 8.40.0(eslint@9.39.5(jiti@2.7.0))(typescript@5.9.3) vite: specifier: ^7.3.8 - version: 7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1) + version: 7.3.8(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1) vitest: specifier: ^3.2.7 - version: 3.2.7(@types/debug@4.1.13)(@types/node@24.3.0)(jiti@2.7.0)(jsdom@26.1.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1) + version: 3.2.7(@types/debug@4.1.13)(@types/node@22.18.0)(jiti@2.7.0)(jsdom@26.1.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1) crates/bindings-typescript/case-conversion-test-client: dependencies: @@ -1787,20 +1787,20 @@ importers: version: link:../../crates/bindings-typescript devDependencies: '@sveltejs/vite-plugin-svelte': - specifier: ^5.1.1 - version: 5.1.1(svelte@5.59.1(@typescript-eslint/types@8.50.0))(vite@6.4.6(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1)) + specifier: ^6.2.4 + version: 6.2.4(svelte@5.59.1(@typescript-eslint/types@8.50.0))(vite@7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1)) svelte: - specifier: ^5.0.0 + specifier: ^5.46.4 version: 5.59.1(@typescript-eslint/types@8.50.0) svelte-check: - specifier: ^4.0.0 + specifier: ^4.7.8 version: 4.7.8(picomatch@4.0.7)(svelte@5.59.1(@typescript-eslint/types@8.50.0))(typescript@5.6.3) typescript: specifier: ~5.6.2 version: 5.6.3 vite: - specifier: ^6.4.6 - version: 6.4.6(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1) + specifier: ^7.3.8 + version: 7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1) templates/tanstack-ts: dependencies: @@ -7112,20 +7112,20 @@ packages: resolution: {integrity: sha512-VT3qmUb8pRV2QrZjd8iAmtg8lf4W0TIjZbvXtz5MKei/q96teWZgGJyyidJzOjzZzvdq616eSRVeMYIQChUTAQ==} engines: {node: '>= 18.0.0'} - '@sveltejs/vite-plugin-svelte-inspector@4.0.1': - resolution: {integrity: sha512-J/Nmb2Q2y7mck2hyCX4ckVHcR5tu2J+MtBEQqpDrrgELZ2uvraQcK/ioCV61AqkdXFgriksOKIceDcQmqnGhVw==} - engines: {node: ^18.0.0 || ^20.0.0 || >=22} + '@sveltejs/vite-plugin-svelte-inspector@5.0.2': + resolution: {integrity: sha512-TZzRTcEtZffICSAoZGkPSl6Etsj2torOVrx6Uw0KpXxrec9Gg6jFWQ60Q3+LmNGfZSxHRCZL7vXVZIWmuV50Ig==} + engines: {node: ^20.19 || ^22.12 || >=24} peerDependencies: - '@sveltejs/vite-plugin-svelte': ^5.0.0 + '@sveltejs/vite-plugin-svelte': ^6.0.0-next.0 svelte: ^5.0.0 - vite: ^6.0.0 + vite: ^6.3.0 || ^7.0.0 - '@sveltejs/vite-plugin-svelte@5.1.1': - resolution: {integrity: sha512-Y1Cs7hhTc+a5E9Va/xwKlAJoariQyHY+5zBgCZg4PFWNYQ1nMN9sjK1zhw1gK69DuqVP++sht/1GZg1aRwmAXQ==} - engines: {node: ^18.0.0 || ^20.0.0 || >=22} + '@sveltejs/vite-plugin-svelte@6.2.4': + resolution: {integrity: sha512-ou/d51QSdTyN26D7h6dSpusAKaZkAiGM55/AKYi+9AGZw7q85hElbjK3kEyzXHhLSnRISHOYzVge6x0jRZ7DXA==} + engines: {node: ^20.19 || ^22.12 || >=24} peerDependencies: svelte: ^5.0.0 - vite: ^6.0.0 + vite: ^6.3.0 || ^7.0.0 '@svgr/babel-plugin-add-jsx-attribute@8.0.0': resolution: {integrity: sha512-b9MIk7yhdS1pMCZM8VeNfUlSKVRhsHZNMl5O9SfaX0l0t5wjdgu4IDzGB8bpnGBBOjGST3rRFVsaaEtI4W6f7g==} @@ -22264,27 +22264,22 @@ snapshots: '@sveltejs/load-config@0.2.3': {} - '@sveltejs/vite-plugin-svelte-inspector@4.0.1(@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.59.1(@typescript-eslint/types@8.50.0))(vite@6.4.6(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1)))(svelte@5.59.1(@typescript-eslint/types@8.50.0))(vite@6.4.6(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1))': + '@sveltejs/vite-plugin-svelte-inspector@5.0.2(@sveltejs/vite-plugin-svelte@6.2.4(svelte@5.59.1(@typescript-eslint/types@8.50.0))(vite@7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1)))(svelte@5.59.1(@typescript-eslint/types@8.50.0))(vite@7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1))': dependencies: - '@sveltejs/vite-plugin-svelte': 5.1.1(svelte@5.59.1(@typescript-eslint/types@8.50.0))(vite@6.4.6(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1)) - debug: 4.4.3 + '@sveltejs/vite-plugin-svelte': 6.2.4(svelte@5.59.1(@typescript-eslint/types@8.50.0))(vite@7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1)) + obug: 2.2.1 svelte: 5.59.1(@typescript-eslint/types@8.50.0) - vite: 6.4.6(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1) - transitivePeerDependencies: - - supports-color + vite: 7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1) - '@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.59.1(@typescript-eslint/types@8.50.0))(vite@6.4.6(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1))': + '@sveltejs/vite-plugin-svelte@6.2.4(svelte@5.59.1(@typescript-eslint/types@8.50.0))(vite@7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1))': dependencies: - '@sveltejs/vite-plugin-svelte-inspector': 4.0.1(@sveltejs/vite-plugin-svelte@5.1.1(svelte@5.59.1(@typescript-eslint/types@8.50.0))(vite@6.4.6(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1)))(svelte@5.59.1(@typescript-eslint/types@8.50.0))(vite@6.4.6(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1)) - debug: 4.4.3 + '@sveltejs/vite-plugin-svelte-inspector': 5.0.2(@sveltejs/vite-plugin-svelte@6.2.4(svelte@5.59.1(@typescript-eslint/types@8.50.0))(vite@7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1)))(svelte@5.59.1(@typescript-eslint/types@8.50.0))(vite@7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1)) deepmerge: 4.3.1 - kleur: 4.1.5 magic-string: 0.30.21 + obug: 2.2.1 svelte: 5.59.1(@typescript-eslint/types@8.50.0) - vite: 6.4.6(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1) - vitefu: 1.1.4(vite@6.4.6(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1)) - transitivePeerDependencies: - - supports-color + vite: 7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1) + vitefu: 1.1.4(vite@7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1)) '@svgr/babel-plugin-add-jsx-attribute@8.0.0(@babel/core@7.29.13)': dependencies: @@ -23010,6 +23005,7 @@ snapshots: '@types/node@24.3.0': dependencies: undici-types: 7.10.0 + optional: true '@types/object-inspect@1.13.0': {} @@ -23429,7 +23425,7 @@ snapshots: vite: 7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1) vue: 3.5.46(typescript@5.6.3) - '@vitest/coverage-v8@3.2.7(vitest@3.2.7(@types/debug@4.1.13)(@types/node@24.3.0)(jiti@2.7.0)(jsdom@26.1.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1))': + '@vitest/coverage-v8@3.2.7(vitest@3.2.7(@types/debug@4.1.13)(@types/node@22.18.0)(jiti@2.7.0)(jsdom@26.1.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1))': dependencies: '@ampproject/remapping': 2.3.0 '@bcoe/v8-coverage': 1.0.2 @@ -23444,7 +23440,7 @@ snapshots: std-env: 3.10.0 test-exclude: 7.0.2 tinyrainbow: 2.0.0 - vitest: 3.2.7(@types/debug@4.1.13)(@types/node@24.3.0)(jiti@2.7.0)(jsdom@26.1.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1) + vitest: 3.2.7(@types/debug@4.1.13)(@types/node@22.18.0)(jiti@2.7.0)(jsdom@26.1.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1) transitivePeerDependencies: - supports-color @@ -23472,21 +23468,21 @@ snapshots: optionalDependencies: vite: 7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1) - '@vitest/mocker@3.2.7(vite@7.3.8(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1))': + '@vitest/mocker@3.2.7(vite@7.3.8(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1))': dependencies: '@vitest/spy': 3.2.7 estree-walker: 3.0.3 magic-string: 0.30.21 optionalDependencies: - vite: 7.3.8(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1) + vite: 7.3.8(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1) - '@vitest/mocker@3.2.7(vite@7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1))': + '@vitest/mocker@3.2.7(vite@7.3.8(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1))': dependencies: '@vitest/spy': 3.2.7 estree-walker: 3.0.3 magic-string: 0.30.21 optionalDependencies: - vite: 7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1) + vite: 7.3.8(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1) '@vitest/mocker@3.2.7(vite@7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1))': dependencies: @@ -31809,26 +31805,25 @@ snapshots: ts-interface-checker@0.1.13: {} - ts-node@10.9.2(@types/node@24.3.0)(typescript@5.6.3): + ts-node@10.9.2(@types/node@22.18.0)(typescript@5.9.3): dependencies: '@cspotcode/source-map-support': 0.8.1 '@tsconfig/node10': 1.0.11 '@tsconfig/node12': 1.0.11 '@tsconfig/node14': 1.0.3 '@tsconfig/node16': 1.0.4 - '@types/node': 24.3.0 + '@types/node': 22.18.0 acorn: 8.19.0 acorn-walk: 8.3.4 arg: 4.1.3 create-require: 1.1.1 diff: 4.0.4 make-error: 1.3.6 - typescript: 5.6.3 + typescript: 5.9.3 v8-compile-cache-lib: 3.0.1 yn: 3.1.1 - optional: true - ts-node@10.9.2(@types/node@24.3.0)(typescript@5.9.3): + ts-node@10.9.2(@types/node@24.3.0)(typescript@5.6.3): dependencies: '@cspotcode/source-map-support': 0.8.1 '@tsconfig/node10': 1.0.11 @@ -31842,9 +31837,10 @@ snapshots: create-require: 1.1.1 diff: 4.0.4 make-error: 1.3.6 - typescript: 5.9.3 + typescript: 5.6.3 v8-compile-cache-lib: 3.0.1 yn: 3.1.1 + optional: true tsconfck@3.1.6(typescript@5.9.3): optionalDependencies: @@ -32503,13 +32499,13 @@ snapshots: - tsx - yaml - vite-node@3.2.4(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1): + vite-node@3.2.4(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1): dependencies: cac: 6.7.14 debug: 4.4.3 es-module-lexer: 1.7.0 pathe: 2.0.3 - vite: 7.3.8(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1) + vite: 7.3.8(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1) transitivePeerDependencies: - '@types/node' - jiti @@ -32524,13 +32520,13 @@ snapshots: - tsx - yaml - vite-node@3.2.4(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1): + vite-node@3.2.4(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1): dependencies: cac: 6.7.14 debug: 4.4.3 es-module-lexer: 1.7.0 pathe: 2.0.3 - vite: 7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1) + vite: 7.3.8(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1) transitivePeerDependencies: - '@types/node' - jiti @@ -32686,7 +32682,7 @@ snapshots: tsx: 4.23.15 yaml: 2.9.1 - vite@7.3.8(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1): + vite@7.3.8(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1): dependencies: esbuild: 0.28.2 fdir: 6.5.0(picomatch@4.0.7) @@ -32700,11 +32696,11 @@ snapshots: jiti: 2.7.0 lightningcss: 1.33.0 sass: 1.97.3 - terser: 5.51.4 + terser: 5.43.1 tsx: 4.23.15 yaml: 2.9.1 - vite@7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1): + vite@7.3.8(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1): dependencies: esbuild: 0.28.2 fdir: 6.5.0(picomatch@4.0.7) @@ -32713,12 +32709,12 @@ snapshots: rollup: 4.68.8 tinyglobby: 0.2.17 optionalDependencies: - '@types/node': 24.3.0 + '@types/node': 22.18.0 fsevents: 2.3.3 jiti: 2.7.0 lightningcss: 1.33.0 sass: 1.97.3 - terser: 5.43.1 + terser: 5.51.4 tsx: 4.23.15 yaml: 2.9.1 @@ -32774,10 +32770,6 @@ snapshots: tsx: 4.23.15 yaml: 2.9.1 - vitefu@1.1.4(vite@6.4.6(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1)): - optionalDependencies: - vite: 6.4.6(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1) - vitefu@1.1.4(vite@7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1)): optionalDependencies: vite: 7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1) @@ -32829,11 +32821,11 @@ snapshots: - tsx - yaml - vitest@3.2.7(@types/debug@4.1.13)(@types/node@22.18.0)(jiti@2.7.0)(jsdom@26.1.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1): + vitest@3.2.7(@types/debug@4.1.13)(@types/node@22.18.0)(jiti@2.7.0)(jsdom@26.1.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1): dependencies: '@types/chai': 5.2.3 '@vitest/expect': 3.2.7 - '@vitest/mocker': 3.2.7(vite@7.3.8(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1)) + '@vitest/mocker': 3.2.7(vite@7.3.8(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1)) '@vitest/pretty-format': 3.2.7 '@vitest/runner': 3.2.7 '@vitest/snapshot': 3.2.7 @@ -32851,8 +32843,8 @@ snapshots: tinyglobby: 0.2.17 tinypool: 2.2.0 tinyrainbow: 2.0.0 - vite: 7.3.8(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1) - vite-node: 3.2.4(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1) + vite: 7.3.8(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1) + vite-node: 3.2.4(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1) why-is-node-running: 2.3.0 optionalDependencies: '@types/debug': 4.1.13 @@ -32872,11 +32864,11 @@ snapshots: - tsx - yaml - vitest@3.2.7(@types/debug@4.1.13)(@types/node@24.3.0)(jiti@2.7.0)(jsdom@26.1.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1): + vitest@3.2.7(@types/debug@4.1.13)(@types/node@22.18.0)(jiti@2.7.0)(jsdom@26.1.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1): dependencies: '@types/chai': 5.2.3 '@vitest/expect': 3.2.7 - '@vitest/mocker': 3.2.7(vite@7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1)) + '@vitest/mocker': 3.2.7(vite@7.3.8(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1)) '@vitest/pretty-format': 3.2.7 '@vitest/runner': 3.2.7 '@vitest/snapshot': 3.2.7 @@ -32894,12 +32886,12 @@ snapshots: tinyglobby: 0.2.17 tinypool: 2.2.0 tinyrainbow: 2.0.0 - vite: 7.3.8(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1) - vite-node: 3.2.4(@types/node@24.3.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.43.1)(tsx@4.23.15)(yaml@2.9.1) + vite: 7.3.8(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1) + vite-node: 3.2.4(@types/node@22.18.0)(jiti@2.7.0)(lightningcss@1.33.0)(sass@1.97.3)(terser@5.51.4)(tsx@4.23.15)(yaml@2.9.1) why-is-node-running: 2.3.0 optionalDependencies: '@types/debug': 4.1.13 - '@types/node': 24.3.0 + '@types/node': 22.18.0 jsdom: 26.1.0 transitivePeerDependencies: - jiti diff --git a/templates/svelte-ts/.gitignore b/templates/svelte-ts/.gitignore index ab8ad35a188..63a103aa772 100644 --- a/templates/svelte-ts/.gitignore +++ b/templates/svelte-ts/.gitignore @@ -1,6 +1,5 @@ node_modules dist -.svelte-kit *.log .DS_Store diff --git a/templates/svelte-ts/package.json b/templates/svelte-ts/package.json index dff1b7bc8ef..ef1229ae685 100644 --- a/templates/svelte-ts/package.json +++ b/templates/svelte-ts/package.json @@ -5,7 +5,8 @@ "type": "module", "scripts": { "dev": "vite", - "build": "vite build", + "build": "svelte-check --tsconfig ./tsconfig.json && vite build", + "check": "svelte-check --tsconfig ./tsconfig.json", "preview": "vite preview", "generate": "pnpm --dir spacetimedb install && cargo run -p gen-bindings -- --out-dir src/module_bindings --module-path spacetimedb && prettier --write src/module_bindings", "spacetime:generate": "spacetime generate --lang typescript --out-dir src/module_bindings --module-path spacetimedb", @@ -16,11 +17,11 @@ "spacetimedb": "workspace:*" }, "devDependencies": { - "@sveltejs/vite-plugin-svelte": "^5.1.1", - "svelte": "^5.0.0", - "svelte-check": "^4.0.0", + "@sveltejs/vite-plugin-svelte": "^6.2.4", + "svelte": "^5.46.4", + "svelte-check": "^4.7.8", "typescript": "~5.6.2", - "vite": "^6.4.6" + "vite": "^7.3.8" }, "engines": { "node": "^22.23.4 || ^24.22.1 || >=26.12.1" diff --git a/templates/svelte-ts/svelte.config.js b/templates/svelte-ts/svelte.config.js index 4c6b24b1073..ed459535cc1 100644 --- a/templates/svelte-ts/svelte.config.js +++ b/templates/svelte-ts/svelte.config.js @@ -1,5 +1,2 @@ -import { vitePreprocess } from '@sveltejs/vite-plugin-svelte'; - -export default { - preprocess: vitePreprocess(), -}; +/** @type {import("@sveltejs/vite-plugin-svelte").SvelteConfig} */ +export default {}; diff --git a/templates/svelte-ts/tsconfig.json b/templates/svelte-ts/tsconfig.json index 6406a7d1573..859fbbd2730 100644 --- a/templates/svelte-ts/tsconfig.json +++ b/templates/svelte-ts/tsconfig.json @@ -3,13 +3,14 @@ "target": "ES2020", "useDefineForClassFields": true, "lib": ["ES2020", "DOM", "DOM.Iterable"], - "types": ["vite/client"], + "types": ["svelte", "vite/client"], "module": "ESNext", "skipLibCheck": true, "moduleResolution": "bundler", "allowImportingTsExtensions": true, "isolatedModules": true, + "verbatimModuleSyntax": true, "moduleDetection": "force", "noEmit": true, From 83a393fc2ab6131252554b7a59c2808480fac413 Mon Sep 17 00:00:00 2001 From: Kris Jenkins Date: Wed, 18 Nov 2026 10:36:39 +0000 Subject: [PATCH 09/15] Explain the Svelte template's connection setup and stores in its README. Someone who has just scaffolded the Svelte template opens the README to find their way around. The project tree shows src/App.svelte and module_bindings, and nothing else. But the first thing they'll want to change is which database they connect to, and that lives in src/Root.svelte, a file the README never mentions. They'll find it eventually. They'll then wonder why it exists at all, since every other framework template sets up its connection in main.ts, and may try to move it there. That fails at runtime, because createSpacetimeDBProvider uses Svelte context and only works while a component is being created. The README also never says that the hooks return Svelte stores. A Svelte 5 developer expects runes, so seeing $people and $conn in App.svelte looks like legacy syntax rather than the intended API. And 'Next steps' pointed at the top of a long TypeScript reference rather than its Svelte section, and left out the chat tutorial that the React README links to. The README is generated from the Svelte quickstart page by tools/templates/generate-template-readmes.ts, so the changes are made in docs/docs/00100-intro/00200-quickstarts/00160-svelte.md and the README is regenerated from it: - The project tree lists main.ts, Root.svelte and App.svelte, each with its role, and the text says where the connection is configured. - A new 'Use your data in Svelte' step explains why Root.svelte exists, says the hooks return stores read with $, and shows a short type-checked example using the template's own person table and add reducer. - 'Next steps' links to the Svelte section of the TypeScript reference, and to the chat tutorial, noting that its client is React but its module and SDK calls carry over. The example was checked with svelte-check inside the template. Running the generator also rewrites nine other templates' READMEs that have drifted from their quickstarts; those changes are not part of this commit. --- .../00200-quickstarts/00160-svelte.md | 41 +++++++++++++++---- templates/svelte-ts/README.md | 40 ++++++++++++++---- 2 files changed, 67 insertions(+), 14 deletions(-) diff --git a/docs/docs/00100-intro/00200-quickstarts/00160-svelte.md b/docs/docs/00100-intro/00200-quickstarts/00160-svelte.md index 80f19aebb26..b3e179082ae 100644 --- a/docs/docs/00100-intro/00200-quickstarts/00160-svelte.md +++ b/docs/docs/00100-intro/00200-quickstarts/00160-svelte.md @@ -46,17 +46,19 @@ spacetime dev --template svelte-ts Your project contains both server and client code. - Edit `spacetimedb/src/index.ts` to add tables and reducers. Edit `src/App.svelte` to build your UI. + Edit `spacetimedb/src/index.ts` to add tables and reducers. Edit `src/App.svelte` to build your UI. The connection to SpacetimeDB is configured in `src/Root.svelte`. ``` my-spacetime-app/ -├── spacetimedb/ # Your SpacetimeDB module +├── spacetimedb/ # Your SpacetimeDB module │ └── src/ -│ └── index.ts # Server-side logic -├── src/ # Svelte frontend -│ ├── App.svelte -│ └── module_bindings/ # Auto-generated types +│ └── index.ts # Server-side logic +├── src/ # Svelte frontend +│ ├── main.ts # Mounts Root.svelte +│ ├── Root.svelte # Connects to SpacetimeDB +│ ├── App.svelte # Your UI +│ └── module_bindings/ # Auto-generated types └── package.json ``` @@ -99,6 +101,30 @@ export const sayHello = spacetimedb.reducer(ctx => { + + + `src/Root.svelte` calls `createSpacetimeDBProvider`, which shares the connection with every component below it. It has to run inside a component, because it uses Svelte context, so it can't move to `main.ts`. + + `src/App.svelte` then reads that connection with the hooks from `spacetimedb/svelte`. `useSpacetimeDB` and `useTable` return Svelte stores, so read them with a `$` prefix. `useTable` subscribes to the table and keeps its rows up to date. `useReducer` returns a function that calls the reducer. + + +```svelte + + +

{$conn.isActive ? 'Connected' : 'Disconnected'}

+

{$people.length} people

+ +``` +
+
+ Open a new terminal and navigate to your project directory. Then use the SpacetimeDB CLI to call reducers and query your data directly. @@ -130,4 +156,5 @@ spacetime logs ## Next steps -- Read the [TypeScript SDK Reference](../../00200-core-concepts/00600-clients/00700-typescript-reference.md) for detailed API docs +- Read the [Svelte section of the TypeScript SDK Reference](../../00200-core-concepts/00600-clients/00700-typescript-reference.md#svelte) for the full Svelte API +- Work through the [Chat App Tutorial](../00300-tutorials/00100-chat-app.md) to build a bigger module. Its client is written in React, but the module and the SDK calls carry over to Svelte. diff --git a/templates/svelte-ts/README.md b/templates/svelte-ts/README.md index 2833e9dd72a..c6770436591 100644 --- a/templates/svelte-ts/README.md +++ b/templates/svelte-ts/README.md @@ -33,16 +33,18 @@ The template includes a basic Svelte app connected to SpacetimeDB. Your project contains both server and client code. -Edit `spacetimedb/src/index.ts` to add tables and reducers. Edit `src/App.svelte` to build your UI. +Edit `spacetimedb/src/index.ts` to add tables and reducers. Edit `src/App.svelte` to build your UI. The connection to SpacetimeDB is configured in `src/Root.svelte`. ``` my-spacetime-app/ -├── spacetimedb/ # Your SpacetimeDB module +├── spacetimedb/ # Your SpacetimeDB module │ └── src/ -│ └── index.ts # Server-side logic -├── src/ # Svelte frontend -│ ├── App.svelte -│ └── module_bindings/ # Auto-generated types +│ └── index.ts # Server-side logic +├── src/ # Svelte frontend +│ ├── main.ts # Mounts Root.svelte +│ ├── Root.svelte # Connects to SpacetimeDB +│ ├── App.svelte # Your UI +│ └── module_bindings/ # Auto-generated types └── package.json ``` @@ -84,6 +86,29 @@ export const sayHello = spacetimedb.reducer(ctx => { +## Use your data in Svelte + +`src/Root.svelte` calls `createSpacetimeDBProvider`, which shares the connection with every component below it. It has to run inside a component, because it uses Svelte context, so it can't move to `main.ts`. + +`src/App.svelte` then reads that connection with the hooks from `spacetimedb/svelte`. `useSpacetimeDB` and `useTable` return Svelte stores, so read them with a `$` prefix. `useTable` subscribes to the table and keeps its rows up to date. `useReducer` returns a function that calls the reducer. + +```svelte + + +

{$conn.isActive ? 'Connected' : 'Disconnected'}

+

{$people.length} people

+ +``` + + + ## Test with the CLI Open a new terminal and navigate to your project directory. Then use the SpacetimeDB CLI to call reducers and query your data directly. @@ -111,4 +136,5 @@ spacetime logs ## Next steps -- Read the [TypeScript SDK Reference](https://spacetimedb.com/docs/clients/typescript) for detailed API docs +- Read the [Svelte section of the TypeScript SDK Reference](https://spacetimedb.com/docs/clients/typescript#svelte) for the full Svelte API +- Work through the [Chat App Tutorial](https://spacetimedb.com/docs/tutorials/chat-app) to build a bigger module. Its client is written in React, but the module and the SDK calls carry over to Svelte. From 465f60d818c268cb70239825ec398e07d61aff99 Mon Sep 17 00:00:00 2001 From: Kris Jenkins Date: Wed, 18 Nov 2026 10:40:05 +0000 Subject: [PATCH 10/15] Test the Svelte bindings beyond table reconnects. The Svelte bindings have one test file, framework_table_reconnect.test.ts, and it only asks one question of every framework: does useTable keep its subscription and rows across a reconnect? Everything else in spacetimedb/svelte had no tests: createSpacetimeDBProvider, useSpacetimeDB, useReducer, the new useProcedure, and the parts of useTable that aren't about reconnecting (where-clause filtering, the insert/delete/update callbacks, and updating the rows store once per transaction rather than once per row). The last few commits changed several of those, and they could only be checked with a throwaway harness outside the repo. The next person to touch them won't have that harness. The new tests/svelte_bindings.test.ts follows the existing file's approach: svelte is mocked with a minimal component lifecycle (one shared context map per test, and onDestroy callbacks collected per component), and the provider and useTable run against a real DbConnection over the websocket test adapter. The test app has no procedures, and useReducer and useProcedure only depend on getConnection() and the accessor map, so those two run against a hand-driven connection store. The tests cover: - useSpacetimeDB and useTable throwing helpful errors outside a provider. - The provider sharing one read-only store with its children, reporting the identity and token once connected, replacing the connection on reconnect(builder), and releasing it, deferred, when destroyed. - useReducer and useProcedure queueing calls made before connecting, passing return values and errors through, calling straight through when connected, and dropping the queue once destroyed. - useTable becoming ready with the subscribed rows, emitting once per transaction while firing callbacks per row, mapping updates across the where clause to onInsert/onDelete/onUpdate, and unsubscribing and going quiet when destroyed. Each test was checked by breaking the behaviour it covers: making the store writable, dropping the onDestroy unsubscribe in useReducer or useProcedure, recomputing rows per row, skipping membership classification, keeping table listeners after destroy, and never releasing the connection. Each break fails exactly the test aimed at it. The full unit suite passes (502 tests) apart from the two wasm test files, which need a locally built artefact. --- .../tests/svelte_bindings.test.ts | 477 ++++++++++++++++++ 1 file changed, 477 insertions(+) create mode 100644 crates/bindings-typescript/tests/svelte_bindings.test.ts diff --git a/crates/bindings-typescript/tests/svelte_bindings.test.ts b/crates/bindings-typescript/tests/svelte_bindings.test.ts new file mode 100644 index 00000000000..13a4d70c28f --- /dev/null +++ b/crates/bindings-typescript/tests/svelte_bindings.test.ts @@ -0,0 +1,477 @@ +// Tests for the Svelte bindings (`spacetimedb/svelte`). Reconnect behaviour of +// `useTable` is covered for every framework in framework_table_reconnect.test.ts; +// this file covers the rest of the Svelte surface. +// +// `svelte` is mocked with a minimal component lifecycle: `setContext` and +// `getContext` share one map per test (one provider and its children), and +// `onDestroy` callbacks registered while `component()` runs its body are +// returned as that component's `destroy`. +import { afterEach, beforeEach, describe, expect, test, vi } from 'vitest'; +import { get, writable, type Readable } from 'svelte/store'; +import { + createSpacetimeDBProvider, + useProcedure, + useReducer, + useSpacetimeDB, + useTable, +} from '../src/svelte'; +import { + SPACETIMEDB_CONTEXT_KEY, + type ConnectionState, +} from '../src/svelte/connection_state'; +import { ConnectionManager } from '../src/sdk/connection_manager'; +import { ConnectionId } from '../src'; +import { ServerMessage } from '../src/sdk/client_api/types'; +import { WebsocketTestAdapterFactory } from '../src/sdk/websocket_test_adapter'; +import { DbConnection, tables } from '../test-app/src/module_bindings'; +import type { UntypedProcedureDef } from '../src/sdk/procedures'; +import type { UntypedReducerDef } from '../src/sdk/reducers'; +import { + anIdentity, + bobIdentity, + encodeUser, + makeQueryRows, + makeQuerySetUpdate, + sallyIdentity, +} from './utils'; + +const lifecycle = vi.hoisted(() => ({ + contexts: new Map(), + destroyers: [] as (() => void)[], +})); +vi.mock('svelte', () => ({ + setContext: (key: unknown, value: unknown) => { + lifecycle.contexts.set(key, value); + return value; + }, + getContext: (key: unknown) => lifecycle.contexts.get(key), + onDestroy: (fn: () => void) => { + lifecycle.destroyers.push(fn); + }, +})); + +/** Run `body` as a component's initialisation; returns its result and a destroy function. */ +function component(body: () => T): { value: T; destroy: () => void } { + lifecycle.destroyers = []; + const value = body(); + const destroyers = lifecycle.destroyers; + lifecycle.destroyers = []; + return { value, destroy: () => destroyers.forEach(fn => fn()) }; +} + +/** Let queued promise callbacks run. */ +async function settle() { + for (let i = 0; i < 5; i++) await Promise.resolve(); +} + +let factory: WebsocketTestAdapterFactory; +let databaseCounter = 0; + +function builder() { + return DbConnection.builder() + .withUri('ws://localhost:1234') + .withDatabaseName(`svelte-bindings-${databaseCounter}`) + .withWSFn(factory.openWebSocket); +} + +/** Complete the handshake for the connection currently opening. */ +async function establish(connection: DbConnection) { + await connection['wsPromise']; + factory.current.acceptConnection(); + factory.current.sendToClient( + ServerMessage.InitialConnection({ + identity: anIdentity, + connectionId: ConnectionId.random(), + token: 'token', + }) + ); + await settle(); +} + +beforeEach(() => { + vi.useFakeTimers(); + lifecycle.contexts.clear(); + lifecycle.destroyers = []; + factory = new WebsocketTestAdapterFactory(); + databaseCounter += 1; +}); +afterEach(() => { + vi.useRealTimers(); +}); + +describe('useSpacetimeDB', () => { + test('throws a helpful error outside a provider', () => { + expect(() => useSpacetimeDB()).toThrow(/createSpacetimeDBProvider/); + }); + + test('useTable also explains a missing provider', () => { + expect(() => useTable(tables.user)).toThrow( + /Did you forget to call `createSpacetimeDBProvider`/ + ); + }); +}); + +describe('createSpacetimeDBProvider', () => { + test('shares a read-only connection store with its children', () => { + const provider = component(() => createSpacetimeDBProvider(builder())); + try { + const store = provider.value; + expect(useSpacetimeDB()).toBe(store); + expect('set' in store).toBe(false); + expect('update' in store).toBe(false); + expect(get(store).isActive).toBe(false); + } finally { + provider.destroy(); + } + }); + + test('reflects the connection becoming active', async () => { + const provider = component(() => createSpacetimeDBProvider(builder())); + try { + const store = provider.value; + const connection = get(store).getConnection() as DbConnection; + expect(connection).toBeInstanceOf(DbConnection); + + await establish(connection); + + const state = get(store); + expect(state.isActive).toBe(true); + expect(state.identity?.isEqual(anIdentity)).toBe(true); + expect(state.token).toBe('token'); + } finally { + provider.destroy(); + } + }); + + test('reconnect(builder) replaces the connection', async () => { + const provider = component(() => createSpacetimeDBProvider(builder())); + try { + const store = provider.value; + const first = get(store).getConnection() as DbConnection; + await establish(first); + + get(store).reconnect(builder().withToken('new-token')); + + const second = get(store).getConnection() as DbConnection; + expect(second).toBeInstanceOf(DbConnection); + expect(second).not.toBe(first); + expect(first.isActive).toBe(false); + } finally { + provider.destroy(); + } + }); + + test('releases the connection when destroyed', async () => { + const b = builder(); + const key = ConnectionManager.getKey(b.getUri(), b.getModuleName()); + const provider = component(() => createSpacetimeDBProvider(b)); + const connection = get(provider.value).getConnection() as DbConnection; + await establish(connection); + + provider.destroy(); + // Release is deferred so a quick remount (HMR, {#key}) can reuse it. + expect(ConnectionManager.getConnection(key)).toBe(connection); + await vi.runOnlyPendingTimersAsync(); + + expect(ConnectionManager.getConnection(key)).toBeNull(); + expect(connection.isActive).toBe(false); + }); +}); + +/** A connection store driven by hand, for testing the call hooks in isolation. */ +function fakeConnectionStore() { + const calls: [string, unknown][] = []; + const connection = { + reducers: { + createPlayer: (args: unknown) => { + calls.push(['createPlayer', args]); + return Promise.resolve(); + }, + failingReducer: () => Promise.reject(new Error('reducer failed')), + }, + procedures: { + getScore: (args: { name: string }) => { + calls.push(['getScore', args]); + return Promise.resolve(`score for ${args.name}`); + }, + failingProcedure: () => Promise.reject(new Error('procedure failed')), + }, + }; + const state = (live: boolean): ConnectionState => ({ + isActive: live, + identity: undefined, + token: undefined, + connectionId: ConnectionId.random(), + connectionError: undefined, + getConnection: () => (live ? (connection as never) : null), + reconnect: () => {}, + }); + const store = writable(state(false)); + lifecycle.contexts.set( + SPACETIMEDB_CONTEXT_KEY, + store satisfies Readable + ); + return { + calls, + connect: () => store.set(state(true)), + disconnect: () => store.set(state(false)), + }; +} + +const createPlayer = { accessorName: 'createPlayer' } as UntypedReducerDef; +const failingReducer = { accessorName: 'failingReducer' } as UntypedReducerDef; +const getScore = { accessorName: 'getScore' } as UntypedProcedureDef; +const failingProcedure = { + accessorName: 'failingProcedure', +} as UntypedProcedureDef; + +describe('useReducer', () => { + test('queues calls made before connecting and sends them once connected', async () => { + const conn = fakeConnectionStore(); + const hook = component(() => useReducer(createPlayer)); + const call = hook.value as (args: unknown) => Promise; + + const pending = call({ name: 'Alice' }); + await settle(); + expect(conn.calls).toEqual([]); + + conn.connect(); + await expect(pending).resolves.toBeUndefined(); + expect(conn.calls).toEqual([['createPlayer', { name: 'Alice' }]]); + hook.destroy(); + }); + + test('calls straight through when connected', async () => { + const conn = fakeConnectionStore(); + conn.connect(); + const hook = component(() => useReducer(createPlayer)); + const call = hook.value as (args: unknown) => Promise; + + await call({ name: 'Bob' }); + expect(conn.calls).toEqual([['createPlayer', { name: 'Bob' }]]); + hook.destroy(); + }); + + test('rejects a queued call when the reducer fails', async () => { + const conn = fakeConnectionStore(); + const hook = component(() => useReducer(failingReducer)); + const pending = (hook.value as () => Promise)(); + conn.connect(); + await expect(pending).rejects.toThrow('reducer failed'); + hook.destroy(); + }); + + test('stops sending queued calls once destroyed', async () => { + const conn = fakeConnectionStore(); + const hook = component(() => useReducer(createPlayer)); + void (hook.value as (args: unknown) => Promise)({ name: 'Ghost' }); + + hook.destroy(); + conn.connect(); + await settle(); + expect(conn.calls).toEqual([]); + }); +}); + +describe('useProcedure', () => { + test('queues calls made before connecting and resolves with the return value', async () => { + const conn = fakeConnectionStore(); + const hook = component(() => useProcedure(getScore)); + const call = hook.value as (args: { name: string }) => Promise; + + const pending = call({ name: 'Alice' }); + await settle(); + expect(conn.calls).toEqual([]); + + conn.connect(); + await expect(pending).resolves.toBe('score for Alice'); + hook.destroy(); + }); + + test('calls straight through when connected', async () => { + const conn = fakeConnectionStore(); + conn.connect(); + const hook = component(() => useProcedure(getScore)); + const call = hook.value as (args: { name: string }) => Promise; + + await expect(call({ name: 'Bob' })).resolves.toBe('score for Bob'); + hook.destroy(); + }); + + test('rejects a queued call when the procedure fails', async () => { + const conn = fakeConnectionStore(); + const hook = component(() => useProcedure(failingProcedure)); + const pending = (hook.value as () => Promise)(); + conn.connect(); + await expect(pending).rejects.toThrow('procedure failed'); + hook.destroy(); + }); + + test('stops sending queued calls once destroyed', async () => { + const conn = fakeConnectionStore(); + const hook = component(() => useProcedure(getScore)); + void (hook.value as (args: { name: string }) => Promise)({ + name: 'Ghost', + }); + + hook.destroy(); + conn.connect(); + await settle(); + expect(conn.calls).toEqual([]); + }); +}); + +describe('useTable', () => { + const alice = { identity: anIdentity, username: 'Alice' }; + const bob = { identity: bobIdentity, username: 'Bob' }; + const sally = { identity: sallyIdentity, username: 'Sally' }; + + /** Mount a provider with a live connection, then a component calling useTable. */ + async function mountTable( + query: Parameters[0], + initialRows: (typeof alice)[] + ) { + const events: string[] = []; + const provider = component(() => createSpacetimeDBProvider(builder())); + const connection = get(provider.value).getConnection() as DbConnection; + await establish(connection); + + const hook = component(() => + useTable(query, { + onInsert: row => events.push(`insert ${row.username}`), + onDelete: row => events.push(`delete ${row.username}`), + onUpdate: (oldRow, newRow) => + events.push(`update ${oldRow.username} -> ${newRow.username}`), + }) + ); + const [rows, ready] = hook.value; + await settle(); + + const subscribe = factory.current.outgoingMessages.at(-1); + if (subscribe?.tag !== 'Subscribe') { + throw new Error('Expected useTable to subscribe'); + } + const querySetId = subscribe.value.querySetId.id; + factory.current.sendToClient( + ServerMessage.SubscribeApplied({ + requestId: subscribe.value.requestId, + querySetId: subscribe.value.querySetId, + rows: makeQueryRows('user', initialRows.map(encodeUser)), + }) + ); + await settle(); + + const emissions: string[][] = []; + const stopWatching = rows.subscribe(value => + emissions.push(value.map(row => row.username as string)) + ); + emissions.length = 0; // drop the immediate emission from subscribing + + const transaction = async ( + inserts: (typeof alice)[], + deletes: (typeof alice)[] = [] + ) => { + factory.current.sendToClient( + ServerMessage.TransactionUpdate({ + querySets: [ + makeQuerySetUpdate( + querySetId, + 'user', + inserts.map(encodeUser), + deletes.map(encodeUser) + ), + ], + }) + ); + await settle(); + }; + const names = () => get(rows).map(row => row.username); + const destroy = () => { + stopWatching(); + hook.destroy(); + provider.destroy(); + }; + return { rows, ready, names, events, emissions, transaction, destroy }; + } + + test('becomes ready with the subscribed rows', async () => { + const t = await mountTable(tables.user, [alice, bob]); + try { + expect(get(t.ready)).toBe(true); + expect(t.names()).toEqual(['Alice', 'Bob']); + } finally { + t.destroy(); + } + }); + + test('updates rows once per transaction, firing callbacks per row', async () => { + const t = await mountTable(tables.user, [alice]); + try { + t.events.length = 0; + await t.transaction([bob, sally]); + + expect(t.names()).toEqual(['Alice', 'Bob', 'Sally']); + expect(t.events).toEqual(['insert Bob', 'insert Sally']); + expect(t.emissions).toEqual([['Alice', 'Bob', 'Sally']]); + } finally { + t.destroy(); + } + }); + + test('filters rows and callbacks by the where clause', async () => { + const t = await mountTable( + tables.user.where(row => row.username.eq('Alice')), + [alice, bob] + ); + try { + expect(t.names()).toEqual(['Alice']); + t.events.length = 0; + + // Bob is renamed to Alice: he enters the filtered set, so onInsert. + await t.transaction([{ ...bob, username: 'Alice' }], [bob]); + expect(t.events).toEqual(['insert Alice']); + expect(t.names()).toEqual(['Alice', 'Alice']); + + // Alice is renamed: she leaves the filtered set, so onDelete. + t.events.length = 0; + await t.transaction([{ ...alice, username: 'Alicia' }], [alice]); + expect(t.events).toEqual(['delete Alice']); + expect(t.names()).toEqual(['Alice']); + + // A change entirely outside the filter fires nothing. + t.events.length = 0; + t.emissions.length = 0; + await t.transaction([sally]); + expect(t.events).toEqual([]); + expect(t.emissions).toEqual([]); + } finally { + t.destroy(); + } + }); + + test('reports an in-filter change as an update', async () => { + const t = await mountTable(tables.user, [alice]); + try { + t.events.length = 0; + await t.transaction([{ ...alice, username: 'Alicia' }], [alice]); + expect(t.events).toEqual(['update Alice -> Alicia']); + expect(t.names()).toEqual(['Alicia']); + } finally { + t.destroy(); + } + }); + + test('unsubscribes and stops listening when destroyed', async () => { + const t = await mountTable(tables.user, [alice]); + t.destroy(); + await settle(); + expect(factory.current.outgoingMessages.at(-1)?.tag).toBe('Unsubscribe'); + + // Later transactions no longer reach the destroyed hook. + t.events.length = 0; + t.emissions.length = 0; + await t.transaction([bob]); + expect(t.events).toEqual([]); + expect(t.emissions).toEqual([]); + }); +}); From 337e3f4a554fd81fcd47757baf0265ee2e12e5e6 Mon Sep 17 00:00:00 2001 From: Kris Jenkins Date: Wed, 18 Nov 2026 13:42:07 +0000 Subject: [PATCH 11/15] Key the svelte-ts template's people list by row. The template's list of people is an unkeyed {#each}: {#each $people as person}
  • {person.name}
  • {/each} Without a key, Svelte matches list items to rows by position. When someone is inserted or deleted anywhere but the end, every item after that point is handed a different person and patched to match, instead of one item being added or removed. On this two-field list that's invisible, but the template is what people copy, and as soon as an item holds state of its own (an input, a transition, a focused button) it ends up attached to the wrong person. The Svelte docs recommend keying lists for exactly this reason. The reason it wasn't keyed is that the person table has no primary key, and adding one would change the module shared by every TypeScript template and the quickstart docs. That turns out not to be necessary. The SDK's client cache keeps one object per row until the row changes: rows without a primary key are stored under their encoded bytes, and a repeated insert from an overlapping subscription bumps a refcount and keeps the existing object. So the row object itself is a stable, unique key, and for a table with no primary key it is exactly the right identity: such a row is never updated, only deleted and re-inserted. The list is now keyed by the row object, with a comment saying why that works. --- templates/svelte-ts/src/App.svelte | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/templates/svelte-ts/src/App.svelte b/templates/svelte-ts/src/App.svelte index 9e3f0d37e2c..96fb1c77cb9 100644 --- a/templates/svelte-ts/src/App.svelte +++ b/templates/svelte-ts/src/App.svelte @@ -54,7 +54,9 @@ function addPerson(e: SubmitEvent) {

    No people yet. Add someone above!

    {:else}
      - {#each $people as person} + + {#each $people as person (person)}
    • {person.name}
    • {/each}
    From 7943b3d88f124b47578d9d5b40de62817c933c21 Mon Sep 17 00:00:00 2001 From: Kris Jenkins Date: Wed, 18 Nov 2026 14:20:06 +0000 Subject: [PATCH 12/15] Show reducer failures in the svelte-ts template. Suppose you start from this template and give the add reducer some validation, which is the first thing most people do: if (name === '') throw new SenderError('name is required'); Then you submit a name the reducer rejects. The input clears as if it worked, no one is added to the list, and nothing on the page says why. The template called the reducer like this: addReducer({ name: name }); name = ''; addReducer returns a promise, which rejects with the server's error (or with a DisconnectedError if the connection drops), and the template threw it away. The only trace is an unhandled-rejection line in the browser console. It wasn't noticed because the template's own reducer can't fail, so the path was never exercised. addPerson now awaits the call and shows the error under the form, naming the person it couldn't add, since the input has already been cleared for the next entry. The next submit clears the message. Checked against a local server with a copy of the module whose add reducer throws SenderError for one name: the page shows "Couldn't add boom: names cannot be boom", the list is unchanged, and the next successful add clears the message. --- templates/svelte-ts/src/App.svelte | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/templates/svelte-ts/src/App.svelte b/templates/svelte-ts/src/App.svelte index 96fb1c77cb9..7ae6c860a5d 100644 --- a/templates/svelte-ts/src/App.svelte +++ b/templates/svelte-ts/src/App.svelte @@ -10,14 +10,21 @@ const [people] = useTable(tables.person); const addReducer = useReducer(reducers.add); let name = $state(''); +let error = $state(null); -function addPerson(e: SubmitEvent) { +async function addPerson(e: SubmitEvent) { e.preventDefault(); if (!name.trim() || !$conn.isActive) return; - // Call the add reducer - addReducer({ name: name }); + const newName = name; name = ''; + error = null; + try { + // Call the add reducer. It rejects if the reducer fails on the server. + await addReducer({ name: newName }); + } catch (err) { + error = `Couldn't add ${newName}: ${err instanceof Error ? err.message : err}`; + } } @@ -48,6 +55,10 @@ function addPerson(e: SubmitEvent) { + {#if error} +

    {error}

    + {/if} +

    People ({$people.length})

    {#if $people.length === 0} From 547361eec9cd7beeb6873e912304875985804228 Mon Sep 17 00:00:00 2001 From: Kris Jenkins Date: Wed, 18 Nov 2026 14:21:14 +0000 Subject: [PATCH 13/15] Show a loading state in the svelte-ts template until people arrive. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Open the template app against a database that already has people in it. Before the list appears, the page says "People (0)" and "No people yet. Add someone above!", and then a moment later the people pop in. Recording the page text on a reload with two rows in the table shows it: Status: Disconnected People (0) No people yet. Add someone above! Status: Connected People (0) No people yet. Add someone above! Status: Connected People (2) Alice, Bob The app tells the user, wrongly, that the table is empty, for as long as connecting and subscribing take. On localhost that's a flicker; over a real network it's long enough to read. The template only looked at the rows, and an empty array means both "nothing loaded yet" and "loaded, and empty". useTable already returns a second store, isReady, which is true once the subscription's first results have been applied. The template now uses it: while the list is empty and not ready, it shows "Loading…" and leaves the count off the heading. Rows that are already loaded stay on screen if isReady drops, for example during a reconnect, because the check only applies to an empty list. Checked in headless Chrome against a local server, recording every state of the page: an empty table goes Loading… to "No people yet", a table with two rows goes Loading… to the two names, and "No people yet" never shows in between. --- templates/svelte-ts/src/App.svelte | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/templates/svelte-ts/src/App.svelte b/templates/svelte-ts/src/App.svelte index 7ae6c860a5d..4dc80191f2c 100644 --- a/templates/svelte-ts/src/App.svelte +++ b/templates/svelte-ts/src/App.svelte @@ -5,7 +5,11 @@ import { tables, reducers } from './module_bindings'; const conn = useSpacetimeDB(); // Subscribe to all people in the database -const [people] = useTable(tables.person); +const [people, peopleReady] = useTable(tables.person); + +// Until the subscription's first results arrive, an empty list means +// "not loaded yet", not "no people". +const loading = $derived(!$peopleReady && $people.length === 0); const addReducer = useReducer(reducers.add); @@ -60,8 +64,10 @@ async function addPerson(e: SubmitEvent) { {/if}
    -

    People ({$people.length})

    - {#if $people.length === 0} +

    People{loading ? '' : ` (${$people.length})`}

    + {#if loading} +

    Loading…

    + {:else if $people.length === 0}

    No people yet. Add someone above!

    {:else}
      From db5844cfd36d3af8b2f51fcbbbe5b662776c0d39 Mon Sep 17 00:00:00 2001 From: Kris Jenkins Date: Wed, 18 Nov 2026 14:22:51 +0000 Subject: [PATCH 14/15] Compile the svelte-ts template's components in runes mode. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Svelte 5 decides per component whether to use runes. A component that uses no runes is compiled in legacy (Svelte 4) mode, where `export let` declares props and every top-level `let` is reactive. So someone who starts from this template and adds a component written from an older tutorial or an AI suggestion, say: gets no error and no warning: it builds and runs. The app now mixes two reactivity models, and that component quietly loses runes-only features such as $props, snippets and $derived. Nothing tells you which mode a file is in, so this is easy to miss. The template's own components all use runes, so it never came up. svelte.config.js now forces runes mode for the app's own components. The Svelte docs warn against setting compilerOptions.runes to true, because it also applies to components inside node_modules, which may have been written for legacy mode. So this uses vite-plugin-svelte's dynamicCompileOptions instead, and leaves files under node_modules alone. Svelte's docs say runes will be the default in Svelte 6. The check happens in vite build, not svelte-check, which doesn't read the vitePlugin options. The template's build script runs both, so it still fails. Checked with a scratch component like the one above: before this change the build succeeds; after it, the build fails with "Cannot use `export let` in runes mode — use `$props()` instead". --- templates/svelte-ts/svelte.config.js | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/templates/svelte-ts/svelte.config.js b/templates/svelte-ts/svelte.config.js index ed459535cc1..43b3b42313e 100644 --- a/templates/svelte-ts/svelte.config.js +++ b/templates/svelte-ts/svelte.config.js @@ -1,2 +1,12 @@ /** @type {import("@sveltejs/vite-plugin-svelte").SvelteConfig} */ -export default {}; +export default { + vitePlugin: { + // Compile this app's components in runes mode, so a component can't + // silently fall back to legacy mode. Components from dependencies keep + // whichever mode they were written in. + dynamicCompileOptions: ({ filename }) => + filename.split(/[/\\]/).includes('node_modules') + ? undefined + : { runes: true }, + }, +}; From 68494564e54e989604dd993ccb7ebcbf4d182906 Mon Sep 17 00:00:00 2001 From: Kris Jenkins Date: Wed, 18 Nov 2026 14:23:29 +0000 Subject: [PATCH 15/15] Say why the Svelte provider lives in Root.svelte. A new user's first instinct is often to move the connection setup out of Root.svelte and into main.ts, next to mount(), where setup code usually goes. That breaks: createSpacetimeDBProvider stores the connection in Svelte context, and setContext can only be called while a component is being initialised, so outside a component it throws. The template's README explains this, but people reading the code directly don't see that. Root.svelte now has a two-line comment at the call, saying what the provider does and why it has to be in a component. --- templates/svelte-ts/src/Root.svelte | 2 ++ 1 file changed, 2 insertions(+) diff --git a/templates/svelte-ts/src/Root.svelte b/templates/svelte-ts/src/Root.svelte index 65cfbf6bcb3..afea6ef02d2 100644 --- a/templates/svelte-ts/src/Root.svelte +++ b/templates/svelte-ts/src/Root.svelte @@ -32,6 +32,8 @@ const connectionBuilder = DbConnection.builder() .onDisconnect(onDisconnect) .onConnectError(onConnectError); +// Shares the connection with every component below this one. It uses Svelte +// context, so it has to be called in a component, not in main.ts. createSpacetimeDBProvider(connectionBuilder);