-
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
BSON: For React Native please polyfill crypto.getRandomValues #3714
Comments
Looks like this started to happen after BSON upgraded from "4.2.3" to "4.3.0" (dependency of Realm) which is odd since Realm locks the version to "^4.2.0" |
@cristianoccazinsp very sorry for the confusion - it's an oversight on my part in the latest changes to the BSON package. A PR has been dispatched and will hopefully be out soon: mongodb/js-bson#435 |
@steffenagger thank you! Looking forward to the update. Do you happen to know if we should still install the recommended dependency when using Realm? It would be great for warnings to only happen in DEV also. |
@cristianoccazinsp If you're generating The reason being that a part of |
@cristianoccazinsp in regards to your comment here: mongodb/js-bson#435 (comment) the warning should disappear if you install https://www.npmjs.com/package/react-native-get-random-values (and follow the instructions - it has to be loaded). This is not a solution, by any means, but could perhaps be better than having false error reporting, for the time being? |
@steffenagger thanks for the suggestion! I would rather wait than adding a dependency that will be pretty much unused. Would it break Realm if I downgrade bson to 4.2.x directly in the lock file? |
@cristianoccazinsp for |
@steffenagger, I'm using RealmJS 10.10.1 and I still get this warning message when I use |
Which version of the Can you provide a small code snippet which can reproduce the issue? |
It looks like I don't have the Currently this is how I turn an id into an ObjectID to write to MongoDB (I'm using React Native):
|
@mednche did you rebuild the app, after adding I'm not working at Realm anymore, so I'd probably refer you to @kneth, if further investigation is needed :) |
My simple app (with the code from #3714 (comment)) doesn't give me a warning. Please run If you create a simple app and install BSON ( |
@kneth, thanks for your reply. So, I've run [email protected] I've created a simple app and installed BSON (with |
I am getting the same and realm doesnt write after that warning. I have tried everything in vain. Did u get a work around? |
@xtianmpimbaza, nope, still haven't found a way around it. In my case, it doesn't prevent Realm writes though. @kneth, any idea why those warnings are showing? |
I put
|
Thx @andrelomba86! This approach solved my problem. |
For anyone else who's finding this thread while being new to Realm (and possibly React Native): The total steps as of now are:
|
I'm struggling to understand why this is not a dependency and therefore showing up as an error to people who are using Realm inside React Native. As I understand it, Realm requires that the ID has a portion that's random. Therefore any time a BSON ID is generated it requires random values (which is why the error). The only time a dev would not run in to this is if they are not creating any items on-device. Personally that sounds like a very low-chance edge case. (Excepting the case above which seems like CI/CD testing) Pros to making it a dependency:
Cons:
Personally as a new user I think there's a strong case, but there are a lot of things I don't know about React Native, Realm, or the goals of the realm-js package so YMMV. |
@Joshfindit thanks for the detailed analysis! We'll discuss this on our team meeting next week and I'll report back. |
What is the status on this? As its been almost six months others are waiting on how to handle this... |
this issue is still present right ? I can see it has been detected way back and there has been action to solve but fast forward to now and I still get the same warning ? Am I doing something wrong ? |
@adhamhassan99 Please create a new issue with all details for us to reproduce it. |
|
This comment was marked as spam.
This comment was marked as spam.
It seems this is causing confusing to quite a lot of people, although we believe the instructions are straight forward, the need for this might not be clear and it seems we never clarified this. The reason we are not adding the polyfill as a dependency of our package is three-fold:
If you you're experiencing the warning, you have a few options:
|
@kraenhansen Thank you for your answer. What can I use instead of ObjectId or UUID? In my case it can only be an int value that can be unique. For example, a unique id with +1 more than the other, such as 1, 2, 3... will do the job. Or I can ignore the warning if it won't cause a problem as you stated. |
Ints could work as primary key, but many just use a string. Some even generate a cryptographically strong UUID using another library and simply store it in a string property. |
@kraenhansen I don't need a structure that would require me to have a very strong id. But I want it to be practical. Is there a way I can increase it automatically? For example, is there a method that I can add as default without dealing with queries? |
@bloggerklik since Realm is designed to be easy to use when synchronising data between clients, we don't currently support an "auto-increment" default on ints. The risk of two clients picking the same id and getting into conflicts because of that seems like a "foot-gun" that we don't want to actively encourage. This is however not an issue if you're local only and you could probably use the feature of passing a function as default: // ... Be aware, I haven't actually tested this code 🙈
properties: {
id: {
type: "int",
default: () => realm.objects("Thing").max("id") + 1,
},
} Anyways, we're outside of the scope of this issue and I'll lock it for now to avoid pinging people that might be watching it. |
Goals
Regular use.
Expected Results
Regular use.
Actual Results
A warning started appearing after upgrading to Realm 10.4.0.
Steps to Reproduce
Just use Realm (offline)
Code Sample
Version of Realm and Tooling
The text was updated successfully, but these errors were encountered: