instantdb / instant

Instant is a modern Firebase. We make you productive by giving your frontend a real-time database.
https://instantdb.com
Apache License 2.0
6.69k stars 184 forks source link

Frequent `Validation failed for room` errors in dev #164

Open G2Jose opened 2 months ago

G2Jose commented 2 months ago

I seem to be running into this error a lot:

ERROR Validation failed for room {"client-event-id": "xxx", "op": "error", "original-event": {"client-event-id": "xxx", "data": {"id": "xxx", "online": true}, "op": "set-presence", "receive-q-delay-ms": 0, "room-id": "main", "session-id": "xxx", "total-delay-ms": 0, "worker-delay-ms": 0}, "status": 400, "type": "validation-failed"} ERROR This error comes with some debugging information. Here it is: {"data-type": "room", "errors": [{"message": "You have not entered this room yet."}], "input": {"app-id": "xxx", "room-id": "xxx", "session-id": "xxx"}}

(I've redacted actual ids for security).

The relevant part of the error seems to be You have not entered this room yet.

What am I doing wrong in this code? The docs don't indicate having to do anything to enter a room.

function usePresence() {
  const userId = useAppSelector(getCurrentUserId)
  const appState = useAppState()

  room.useSyncPresence({ id: userId, online: appState === 'active' })

  const presence = room.usePresence()

  return presence
}

const Component = () => {
  const { peers } = usePresence()
  return <SomeView />
}

Things I've tried:

  1. Reloading the javascript in the app (hitting r on expo cli) doesn't help, the error reappears after the refresh
  2. Fully closing the restarting the app (including javascript) doesn't help either
Platform: Android emulator
Version: @instantdb/react-native: 0.12.26
nimonian commented 2 months ago

Just an FYI I remember this being mentioned on the Discord server and someone said it was a bug.

I experience the same thing and I believe your code is fine. If I refresh several times, sometimes the bug goes away.

Hopefully it is fixed soon.