Skip to content

Regression after upgrading React Native 0.82.1 → 0.83.0 and React 19.1.1 → 19.2.0: “Accessing object which has been invalidated or deleted” when using useQuery results in UI #7086

@AlexeyLyt

Description

@AlexeyLyt

How frequently does the bug occur?

Always

Description

After upgrading React Native from 0.82.1 to 0.83.0 and React from 19.1.1 to 19.2.0, I started to consistently encounter the following runtime error in React Native UI when reading Realm objects obtained via useQuery after a realm.write mutation:

Error: Accessing object which has been invalidated or deleted

This error did not occur before the upgrade, with the same Realm schemas and update logic.
The issue appears to be triggered when:

  • Realm objects (or nested lists) returned from useQuery
  • are consumed directly in the UI (e.g. FlatList / FlashList)
  • and a realm.write updates nested embedded lists using splice

Stacktrace & log output

Error: Accessing object which has been invalidated or deleted
    at construct (native)
    at get (default.js:30:40)
    at addObjectDiffToProperties (ReactFabric-dev.js:2020:25)
    at logComponentRender (ReactFabric-dev.js:2194:47)
    at commitPassiveMountOnFiber (ReactFabric-dev.js:12034:31)
    ...
    at flushPassiveEffects (ReactFabric-dev.js:14844:34)
    at performSyncWorkOnRoot (ReactFabric-dev.js:3685:30)

Error: Should not already be working.
    at performWorkOnRoot (ReactFabric-dev.js:13007:20)

Can you reproduce the bug?

Always

Reproduction Steps

Schema structure (simplified)

class RoomSchema {
  _id!: Realm.BSON.ObjectId;
  rooms!: Realm.List<Room>; // embedded: true
}

class Room {
  chatId!: string;
  messages!: Realm.List<Message>; // embedded: true
}

class Message {
  id!: string;
  text!: string;
  // contains nested embedded objects and lists
}

Both rooms and messages are embedded objects.

Write logic (inside realm.write)

const state = realm.objects<RoomSchema>('Room')[0];
const room = state.rooms.find((r) => r.chatId === roomId);
// prepare updated messages
const newMessages = JSON.parse(JSON.stringify(room.messages));
// do some changes for newMessages and replace origin "room.messages"
room.messages.splice(0, room.messages.length, ...newMessages);

I am using splice because it is the only reliable way I found to update nested Realm.List values without breaking Realm internals (assigning a new array does not work)

Read logic (React UI)

const state = useQuery<RoomSchema>('Room')[0];
const getRoomById = (chatId: string) => {
  return state?.rooms?.find((r) => r.chatId === chatId);
};
const getRoomMessages = (chatId: string) => {
  const room = getRoomById(chatId);
  return room?.messages ?? [];
};

And in a React Native component:

const messages = getRoomMessages(chatId);
// used in FlatList / FlashList / any UI

Observed behavior

After a realm.write that mutates room.messages, the UI may crash during render or passive effects
The error indicates that an object accessed during render was already invalidated or deleted
This happens even though:

  • the list itself was mutated via splice
  • the parent objects still exist

The issue reproduces reliably on RN 0.83 + React 19.2

Workaround

If I deep-clone the data before returning it to the UI, the error disappears:
return JSON.parse(JSON.stringify(room?.messages)) ?? [];

This strongly suggests the issue is related to live Realm objects being accessed during React render, possibly due to changes in React 19.2 / Fabric scheduling.
However, JSON.stringify is too expensive for production and not a viable long-term solution.

Expected behavior

Accessing objects returned by useQuery should not crash the UI after a realm.write
Or at least the documentation should clearly state that:

  • values returned from useQuery must not be consumed directly in UI
  • deep snapshots are required under React 19 / Fabric

Question

Is this:

  • an expected behavior change with React 19 / Fabric?
  • a known limitation of useQuery with embedded lists?
  • or a regression that Realm plans to address?

I would appreciate guidance on the recommended pattern for:

  • updating nested embedded lists
  • and safely consuming them in React Native UI under RN 0.83+

The same codebase worked without issues on RN 0.82.1 + React 19.1.1
No changes were made to Realm schemas or write logic
Only the React / React Native upgrade triggered the problem
This issue is reproducible not only on my machine, but also for all other developers on the same project, using the same versions and codebase

Version

realm - 20.2.0, @realm/react - 0.20.0

What services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

Android 13–14 and iOS 17.x

Build environment

Which debugger for React Native:
React Native 0.83 introduced the new built-in React Native DevTools (including Network inspection), which are enabled by default. The issue reproduces with these DevTools enabled as part of the standard RN 0.83 setup.

Node.js 22.16.0
Gradle 9.0.0
Android Gradle Plugin 8.9.1

Cocoapods version

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions