Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding more precise detection of Expo Go #6523

Merged
merged 2 commits into from
Apr 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
* Added support for using aggregate operations on Mixed properties in queries. ([realm/realm-core#7398](/~https://github.com/realm/realm-core/pull/7398))
* Improved file compaction performance on platforms with page sizes greater than 4k (for example arm64 Apple platforms) for files less than 256 pages in size. ([realm/realm-core#7492](/~https://github.com/realm/realm-core/pull/7492))
* Added the ability to set the log level for one or more categories via `Realm.setLogLevel`. ([#6560](/~https://github.com/realm/realm-js/issues/6560))
* Added detection and better instructions when imported from the Expo Go app. ([#6523](/~https://github.com/realm/realm-js/pull/6523))

### Fixed
* Aligned Dictionaries to Lists and Sets when they get cleared. ([#6205](/~https://github.com/realm/realm-core/issues/6205), since v10.3.0-rc.1)
Expand Down
41 changes: 41 additions & 0 deletions packages/realm/src/platform/react-native/expo-go-detection.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
////////////////////////////////////////////////////////////////////////////
//
// Copyright 2024 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 { Platform } from "react-native";

export function isExpoGo() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it need to be exported?

Suggested change
export function isExpoGo() {
function isExpoGo() {

try {
// @ts-expect-error - This depends on unstable Expo implementation details
return typeof expo === "object" && expo.modules?.ExponentConstants?.executionEnvironment === "storeClient";
} catch {
return false;
}
}

export class RealmInExpoGoError extends Error {
constructor() {
const runCommand = `npx expo run:${Platform.OS}`;
super(
`'realm' was imported from the Expo Go app, but unfortunately Expo Go doesn't contain the native module for the 'realm' package - consider using an Expo development build instead:\n\nnpm install expo-dev-client\n${runCommand}\n\nRead more: https://docs.expo.dev/develop/development-builds/introduction/`,
);
}
}

if (isExpoGo()) {
throw new RealmInExpoGoError();
}
1 change: 1 addition & 0 deletions packages/realm/src/platform/react-native/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
//
////////////////////////////////////////////////////////////////////////////

import "./expo-go-detection";
import "./binding";
import "./fs";
import "./device-info";
Expand Down
Loading