Skip to content

Add Dioxus code generation support (--lang dioxus)#4

Open
Copilot wants to merge 7 commits intomasterfrom
copilot/create-pr-for-dioxus-changes
Open

Add Dioxus code generation support (--lang dioxus)#4
Copilot wants to merge 7 commits intomasterfrom
copilot/create-pr-for-dioxus-changes

Conversation

Copy link

Copilot AI commented Feb 28, 2026

Ports the Dioxus-only changes from #2 onto current master, excluding the WASM SDK changes. Adds spacetime generate --lang dioxus as a new codegen target that produces reactive Dioxus 0.7+ hooks and signals alongside standard Rust SDK bindings.

Generated output (dioxus.rs module)

Connection management:

  • use_spacetimedb_context_provider(uri, module_name) — root-level context provider
  • use_spacetimedb_context(), use_connection(), use_connection_state(), use_connection_error()

Per-table hooks (generated for each table):

  • use_table_<name>() -> SyncSignal<Vec<Row>> — reactive signal updated via on_insert/on_update/on_delete callbacks

Per-reducer/procedure hooks:

  • use_reducer_<name>() / use_procedure_<name>() — returns a Clone callback invoking the reducer/procedure through the shared connection

Subscription:

  • use_subscription(&["SELECT * FROM ..."])

Example

fn App() -> Element {
    use_spacetimedb_context_provider("http://localhost:3000", "my-module");
    rsx! { UserList {} }
}

fn UserList() -> Element {
    let users = use_table_user();
    let send_msg = use_reducer_send_message();
    rsx! {
        for user in users.read().iter() { div { "{user.name}" } }
        button { onclick: move |_| send_msg("Hello".to_string()), "Send" }
    }
}

Implementation notes

  • Reuses all Rust type/table/reducer/procedure file generation; only adds a dioxus.rs module and injects pub mod dioxus; into mod.rs
  • All table signals are created at root level (TableSignals struct inside SpacetimeDbContext) to ensure they outlive child components
  • Uses SyncSignal (thread-safe) so SpacetimeDB callbacks can safely write from background threads
  • Updated for current codegen API: CodegenOptions parameter on generate_global_files, CodegenVisibility on iterators, 3-tuple (name, accessor_name, type_ref) from iter_table_names_and_types
  • Dioxus output is formatted with rustfmt; default output dir is src/module_bindings

API and ABI breaking changes

None. New --lang dioxus option is purely additive; existing generators are unaffected.

Expected complexity level and risk

2. Self-contained within the codegen module. Adds a new Lang impl that delegates all type/table/reducer/procedure file generation to Rust, only adding the dioxus.rs global module. No changes to existing generators, SDK, or server code.

Testing

  • test_codegen_dioxus snapshot test added and passing
  • All existing codegen tests still pass (test_codegen_rust, test_codegen_csharp, test_codegen_typescript)
  • spacetimedb-cli and spacetimedb-codegen build cleanly
  • Reviewer: verify generated dioxus.rs snapshot looks correct for the module-test module
Original prompt

This section details on the original issue you should resolve

<issue_title>create a new pr for the recent master branch like #2</issue_title>
<issue_description>The new pr should only contain the dioxus related changes from #2 and not the wasm related ones.</issue_description>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the build failed saying strict field is missing in BuilderOptions

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It does build for me - can you elaborate on your build environment? And post the error?

I was building on Fedora Linux.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry it's actually BundlerOptions not BuilderOptions

Look at this: https://github.com/rolldown/rolldown/blob/main/crates%2Frolldown_common%2Fsrc%2Finner_bundler_options%2Fmod.rs

The last field of BO is strict maybe it was added recently, I added it and the build succeeded, I am on arch.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i verified, it won't be an issue for you, the strict field is not required in rolldown/tag: v1.0.0-rc.3, the one you are using, i updated it that whats caused the issue, my bad.

@Nirajsah
Copy link

Nirajsah commented Mar 4, 2026

nice work~ 👍

@enaut enaut force-pushed the copilot/create-pr-for-dioxus-changes branch from efed210 to dac993c Compare March 20, 2026 18:44
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.

create a new pr for the recent master branch like #2

3 participants