SpacetimeDB icon indicating copy to clipboard operation
SpacetimeDB copied to clipboard

Rust reducers must disallow reducers starting with reserved prefix

Open RReverser opened this issue 11 months ago • 0 comments

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.

RReverser avatar Jan 27 '25 16:01 RReverser