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

RangeError: Maximum call stack size exceeded with custom validator #298

Closed
dgcoffman opened this issue Jan 13, 2016 · 10 comments
Closed

RangeError: Maximum call stack size exceeded with custom validator #298

dgcoffman opened this issue Jan 13, 2016 · 10 comments

Comments

@dgcoffman
Copy link

"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:/christianalfoni/formsy-react/blob/master/API.md#validations

Similar issue: #106

@tnrich
Copy link

tnrich commented Jan 27, 2016

I am also seeing this error. Either this should get fixed, or the "inline" custom validator examples should be removed

@christopherdbull
Copy link

I'm seeing this as well. I've created a custom component and it's causing an infinite loop when there is no validation set. When I set validations to isExisty it behaves as expected.

@jwohlfert23
Copy link

+1

@jamedranoa
Copy link

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.

@ffigiel
Copy link

ffigiel commented Mar 21, 2016

@jamedranoa fantastic job debugging this!

@ffigiel
Copy link

ffigiel commented Mar 21, 2016

Other way you can get custom validators is this

Formsy.addValidationRule('notIn', (values, value, array) => !_.includes(array, value))

// usage
validations: {
    matchRegexp: /^[\w -]+$/,
    notIn: reservedNames,
},

@Stupidism
Copy link

Stupidism commented May 9, 2016

Why is this not fixed yet?
I came up into this bug last week and it has wasted me several hours locating the problem into formsy-react.

@dgcoffman
Copy link
Author

I think removing it from the docs and marking wontfix would be sufficient, if maintainers have no interest in fixing this feature.

@cj3kim
Copy link

cj3kim commented May 20, 2016

+1

@cj3kim
Copy link

cj3kim commented May 20, 2016

When will the solution be merged in?

sdemjanenko added a commit to meraki/mki-formsy-react that referenced this issue Jul 11, 2016
* christ/master:
  0.18.1
  Fixed christianalfoni#335: getErrorMessages is undocumented in API
  Fixed christianalfoni#298: RangeError: Maximum call stack size exceeded with custom validator
  Fixed uncontrollable/controllable components in examples
  Fixed christianalfoni#361: Unknown props `onValidSubmit`, `onSubmitted` on <form> tag
  Use better names for components wrapped into HOC
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants