-
Notifications
You must be signed in to change notification settings - Fork 249
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
[BUG?] Paths not being tracked properly #487
Comments
I tried reproducing with this simple example: var scene = FamousEngine.createScene()
var logo = scene.addChild()
var node2 = scene.addChild()
scene.removeChild(logo)
node2.addChild(logo)
new Position(logo)
node2.removeChild(logo)
scene.addChild(logo) but that works. In my case, I'm removing and adding hundreds of nodes at a time. |
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 if (viewNode === cardFamousNode.getParent()) {
console.log('viewNode is already parent...')
debugger
}
viewNode.addChild(cardFamousNode) The |
Sorry, this is really hard to debug without the specific code. Not much we can do here. |
Here is the situation in which this bug occurs for me: class MyNode extends Node
constructor: ()->
super
@.nextBtn = new NextBtnNode() #this class also extends Node
@.addChild( @.nextBtn )
@.moduleNodes = []
#remove all of the current module nodes and insert the new modules
setModules: (modules)->
@.modules = modules
for node in @.moduleNodes
@.removeChild node
for module in @.modules
newNode = new ModuleNode(module)
@.moduleNodes.push newNode
@.addChild newNode
myNode = new MyNode()
myNode.setModules( [1, 2, 3] )
myNode.setModules( [4, 5, 6] ) #ERROR item already exists at path 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. |
@artichox Is that code who's repo you don't mind sharing? |
I have this problem in another project now. My case is simple. I've got some code like this: import Node from 'react-famous/Node'
import {SplashScreen, SignUpScreen, LoginScreen} from './screens'
// This must contain React components that extend from react-famous/Node
let loginlayouts = {
SplashScreen, SignUpScreen, LoginScreen
}
class Login extends Node {
render() {
return (
<Node _famousParent = {this} id="rootNode">
{React.createElement(this.data.loginLayout)}
</Node>
)
}
getMeteorData() {
console.log('login root data changed.')
return {
loginLayout: loginlayouts[Session.get('loginlayout')]
}
}
}
reactMixin(Login.prototype, ReactMeteorData)
export default Login When the value of import Node from 'react-famous/Node'
import Node from 'react-famous/dom-rederables/DOMElement'
export default
class SplashScreen extends Node {
render() {
return (
<Node _famousParent={this} id="SplashRoot">
<DOMElement>
<h1>...</h1>
</DOMElement>
<Node>
...
</Node>
</Node>
)
}
} When the value of So, in my case, all that is happening (when the value of Maybe the index in one of the loops in the path logic is off by one or something? |
@artichox I'm gonna look into fixing this today. |
@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. |
@trusktr this should be one of the highest priorities to fix |
@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. |
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? |
@artichox Maybe we can override a method in the dom renderer to not recycle anything, for now? |
…are re-used @see artichox's comment 4-Sep at Famous#487
When we try to add a Node to a parent Node a second time, we expect an error like this, as in
, we expect an error like this:
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:The "item" in question happens to be a Transform who's path is being (re)added
TransformSystem#registerTransformAtPath
, based on the stack trace: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.The text was updated successfully, but these errors were encountered: