Slate: Schema normalization rules no longer seem to have a limit to prevent infinite loops

Created on 23 Oct 2018  Â·  8Comments  Â·  Source: ianstormtaylor/slate

This feature in previous versions of Slate was really helpful, but in 0.42.x it doesn't seem to be there; at least I'm not seeing it.

Error: A schema rule could not be normalized after sufficient iterations. This is usually due to arule.normalizeorplugin.normalizeNodefunction of a schema being incorrectly written, causing an infinite loop.

I've been waiting to hit the maximum callstack while debugging some normalization rules and it made me realize how much I appreciated that failsafe. Was this intentionally removed, or did I break something?

bug ♥ help

All 8 comments

Schema iteration count doesn't increment in most cases when dealing with a schema rule that causes infinite loops. I have found that it incremented for some rules, but in the cases that are actually infinite loops it doesn't seem to count up.

https://github.com/ianstormtaylor/slate/blob/master/packages/slate/src/controllers/change.js#L235

Brief video of debugger at the statement that checks for the limit

@ianstormtaylor can you point towards where this iterating was handled prior to the introduction of the change controller in 0.42.x ? I don't see any obvious problem within the current function. I rolled back to an old commit to try just searching everything for the function name, normalizeNodeByPath but I guess it was named differently in the past too.

If you search for iterate( that should find it I think.

Great, I found it! Thanks Ian!

@Slapbox I'm pretty sure it still works, it's just too large of a number. If we change this line...

https://github.com/ianstormtaylor/slate/blob/46df9f6c52a52a62ed17cfad13e6417f9a39030d/packages/slate/src/controllers/editor.js#L564

...to 100 instead of 1000 that should surface it earlier, and be good enough for now. Ideally there would be some sort of way to know what the true max is, so we didn't have to go so big.

Whoops, I guess I forgot to update. I took a look for a while and couldn't find anything wrong. I hadn't come to that conclusion, but I think you're right. Hitting the maximum call stack before you hit the 1000 recursions is definitely possible with complex rules and a mistake that cause a loop.

I think your point is good though that 1000 is too high to be useful so let's keep this open til we fix it.

Just decreased to 100 so hopefully that helps.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

bengotow picture bengotow  Â·  3Comments

chrpeter picture chrpeter  Â·  3Comments

bunterWolf picture bunterWolf  Â·  3Comments

ianstormtaylor picture ianstormtaylor  Â·  3Comments

ianstormtaylor picture ianstormtaylor  Â·  3Comments