ajv
ajv copied to clipboard
ajv.compile not working in react native but working in react web after v7.0.0 release.
ajv.compile doesn't works on mobile (On web it is working fine) and crashes the app, looks like it goes in infinite recursion. It was working fine before version 7.0.0
react: 17.0.2 react-native: 0.67.2 ajv: 8.11.0
import Ajv from 'ajv';
const ajv = new Ajv();
const IPasswordRecoveryTokenSchema = {
type: 'object',
properties: {
token: { type: 'string' },
expiresAtMs: { type: 'number' },
},
required: ['token', 'expiresAtMs'],
additionalProperties: false,
};
export const IPasswordRecoveryTokenValidator = ajv.compile(IPasswordRecoveryTokenSchema);
RangeError: Maximum call stack size exceeded (native stack depth), js engine: hermes
I am facing the same issue. Any idea how we can address this or if there are any plans to fix this?
Thanks.
Same issue here. RangeError: Maximum call stack size exceeded (native stack depth)
Probably need to add note to the docs that this library doesn't support react native. We have it integrated in our quite huge web app which reuses validation logic with react native, and now when we enabled validation in react native we found this unpleasant fact.
I have just run into this problem as well using the Hermes JavaScript engine on react-native.
Stepping through the code, it seems to loop on this line.
I suspect we need a polyfill of some sort for react-native. Perhaps the Regex implementation is not correct?
Missing features from ES9 include: Named capture groups. Unicode property escapes.
Also, I'm wondering if anyone has tried the standalone implementation?
@epoberezkin do you have any suggestions for what might be causing this problem?
On further reading, it looks like it could be a problem with eval(). Hermes does not support local eval. I don't understand the local mode limitation and if this is something that can be worked around.
I guess AJV will not be compatible with react-native/hermes. Anyone working on a validator that does not use eval? 😬
If Function constructor is not supported by some JavaScript environment, you should be able to compile the schemas during build time (as long as they are not dynamically generated at run time) - see standalone validation functions in docs.
I believe you can use a standard-compliant JS engine with react-native, so the problem is more narrow than react-native - it seems specific to Hermes from the comments.
That they made a non-standard JS engine default is surprising…
Same issue here. RangeError: Maximum call stack size exceeded (native stack depth)
@surushTodzhibekov this is unrelated - please search the issues - either you used self-referencing object for schema, or schema is too deep, or you used something to de-reference $refs
Thanks for your quick reply @epoberezkin!
I think Hermes may be required for the new Fabric architecture (unsure), but it seems that react-native team is pushing everyone to use Hermes.
I'm going to look at standalone implementation for the immediate future.
re:
RangeError: Maximum call stack size exceeded (native stack depth)
This is the same error message that I am seeing in Hermes in iOS. Note: it works fine on web and electron. I haven't tested on Android.
AJV is truly not compatible with the Hermes engine, which is the de-facto new default of react-native. Would be awesome if this issue could be solved.
After some debugging on my end, it seems that the Function.prototype.call(), Function.prototype.apply() along with Array.prototype.reduce() that is used in recursion by this library is limited by the call stack size of hermes. Which, at this point seems to be 128 calls.
We are facing the same issue in react-native
RangeError: Maximum call stack size exceeded (native stack depth)
I am stuck on this error, too. Did anyone come up with a work-around yet?