Skip to content

Conversation

israelshirk
Copy link
Contributor

Description

There's a really weird long error on compilation if you have an empty or falsey default form:

Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!

Source of issue

$digest repeatedly calls watch; on each call, when scope.initialForm is falsey, var form gets a new copy of [*]; on successive calls, new copy doesn't equal old and the scope gets modified so $digest makes another loop.

        scope.$watch(function() {

          var schema = scope.schema;
          var form   = scope.initialForm || ['*'];

          //The check for schema.type is to ensure that schema is not {}
          if (form && schema && schema.type &&
              (lastDigest.form !== form || lastDigest.schema !== schema) &&
              Object.keys(schema.properties).length > 0) {
            lastDigest.schema = schema;
            lastDigest.form = form;

            render(schema, form);
          }
        });

This works as expected -

        var defaultForm = ['*'];

        //Since we are dependant on up to three
        //attributes we'll do a common watch
        scope.$watch(function() {

          var schema = scope.schema;
          var form   = scope.initialForm || defaultForm;

          //The check for schema.type is to ensure that schema is not {}
          if (form && schema && schema.type &&
              (lastDigest.form !== form || lastDigest.schema !== schema) &&
              Object.keys(schema.properties).length > 0) {
            lastDigest.schema = schema;
            lastDigest.form = form;

            render(schema, form);
          }
        });

Full original error message...

