diff --git a/CHANGELOG.md b/CHANGELOG.md index fdbbd82d10..95ebbd27d4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ x.x.x Release notes (yyyy-MM-dd) * Fixed issue where React Native apps would sometimes show stale Realm data until the user interacted with the app UI ([#4389](https://github.com/realm/realm-js/issues/4389), since v10.0.0) * Fixed race condition leading to potential crash when hot reloading an app using Realm Sync ([4509](https://github.com/realm/realm-js/pull/4509), since v10.12.0) * Updated build script to use Xcode 12.4 to ensure xcframework is Bitcode compatibile with older versions ([#4462](https://github.com/realm/realm-js/issues/4462), since v10.0.0) +* Proxied `Realm.Results` (e.g. as returned from `useQuery` in `@realm/react`) could not be used with `MutableSubscriptionSet.add`/`remove` ([#4507](https://github.com/realm/realm-js/issues/4507), since v10.12.0) * Adding an object to a Set, deleting the parent object, and then deleting the previously mentioned object causes crash ([#5387](https://github.com/realm/realm-core/issues/5387), since v10.5.0) * Synchronized Realm files which were first created using SDK version released in the second half of August 2020 would be redownloaded instead of using the existing file, possibly resulting in the loss of any unsynchronized data in those files (since v10.10.1). diff --git a/lib/mutable-subscription-set.js b/lib/mutable-subscription-set.js index 4dac8af9cc..700e3d843b 100644 --- a/lib/mutable-subscription-set.js +++ b/lib/mutable-subscription-set.js @@ -1,6 +1,6 @@ //////////////////////////////////////////////////////////////////////////// // -// Copyright 2021 Realm Inc. +// Copyright 2022 Realm Inc. // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. @@ -16,7 +16,7 @@ // //////////////////////////////////////////////////////////////////////////// -import { symbols } from "@realm.io/common"; +const { symbols } = require("@realm.io/common"); // React Native `Proxy` objects when not using JSI are not compatible with // `JSValueIsObjectOfClass`, because it seems JSC is not able to "unwrap" @@ -29,14 +29,14 @@ import { symbols } from "@realm.io/common"; // if so we pass the original unproxied results to C++. // // Once our v11 branch is merged, we can revert this change as JSI React Native `Proxy`s -// work fine, by reverting PR #xxxx. +// work fine, by reverting PR #4541. const instanceMethods = (realmConstructor) => ({ add(query, options) { return this._add(query[symbols.REALM_REACT_PROXIED_OBJECT] || query, options); }, remove(query) { - return this._remove(query[symbols.REALM_REACT_PROXIED_OBJECT]); + return this._remove(query[symbols.REALM_REACT_PROXIED_OBJECT] || query); } }); diff --git a/packages/realm-common/src/symbols.ts b/packages/realm-common/src/symbols.ts index 9d3ee66d49..54556276d3 100644 --- a/packages/realm-common/src/symbols.ts +++ b/packages/realm-common/src/symbols.ts @@ -1 +1,19 @@ -export const REALM_REACT_PROXIED_OBJECT = Symbol('REALM_REACT_PROXIED_OBJECT'); \ No newline at end of file +//////////////////////////////////////////////////////////////////////////// +// +// Copyright 2022 Realm Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +// +//////////////////////////////////////////////////////////////////////////// + +export const REALM_REACT_PROXIED_OBJECT = Symbol("REALM_REACT_PROXIED_OBJECT"); diff --git a/packages/realm-react/CHANGELOG.md b/packages/realm-react/CHANGELOG.md index 114f72a5ca..15597f1d77 100644 --- a/packages/realm-react/CHANGELOG.md +++ b/packages/realm-react/CHANGELOG.md @@ -24,6 +24,7 @@ const SomeComponent = () => { ### Fixed * Fixed potential "Cannot create asynchronous query while in a write transaction" error with `useObject` due to adding event listeners while in a write transaction ([#4375](https://github.com/realm/realm-js/issues/4375), since v0.1.0) +* Results from `useQuery` could not be passed to `MutableSubscriptionSet.add`/`remove` ([#4507](https://github.com/realm/realm-js/issues/4507), since v0.1.0) ### Compatibility * None.