You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
vibed/quotesdb/.beans/quotesdb-1o8u--triage-nanoi...

2.4 KiB

title status type priority created_at updated_at
[TRIAGE] NanoID crate WASM compatibility with workers-rs target completed task critical 2026-03-10T23:32:08Z 2026-03-10T23:32:08Z
This is a triage decision ticket. It must be resolved before dependent implementation tickets can proceed. NanoID crate WASM compatibility: does the chosen nanoid crate compile for wasm32-unknown-unknown with the workers-rs target? Some crates use thread-local RNG which is not available in WASM. 1. **nanoid crate** — check if it supports `getrandom` with `js` feature for WASM. 2. **uuid v4** — widely compatible, UUIDs are slightly longer than NanoIDs but universally supported. 3. **Custom NanoID** — implement NanoID generation using `getrandom` + custom alphabet. ~20 lines of code, no extra dependency. **RESOLVED 2026-03-02 — Use UUID v4 (`uuid` crate).**

Decision: Option 2 — uuid v4

The nanoid crate (v0.4.0) depends on rand ^0.8, which uses thread_rng() (thread-local RNG). Thread-local storage is unreliable in wasm32-unknown-unknown, and the underlying getrandom wasm_js feature is explicitly discouraged in libraries by the getrandom maintainers.

uuid = { version = "1", features = ["v4", "serde"] } with getrandom = { version = "0.2", features = ["js"] } (wasm32 cfg section only) is the proven, zero-risk approach for Cloudflare Workers. UUID v4 produces 36-char hyphenated IDs — slightly longer than NanoID's 21 chars, but negligible in practice and universally supported.

Created ticket

7a0d9f — "Implement generate_id() in src/lib.rs — UUID v4 for WASM-compatible quote IDs"

  • generate_id() in src/lib.rs returns uuid::Uuid::new_v4().to_string()
  • Cargo.toml adds uuid to [dependencies] and getrandom/js under [target.'cfg(target_arch = "wasm32")'.dependencies]
  • Ticket 05f8ae (PUT handler) and 1f5bb5 (Cargo.toml) updated to reference this approach

Updated tickets

  • 05f8ae: "Generate a NanoID for the quote ID" → use generate_id() from lib.rs (UUID v4)
  • 1f5bb5: Add uuid = { version = "1", features = ["v4", "serde"] } to [dependencies]; add getrandom = { version = "0.2", features = ["js"] } under wasm32 cfg
`chore(quotesdb): resolve triage — nanoid-crate-wasm-compatibility-with-workersrs-target`