Error: [$rootScope:infdig] 10 $digest() iterations reached. Aborting!
    Watchers fired in the last 5 iterations: [[{"msg":"schemaForm.form[0]","newVal":{"title":"First Name","description":"First Name","schema":{"id":"https://api.yeti-support.com#/definitions/first_name","type":"string","minLength":1,"title":"First Name","description":"First Name","name":"first_name"},"ngModelOptions":{},"key":["first_name"],"type":"text"}},{"msg":"schemaForm.form[1]","newVal":{"title":"Last Name","description":"Last Name","schema":{"id":"https://api.yeti-support.com#/definitions/last_name","type":"string","minLength":1,"title":"Last Name","description":"Last Name","name":"last_name"},"ngModelOptions":{},"key":["last_name"],"type":"text"}},{"msg":"schemaForm.form[2]","newVal":{"title":"Slug","description":"Slug","schema":{"id":"https://api.yeti-support.com#/definitions/slug","type":"string","minLength":6,"title":"Slug","description":"Slug","name":"slug"},"ngModelOptions":{},"key":["slug"],"type":"text"}},{"msg":"schemaForm.form[3]","newVal":{"title":"Password","description":"Password","schema":{"id":"https://api.yeti-support.com#/definitions/password","type":"string","minLength":1,"title":"Password","description":"Password","name":"password","default":"Password"},"ngModelOptions":{},"key":["password"],"type":"text"}},{"msg":"schemaForm.form[4]","newVal":{"title":"Spam","description":"Indicates whether the item is marked as spam","schema":{"id":"https://api.yeti-support.com#/definitions/spam","type":"boolean","title":"Spam","description":"Indicates whether the item is marked as spam","name":"spam","default":false},"ngModelOptions":{},"key":["spam"],"type":"checkbox"}},{"msg":"schemaForm.form[5]","newVal":{"title":"Google 2FA Token","description":"Google 2FA Token","schema":{"id":"https://api.yeti-support.com#/definitions/two_factor_token","type":"string","minLength":1,"title":"Google 2FA Token","description":"Google 2FA Token","name":"two_factor_token"},"ngModelOptions":{},"key":["two_factor_token"],"type":"text"}},{"msg":"schemaForm.form[6]","newVal":{"title":"E-mail Address","description":"E-mail Address","schema":{"id":"https://api.yeti-support.com#/definitions/email","type":"string","minLength":1,"title":"E-mail Address","description":"E-mail Address","name":"email","default":"email@address.com"},"ngModelOptions":{},"key":["email"],"type":"text"}}],[{"msg":"schemaForm.form[0]","newVal":{"title":"First Name","description":"First Name","schema":"<<already seen>>","ngModelOptions":{},"key":["first_name"],"type":"text"}},{"msg":"schemaForm.form[1]","newVal":{"title":"Last Name","description":"Last Name","schema":"<<already seen>>","ngModelOptions":{},"key":["last_name"],"type":"text"}},{"msg":"schemaForm.form[2]","newVal":{"title":"Slug","description":"Slug","schema":"<<already seen>>","ngModelOptions":{},"key":["slug"],"type":"text"}},{"msg":"schemaForm.form[3]","newVal":{"title":"Password","description":"Password","schema":"<<already seen>>","ngModelOptions":{},"key":["password"],"type":"text"}},{"msg":"schemaForm.form[4]","newVal":{"title":"Spam","description":"Indicates whether the item is marked as spam","schema":"<<already seen>>","ngModelOptions":{},"key":["spam"],"type":"checkbox"}},{"msg":"schemaForm.form[5]","newVal":{"title":"Google 2FA Token","description":"Google 2FA Token","schema":"<<already seen>>","ngModelOptions":{},"key":["two_factor_token"],"type":"text"}},{"msg":"schemaForm.form[6]","newVal":{"title":"E-mail Address","description":"E-mail Address","schema":"<<already seen>>","ngModelOptions":{},"key":["email"],"type":"text"}}],[{"msg":"schemaForm.form[0]","newVal":{"title":"First Name","description":"First Name","schema":"<<already seen>>","ngModelOptions":{},"key":["first_name"],"type":"text"}},{"msg":"schemaForm.form[1]","newVal":{"title":"Last Name","description":"Last Name","schema":"<<already seen>>","ngModelOptions":{},"key":["last_name"],"type":"text"}},{"msg":"schemaForm.form[2]","newVal":{"title":"Slug","description":"Slug","schema":"<<already seen>>","ngModelOptions":{},"key":["slug"],"type":"text"}},{"msg":"schemaForm.form[3]","newVal":{"title":"Password","description":"Password","schema":"<<already seen>>","ngModelOptions":{},"key":["password"],"type":"text"}},{"msg":"schemaForm.form[4]","newVal":{"title":"Spam","description":"Indicates whether the item is marked as spam","schema":"<<already seen>>","ngModelOptions":{},"key":["spam"],"type":"checkbox"}},{"msg":"schemaForm.form[5]","newVal":{"title":"Google 2FA Token","description":"Google 2FA Token","schema":"<<already seen>>","ngModelOptions":{},"key":["two_factor_token"],"type":"text"}},{"msg":"schemaForm.form[6]","newVal":{"title":"E-mail Address","description":"E-mail Address","schema":"<<already seen>>","ngModelOptions":{},"key":["email"],"type":"text"}}],[{"msg":"schemaForm.form[0]","newVal":{"title":"First Name","description":"First Name","schema":"<<already seen>>","ngModelOptions":{},"key":["first_name"],"type":"text"}},{"msg":"schemaForm.form[1]","newVal":{"title":"Last Name","description":"Last Name","schema":"<<already seen>>","ngModelOptions":{},"key":["last_name"],"type":"text"}},{"msg":"schemaForm.form[2]","newVal":{"title":"Slug","description":"Slug","schema":"<<already seen>>","ngModelOptions":{},"key":["slug"],"type":"text"}},{"msg":"schemaForm.form[3]","newVal":{"title":"Password","description":"Password","schema":"<<already seen>>","ngModelOptions":{},"key":["password"],"type":"text"}},{"msg":"schemaForm.form[4]","newVal":{"title":"Spam","description":"Indicates whether the item is marked as spam","schema":"<<already seen>>","ngModelOptions":{},"key":["spam"],"type":"checkbox"}},{"msg":"schemaForm.form[5]","newVal":{"title":"Google 2FA Token","description":"Google 2FA Token","schema":"<<already seen>>","ngModelOptions":{},"key":["two_factor_token"],"type":"text"}},{"msg":"schemaForm.form[6]","newVal":{"title":"E-mail Address","description":"E-mail Address","schema":"<<already seen>>","ngModelOptions":{},"key":["email"],"type":"text"}}],[{"msg":"schemaForm.form[0]","newVal":{"title":"First Name","description":"First Name","schema":"<<already seen>>","ngModelOptions":{},"key":["first_name"],"type":"text"}},{"msg":"schemaForm.form[1]","newVal":{"title":"Last Name","description":"Last Name","schema":"<<already seen>>","ngModelOptions":{},"key":["last_name"],"type":"text"}},{"msg":"schemaForm.form[2]","newVal":{"title":"Slug","description":"Slug","schema":"<<already seen>>","ngModelOptions":{},"key":["slug"],"type":"text"}},{"msg":"schemaForm.form[3]","newVal":{"title":"Password","description":"Password","schema":"<<already seen>>","ngModelOptions":{},"key":["password"],"type":"text"}},{"msg":"schemaForm.form[4]","newVal":{"title":"Spam","description":"Indicates whether the item is marked as spam","schema":"<<already seen>>","ngModelOptions":{},"key":["spam"],"type":"checkbox"}},{"msg":"schemaForm.form[5]","newVal":{"title":"Google 2FA Token","description":"Google 2FA Token","schema":"<<already seen>>","ngModelOptions":{},"key":["two_factor_token"],"type":"text"}},{"msg":"schemaForm.form[6]","newVal":{"title":"E-mail Address","description":"E-mail Address","schema":"<<already seen>>","ngModelOptions":{},"key":["email"],"type":"text"}}]]

footnote - Tests weren't working locally; I did verify the fix in-place.

@israelshirk
Copy link
Contributor Author

Also, ASF has made my life wonderful.

davidlgj added a commit that referenced this pull request Aug 11, 2015
Moves default form outside of sfSchema's $watch so compiling works
@davidlgj davidlgj merged commit bc1126a into json-schema-form:development Aug 11, 2015
@davidlgj
Copy link
Contributor

@israelshirk Awesome! Thank you very much. Nice explanation and the test is just sugar on the top!

catlove

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

Successfully merging this pull request may close these issues.

2 participants