Skip to content
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

didInsertElement hook gets called twice when inserting only one element in the view #1400

Closed
arasbm opened this issue Sep 23, 2012 · 6 comments
Labels
Milestone

Comments

@arasbm
Copy link

arasbm commented Sep 23, 2012

Please take a look at this jsFiddle: http://jsfiddle.net/arasbm/zpuSE/

I add one item into the view content:

App.items.set('content',[
    Em.Object.create({title:"The Element", id:"item-one"})
  ])

I expect didInsertElement to be called once so I can manipulate the DOM element that will be inserted by Ember for this item. I call this code to verify this behaviour:

  didInsertElement: () ->
    console.log "**didInsertElement** ", this.get('element')
    elementId = this.get('elementId')
    console.log "element in DOM: ", $("#"+elementId)
    console.log "body parent: ", $("#"+elementId).parents("body")

and this is the output in the console:

**didInsertElement**  
<div id=​"ember174" class=​"ember-view">​…​</div>​
element in DOM:  [<div id=​"ember174" class=​"ember-view">​…​</div>​]
body parent:  [<body class=​"ember-application">​…​</body>​]
**didInsertElement**  
<div id=​"ember188" class=​"ember-view">​…​</div>​
element in DOM:  []
body parent:  []

However, as you can see in the console didInsertElement gets called twice and Ember attempts to insert two elements with two different ID's into the DOM.

@ppcano
Copy link
Contributor

ppcano commented Sep 23, 2012

I have also experienced the similar case with a ContainerView (v 0.9.8.1), I had pending to report it and investigate further this issue, meanwhile i assign a view property as workaround.

@madchicken
Copy link

This problem is still present in master.

@esad
Copy link

esad commented Nov 5, 2012

+1

@wagenet
Copy link
Member

wagenet commented Dec 19, 2012

I updated the fiddle to master and can no longer reproduce the error: http://jsfiddle.net/zpuSE/2/

@wagenet wagenet closed this as completed Dec 19, 2012
@robertjpayne
Copy link

This is once again failing in 1.0-pre4 ( the latest download from ember.js website ). Can we ensure a fix gets in before 1.0 is finalised? The workarounds are not friendly to avoid doing work twice in didInsertElement

@wagenet wagenet reopened this Feb 11, 2013
@wagenet
Copy link
Member

wagenet commented Feb 12, 2013

@robertjpayne, this fiddle with the very latest master works fine: http://jsfiddle.net/zpuSE/3/. If you're still having issues, please provide us a failing fiddle.

@wagenet wagenet closed this as completed Feb 12, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants