-
Notifications
You must be signed in to change notification settings - Fork 83
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
Infinite recursion #86
Comments
Hmm, I wonder why this wasn't fixed by #80... mind submitting a failing test (that preferably doesn't involve |
I should have mentioned the version I'm running: 1.1.2 from July 16th, which seems to include the fixes from #80. Maybe it only fails for |
OK, I don't have a test but pasting this in a JS console seems to recreate the error: var father = {name: 'bob'}
var child = {name: 'danny', father: father}
father.children = [child]
var family = new Backbone.NestedModel({lastName: 'Smith', head: father})
family.set({'head.name': 'Bobby'})
family.set({'head.name': 'Robert'})
family.set({'head.name': 'Rob'})
// Now try the same value again:
family.set({'head.name': 'Rob'})
// ==> RangeError: Maximum call stack size exceeded |
Any updates on this going to happen soon? |
@vkovalskiy unfortunately, both I and @afeld are pretty busy. I'll try to get to this in the following week or two. |
@gkatsev thanks for reply. However, I believe that the solution would be to simply forbid recursive models because you'll never know when it's ok to stop traversing. I believe the best that can be done here is informing the user that model has recursive attrbutes and At least, there would be no browser doom state J |
I agree with @vkovalskiy. Throwing with a nice error message is better than trying to guess the best way to handle it. |
That may very well be the best way to handle it 😁 |
I had a bug in my code where, by accident, a reference to the
window
object was added as an attribute to a NestedModel. That caused an infinite recursion in_setAttr
(and subsequent crash) becausewindow
has a few self-referencing properties likewindow.window
,window.self
,window._top
,window.parent
, etc.Even though that was my fault, it revealed that (I think) this could happen with legitimately created recursions (like
order.orderLines[0].order
orpet.owner.pets[0]
, etc.)Maybe NestedModel could try to keep track of the walked objects and avoid the infinite loop.
The text was updated successfully, but these errors were encountered: