realm-js icon indicating copy to clipboard operation
realm-js copied to clipboard

Maximum call stack size exceeded rendering three-level data structure in FlatList using @realm/react v0.4.3

Open myou11 opened this issue 2 years ago • 6 comments

How frequently does the bug occur?

Always

Description

Hi, I am having trouble with my app crashing due to rendering too many Realm items in a FlatList. I have a three level deep nested data structure similar to what can be seen in this repo. I modified the project from this previous related issue. In this previous issue, the PR that fixed it made some changes to cachedObject.ts. I am running into an issue with this file in particular. In my internal company project, my app crashes after adding around 60-80 items depending on the device I test on. Here is a picture of the stacktrace. You can see the "Maximum call stack size exceeded while running cachedObjectHandler.get. realmUNITO-UNDERSCORE!call!UNITO-UNDERSCORE!stack!UNITO-UNDERSCORE!size!UNITO-UNDERSCORE!exceeded!UNITO-UNDERSCORE!flatlist! Unfortunately, I can't reproduce the issue in the repo I linked earlier, but the repo does show a similar three-level data structure (Task ~~> Subtasks~~ > SubSubtasks) to my project. I am able to trigger the crash always by opening the app and adding 60-80 items. The interesting thing is that when I re-open the app, my previous 60-80 items I added before were there and it does not crash until I add another set of 60-80 items in that "session". I downgraded my app to a version I had previously, before I upgraded my @realm/react from 0.4.1 to 0.4.3. The 0.4.1 version does not encounter this issue. I was able to add 100+ items and no crash. I reinstalled the 0.4.3 version and got the crash like stated earlier. I'm not sure exactly how to get around this issue other than downgrading to 0.4.1, but I would like the fixes provided by 0.4.3.

Can you please help me take a look into this issue please?

Stacktrace & log output

No response

Can you reproduce the bug?

Always

Reproduction Steps

No response

Version

[email protected]

What services are you using?

Local Database only

Are you using encryption?

No

Platform OS and version(s)

iOS 16

Build environment

Which debugger for React Native: ..

Cocoapods version

No response

myou11 avatar Apr 14 '23 20:04 myou11

@myou11 Thank you for reporting. It looks like you have found a regression in 0.4.3 but we need to investigate it further.

Your 60-80 items are on the root level, right? How many subtasks and subsubtasks do you have?

kneth avatar Apr 18 '23 11:04 kneth

In my project, the equivalent to the reproduction repo would be: a Task is always added with at least one Subtask and at least one SubSubtask. For my testing, I only had one Subtask and SubSubtask under each Task, but 60-80 of those units as a whole would be enough to crash the app.

Thank you for taking the time to investigate!

myou11 avatar Apr 18 '23 15:04 myou11

We are seeing reports from our production app with same error message. CleanShot 2024-10-02 at 15 55 35@2x

Where transferCollection is simply:

  const transferCollection = useObject<TransferCollectionModel>(
    TransferCollectionModel.schema.name,
    transferCollectionIdObject
  );

The version of @realm/react we have is our own fork, due to open PR that is waiting to be merged :) But it is based on 9.0 (commit: f3db7f1bf916660d72d0e08876339f64ab063158).

Is there any idea how to fix it or any workaround?

bimusiek avatar Oct 02 '24 14:10 bimusiek

@kraenhansen Is there a plan to investigate the issue?

bimusiek avatar Oct 07 '24 10:10 bimusiek

@bimusiek none at the moment, we need some help reproducing this. What's the rate of this issue in your app? I mean, is this happening for everyone over a certain threshold of items in the collection, etc.? Are you able to reproduce this locally?

kraenhansen avatar Oct 07 '24 10:10 kraenhansen

We are not able to reproduce it locally, also does not happen to a lot of users. Few stacktraces with the same issue CleanShot 2024-10-07 at 17 01 04@2x CleanShot 2024-10-07 at 17 13 53@2x

So I guess not so important for us as well, until someone figures out how to reproduce the issue. Based on the logs, it does not happen long into app being opened so I would guess it is not based on number of changes being triggered.

bimusiek avatar Oct 07 '24 15:10 bimusiek