Repository navigation
[BUG?] Paths not being tracked properly #487
Copy link
Copy link
Open
Description
When we try to add a Node to a parent Node a second time, we expect an error like this, as in
var logo = scene.addChild();
scene.addChild(logo);, we expect an error like this:
Uncaught Error: Node is already mounted at: body/0
However, I've got some complex code that is removing and adding child nodes often, and at some point, when I use Node#addChild to add a Node to a parent Node, I'm getting this error from PathStore instead:
Uncaught Error: item already exists at path: [data-reactid=".0"][data-scene-id="1"]/0/97/0/0/0/0/0/1
The "item" in question happens to be a Transform who's path is being (re)added TransformSystem#registerTransformAtPath, based on the stack trace:
ncaught Error: item already exists at path: [data-reactid=".0"][data-scene-id="1"]/0/97/0/0/0/0/0/1
at PathStore.insert (http://localhost:3000/client/lib/_famous/famous.entry.js?bab126b262ed37f8bcf79944013b074b89476f49:2117:16)
at TransformSystem.registerTransformAtPath (http://localhost:3000/client/lib/_famous/famous.entry.js?bab126b262ed37f8bcf79944013b074b89476f49:240:21)
at Node.mount (http://localhost:3000/client/lib/_famous/famous.entry.js?bab126b262ed37f8bcf79944013b074b89476f49:3503:26)
at Dispatch.mount (http://localhost:3000/client/lib/_famous/famous.entry.js?bab126b262ed37f8bcf79944013b074b89476f49:1644:64)
at Node.mount (http://localhost:3000/client/lib/_famous/famous.entry.js?bab126b262ed37f8bcf79944013b074b89476f49:3512:15)
at Dispatch.mount (http://localhost:3000/client/lib/_famous/famous.entry.js?bab126b262ed37f8bcf79944013b074b89476f49:1644:64)
at Node.mount (http://localhost:3000/client/lib/_famous/famous.entry.js?bab126b262ed37f8bcf79944013b074b89476f49:3512:15)
at Dispatch.mount (http://localhost:3000/client/lib/_famous/famous.entry.js?bab126b262ed37f8bcf79944013b074b89476f49:1644:64)
at Node.mount (http://localhost:3000/client/lib/_famous/famous.entry.js?bab126b262ed37f8bcf79944013b074b89476f49:3512:15)
at Dispatch.mount (http://localhost:3000/client/lib/_famous/famous.entry.js?bab126b262ed37f8bcf79944013b074b89476f49:1644:64)
This leads me to believe that the path system might have a bug because I'm strictly using only Node#addChild/Node#removeChild. At some points between those calls I'm adding and removing Position and Rotation components.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels
Activity
trusktr commentedon Aug 27, 2015
I tried reproducing with this simple example:
but that works. In my case, I'm removing and adding hundreds of nodes at a time.
trusktr commentedon Aug 27, 2015
Alright, so I did an experiment to double check that I'm not accidentally adding nodes to the same parent node (in fact, they shouldn't be on any node at all because I'm calling
removeChildelsewhere first). I've got code like this:The
console.loganddebuggerstatements never fire, and the error happens on the line after the conditional check.michaelobriena commentedon Aug 27, 2015
Sorry, this is really hard to debug without the specific code. Not much we can do here.
artichox commentedon Sep 1, 2015
Here is the situation in which this bug occurs for me:
On the last line, the node's TransformSystem tries to register a new node at the path of the current NextBtn node, which was never removed. If I remove all the nodes including the NextBtn and then add all of the nodes, I don't receive an error. Thus, the path to the NextBtn node needs to update itself to reflect that it has moved from being at index 1 among all the children (for example) to index 0.
trusktr commentedon Sep 1, 2015
@artichox Is that code who's repo you don't mind sharing?
trusktr commentedon Sep 1, 2015
I have this problem in another project now. My case is simple. I've got some code like this:
When the value of
this.data.loginLayoutchanges, theLogincomponent is re-rendered (in React's sense of rendering). TheNodeinstance in the return function creates a Famous Node behind the scenes, and that instance remains instantiated across React renders. What changes is the value of{React.createElement(this.data.loginLayout)}. The value of that is a component that looks like this:When the value of
{React.createElement(this.data.loginLayout)}in the Login component changes, that causes the (React) component to be unmounted, which behind the scene unmounts the Famous Node that it represents. Then, the new value of{React.createElement(this.data.loginLayout)}is another React component that, when mounted (in React's sense of mounting) goes a head and creates a new Famous Node and adds that withaddChildto the Login component's Famous Node.So, in my case, all that is happening (when the value of
this.data.loginLayoutchanges) is a single node is removed (and all it's sub-nodes along with it) and a single node is added (and all it's sub-nodes along with it), and that's when I get the error.Maybe the index in one of the loops in the path logic is off by one or something?
trusktr commentedon Sep 1, 2015
@artichox I'm gonna look into fixing this today.
artichox commentedon Sep 2, 2015
Great thank you @trusktr
Here is the repo
client/modules/base/ModulesView.coffee is the node class. setModules is called in client/Scene.coffee
Also, I was mistaken: the bug still persists if I remove all of the child nodes including the NextBtn
trusktr commentedon Sep 2, 2015
@artichox I didn't get to solve this today. I found a temporary workaround to the problem in my case: I'm swapping views by positioning them off screen or on screen instead of adding/removing nodes. It's lame, but that'll do for now.
talves commentedon Sep 2, 2015
@trusktr this should be one of the highest priorities to fix
trusktr commentedon Sep 2, 2015
@talves @michaelobriena @alexanderGugel As mentioned on Slack in #engine, the current workaround is to manually remove child nodes before removing parent nodes, in post-order. I'm gonna test that out.
artichox commentedon Sep 3, 2015
Manually removing all of the child nodes in the tree does prevent path collisions, but unfortunately the recycling of DOM elements will sometimes result in some of the node's content being retained. So when I make a new node, it occasionally will have the content of one of my previous nodes in its background. Pretty funky looking. Preemptively setting content to "" in the node constructor doesn't fix the issue. Anyone found a workaround for this?
trusktr commentedon Sep 8, 2015
@artichox Maybe we can override a method in the dom renderer to not recycle anything, for now?
fix issue with cached elements having lingering style data when they …