question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

RangeError: Maximum call stack size exceeded with custom validator

See original GitHub issue

"react": "0.14.2", "formsy-react": "0.17.0",

We have a component Form:

import Formsy from 'lib/Formsy';
import FormInput from 'FormInput.jsx';
import React from 'react';

const Form = React.createClass({
  render()
  {
    return (
      <div>
        <Formsy.Form onValid={() =>  this.setState({anything: true})}>
          <FormInput name="uid" validations={{ customValidator: () => true }} />
        </Formsy.Form>
      </div>
    );
  },
});
export default Form;

using FormInput:

const React = require('React');
const Formsy = require('lib/Formsy');

const FormInput = React.createClass({
  mixins: [Formsy.Mixin],

  changeValue: function (event) {
    this.setValue(event.currentTarget.value);
  },

  render() {
    return <input type="text" onChange={this.changeValue}/>
  },
});

module.exports = FormInput;

Mounting the component or typing a character in the input causes RangeError: Maximum call stack size exceeded to be thrown to the console.

FWIW, here is a screenshot of the stacktrace for the exception thrown on component mount: stack trace

Replacing customValidator: () => true with a built-in validator like isExisty: true does not cause this exception to be thrown.

Registering a custom validator like:

Formsy.addValidationRule('isAnything', function(values, value, array) {
  return true;
});

and then using it

isAnything: true

does not cause this exception to be thrown.

I haven’t been able to figure out how to implement a custom validator as shown in this example: https://github.com/christianalfoni/formsy-react/blob/master/API.md#validations

Similar issue: https://github.com/christianalfoni/formsy-react/issues/106

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10

github_iconTop GitHub Comments

5reactions
jamedranoacommented, Mar 15, 2016

the problem is coming from here, that if condition will always be false if the component has a custom validation (a function) because the function isSame will always return false when is comparing the two functions allocated in two different objects (new props, prevProps). and the function formsy.validate will make use of setState which will repeat the cycle.

one solution (not ideal) could be adding a condition to compare functions on the isSame function and compare the toString result.

 fun1.toString() === fun2.toString();

but I’m not sure if this could have negative implications in others parts of the code.

0reactions
cj3kimcommented, May 20, 2016

When will the solution be merged in?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Angular: when add remove Validators and update form status ...
The RangeError: Maximum call stack size exceeded error is thrown because you're calling the updateValueAndValidity() function within the ...
Read more >
JavaScript RangeError: Maximum Call Stack Size Exceeded
The RangeError: Maximum call stack size exceeded is thrown when a function call is made that exceeds the call stack size. This can...
Read more >
ExtJs 4.2.4 isValid in custom Validator: Uncaught RangeError
Coding example for the question ExtJs 4.2.4 isValid in custom Validator: Uncaught RangeError: Maximum call stack size exceeded-ext.js.
Read more >
Editable List View javascript error - Maximum call stack size ...
I checked the browser console and there is a JavaScript error: Uncaught RangeError: Maximum call stack size exceeded.
Read more >
RangeError: Maximum call stack size exceeded - Educative.io
The most common source for this error is infinite recursion. You must have a recursive function in your code whose base case is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found