-
Notifications
You must be signed in to change notification settings - Fork 563
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a workaround for React Native
Proxy
objects pre-JSI not working…
… properly with JSC. This change can be reverted once we go to v11. Fixes #4507
- Loading branch information
Tom Duncalf
committed
Apr 29, 2022
1 parent
9c589ad
commit 4c0cc9c
Showing
7 changed files
with
80 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
//////////////////////////////////////////////////////////////////////////// | ||
// | ||
// Copyright 2021 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. | ||
// | ||
//////////////////////////////////////////////////////////////////////////// | ||
|
||
import { symbols } from "@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" | ||
// the proxy - see https://github.com/realm/realm-js/issues/4507#issuecomment-1112237740. | ||
// | ||
// In order to enable the return value of Realm React's `useQuery` (which are wrapped | ||
// in a proxy) to be passed to the subscription mutation methods, we need to store | ||
// the unproxied results on the proxy object as a non-enumerable field with a symbol key | ||
// (see `useQuery.ts` in @realm/react), then in here, we check if that field exists, and | ||
// 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. | ||
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]); | ||
} | ||
}); | ||
|
||
const staticMethods = { | ||
// none | ||
}; | ||
|
||
module.exports = { | ||
static: staticMethods, | ||
instance: instanceMethods, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const REALM_REACT_PROXIED_OBJECT = Symbol('REALM_REACT_PROXIED_OBJECT'); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters