Skip to content

[TS SDK] TypeError: Cannot read properties of undefined (reading 'reducerName') when scheduled reducer fires #3871

Description

@mcgl0vin

Description

When a scheduled reducer (timer) fires on the server, the TypeScript SDK crashes with:
Uncaught (in promise) TypeError: Cannot read properties of undefined (reading 'reducerName') at index-CCjekHwN.js:23:204433 at Array.find ()

This occurs because TransactionUpdate messages from scheduled reducers don't include reducerInfo, but the SDK unconditionally accesses reducerInfo.reducerName in multiple places.

Affected Lines (v1.11.0)

In `dist/index.mjs`:
- Line 4850: [(t2) => t2.name === reducerInfo.reducerName](cci:1://file:///****/client/src/lib/localCache.ts:280:2-282:3)
- Line 4887: `name: reducerInfo.reducerName,`
- Line 4905: `reducerInfo.reducerName,`

Suggested Fix

Use optional chaining:

// Before
reducerInfo.reducerName
// After  
reducerInfo?.reducerName

Reproduction Steps

Create a Rust module with a scheduled reducer
Connect TypeScript client and subscribe to tables
Wait for the scheduled reducer to fire
Observe crash in browser console

Workaround

We patch the SDK after install in our postinstall script:

javascript
content.replace(
  /reducerInfo\.reducerName/g,
  '(reducerInfo==null?void 0:reducerInfo.reducerName)'
);

Environment
SpacetimeDB SDK: 1.11.0
Platform: Browser (Vite/React)
Server: maincloud

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions