Skip to content

Upgrading @realm/react from 0.7.0 to 0.8.0+ breaks app #6842

@nzapponi

Description

@nzapponi

How frequently does the bug occur?

Always

Description

Unable to keep the app running, the realm keeps getting closed for no reason

Stacktrace & log output

Error: Cannot access realm that has been closed.

Can you reproduce the bug?

Always

Reproduction Steps

This is how the provider is initialized:

import { RealmProvider as Provider } from "@realm/react";
import { Buffer } from "buffer";
import { PropsWithChildren, useContext } from "react";
import Spinner from "../components/Spinner";
import { schemas } from "../lib/store/db/realm";
import { EncryptionKeyContext } from "./SessionProvider";

export default function RealmProvider({ children }: PropsWithChildren) {
  const encryptionKeys = useContext(EncryptionKeyContext);

  if (!encryptionKeys.realmKey) {
    return <Spinner />;
  }

  return (
    <Provider
      schema={schemas}
      schemaVersion={5}
      encryptionKey={Buffer.from(encryptionKeys.realmKey, "base64")}
    >
      {children}
    </Provider>
  );
}

This provider only mounts once, so it shouldn't ever close.

Version

0.8.0+

What services are you using?

Local Database only

Are you using encryption?

Yes

Platform OS and version(s)

iPhone 15, OS 17.5

Build environment

Expo 51.0.26
Realm 12.12.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