-
Notifications
You must be signed in to change notification settings - Fork 585
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
Printing calling stack frame when accessing global Realm
#5628
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Cool warning. Will be great to get rid of this soon
const stack = err instanceof Error ? err.stack || "" : ""; | ||
return stack | ||
.split("\n") | ||
.map((line) => line.trim()) | ||
.filter((line) => line.startsWith("at")) | ||
.splice(1); // Skipping this function |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Did you test that on all of node, hermes, and JSC? I know the stack format can differ between engines.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nope ... I thought I wanted to add this with support for Node.js first and then add to it later (because it'll take time to test across runtime).
Anyways, thanks for the reminder. I'll likely test this tomorrow 🤞
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is the output on iOS with Hermes (arguably not the most useful because source-maps aren't applied by default 🤔) - but also it doesn't blow up 🤷♂️ :
Your app is relying on a Realm global, which will be removed in realm-js v13, please update your code to ensure you import Realm via a named import:
import { Realm } from "realm"; // For ES Modules
const { Realm } = require("realm"); // For CommonJS
This is happening at anonymous (http://192.168.1.101:8081/index.bundle?platform=ios&dev=true&minify=false&modulesOnly=false&runModule=true&app=org.reactjs.native.example.RealmReactNativeTests:162740:5)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When revisiting this, I came up with a better strategy: #5660
hi @kraenhansen , I'm already using Context is I've implemented a Singleton class for Realm to ensure reusability throughout the application. Creating a separate instance for each component doesn't seem practical. Or could you guide me to the recommended approach? |
@hpelitebook745G2 I see you've created #6209 ... I'll answer there. |
What, How & Why?
This will improve the warning logged when someone access the global
Realm
from their code, by including the source-code frame reading it: