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

Collection reference from `useQuery()` not updating w/o dep. list

    • Type: Icon: Bug Bug
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: Realm React, WASM
    • None

      This is regarding React (not React Native) and our WASM build.

      Dependencies Used

      • @realm/react@0.5.1
      • realm@12.0.0-browser.2

      Problem

      The following code works as expected in React Native but not in React:

      Unable to find source-code formatter for language: ts. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      const tasks = useQuery(Task);
      

      Behavior:

      Workaround

      The following code is a temporary solution users can implement as a workaround:

      Unable to find source-code formatter for language: ts. Available languages are: actionscript, ada, applescript, bash, c, c#, c++, cpp, css, erlang, go, groovy, haskell, html, java, javascript, js, json, lua, none, nyan, objc, perl, php, python, r, rainbow, ruby, scala, sh, sql, swift, visualbasic, xml, yaml
      const [requeryFlag, setRequeryFlag] = useState(false);
      const tasks = useQuery(Task, (collection) => collection, [requeryFlag]);
      useEffect(() => {
        // The value doesn't matter, only that it is different from the initial value.
        setRequeryFlag(true);
      }, []); // <-- Only on mount is needed
      

      Note that the useEffect() only needs to run on mount for useQuery() to correctly update.

      Reproduce

      Minimal local Realm app to reproduce the behavior: react-userquery-bug.zip

      Notes

      This issue does not seem to appear in React Native.

            Assignee:
            Unassigned Unassigned
            Reporter:
            unitosyncbot Unito Sync Bot
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: