clockworklabs / clockworklabs/SpacetimeDB

Rust reducers must disallow reducers starting with reserved prefix

Open
#2,175 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Rust
Stars
25.2k
Forks
1.1k
Avg merge
2d 7h
Merged PRs (30d)
46

Description

The API proposal states:

Reserved reducer names

We reserve all reducer names beginning with two underscores __, and with on or On. Double-underscore reducer names are used internally to implement built-in reducers, and on/On are used in SDK codegen for reducer callbacks.

Attempting to define a reducer with a name that matches these patterns will cause an error at macro-expand time. Implementors are also encouraged to signal an error at publish time if a module circumvents the bindings library and manually constructs a ModuleDef containing one of these names in a reserved position.

Those are rejected in C# as per proposal, but not in Rust. In fact, rust-wasm-test actually defines such a reducer that should be illegal now:

https://github.com/clockworklabs/SpacetimeDB/blob/729dbb149599b4535c3b4d4e2fb4594be7ea448f/modules/rust-wasm-test/src/lib.rs#L241-L242

and in generated TS code it ends up looking as OnOnConnect event.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the reserved reducer proposal and the reducer definition at modules/rust-wasm-test/src/lib.rs#L241-L242, then trace Rust macro expansion and validation. Ensure names beginning with __, on, or On are rejected at macro-expand time, and verify the generated TypeScript no longer produces names such as OnOnConnect.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust, typescript
Domain
backend-api-design
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.