Uploaded image for project: 'Realm JavaScript SDK'
  1. Realm JavaScript SDK
  2. RJS-2542

The useObject doesn't re-render when the value transitions from undefined to an object.

      How frequently does the bug occur?

      Always

      Description

      Hi Team,

      I'm using Redux to cache an array of IDs. However, when the Realm database is cleared, the re-rendering doesn't occur when the IDs are updated. I have conducted debugging, and I've observed that...

      The originalObjectRef.current in the useObject sometimes returns undefined, not null. However, within the function, it's checked using a null value.

      In line 81 always return undefined
      But in line 85 it's "originalObjectRef.current === null", when I change to "!originalObjectRef.current" => it's work fine

      diff --git a/node_modules/@realm/react/src/useObject.tsx b/node_modules/@realm/react/src/useObject.tsx
      index 3d438b1..6d5d189 100644
      --- a/node_modules/@realm/react/src/useObject.tsx
      +++ b/node_modules/@realm/react/src/useObject.tsx
      @@ -81,7 +81,7 @@ export function createUseObject(useRealm: () => Realm) {
               // Re-instantiate the cachedObject if the primaryKey has changed or the originalObject has gone from null to not null
               if (
                 !arePrimaryKeysIdentical(primaryKey, primaryKeyRef.current) ||
      -          (originalObjectRef.current === null && originalObject !== null)
      +          (!originalObjectRef.current && originalObject !== null)
               ) {
                 cachedObjectRef.current = createCachedObject({
                   object: originalObject ?? null,
      
      

      Stacktrace & log output

      No response

      Can you reproduce the bug?

      Always

      Reproduction Steps

      "realm": "11.0.0-rc.0",
      "@realm/react": "^0.5.2",
      "react-native": "0.68.5",

      Version

      11.0.0-rc.0

      What services are you using?

      Local Database only

      Are you using encryption?

      Yes

      Platform OS and version(s)

      0.68.5

      Build environment

      Which debugger for React Native: ..

      Cocoapods version

      No response

            Assignee:
            andrew.meyer@mongodb.com Andrew Meyer
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: