Skip to content

Conversation

@clockwork-tien
Copy link
Contributor

@clockwork-tien clockwork-tien commented Jan 29, 2026

Description of Changes

The PR implements the following updates:

  • Create a quickstart guide and client support for using SpacetimeDB directly in browser with script tags
  • A template to easily work with/test the implementation and get started with script tags

The bundle is served via https://unpkg.com/spacetimedb@latest/dist/browser.bundle.js, which only works after the package is published to npm, therefore to test locally we can use the browser-ts template and local bundle:

  1. Build local bundle
cd crates/bindings-typescript
pnpm install
pnpm build
  1. Use local bundle built in templateindex.html (swap the URL from unpkg)
- <script src="https://unpkg.com/spacetimedb@latest/dist/browser.bundle.js"></script>
+ <script src="../../crates/bindings-typescript/dist/browser.bundle.js"></script>
  1. Open browser-ts/index.html directly in browser along with spacetime start + publish the module spacetime publish --project-path spacetimedb browser-ts

Screenshots

image image

API and ABI breaking changes

Expected complexity level and risk

Testing

@clockwork-tien clockwork-tien marked this pull request as ready for review January 29, 2026 14:36
@clockwork-tien clockwork-tien force-pushed the tien/feat/js-script-tags branch from 63a4d9c to c07dfef Compare January 29, 2026 15:52
cloutiertyler and others added 3 commits January 30, 2026 09:39
Remove the custom Client class that used JSON protocol and HTTP for
reducer calls. Instead, use the standard DbConnection with code
generation, which uses BSATN binary protocol over WebSocket.

The browser-ts template now:
- Uses spacetime generate for TypeScript bindings
- Bundles bindings with vite into an IIFE
- Loads the bundle in index.html with inline JavaScript
@clockwork-tien
Copy link
Contributor Author

@cloutiertyler Thank you, I have applied the changes from #4167, merged/resolved conflicts and did a minor template description update. The PR is ready for review.

The IIFE and ESM browser bundles built from src/browser/index.ts
are not used by the browser-ts template (which bundles its own
bindings via Vite). The existing dist/index.browser.mjs already
covers the browser ESM use case for import maps.
@cloutiertyler
Copy link
Contributor

Removed the SDK-level browser bundle (src/browser/index.ts, the IIFE and ESM browser configs in tsup.config.ts) since nothing in the template actually uses them. The template bundles its own bindings via Vite instead. The existing dist/index.browser.mjs (built from src/index.ts) already covers the browser ESM use case.

Long-term, the plan is to have the code generator emit .js + .d.ts files instead of .ts, which would allow the template to drop the Vite build step entirely and use import maps to resolve spacetimedb imports natively in the browser. At that point, the generated bindings would just work with a <script type="importmap"> pointing spacetimedb at dist/index.browser.mjs on unpkg.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants