Blaze rendered vs onRendered

I notice that .rendered= works only in some cases, and onRendered() only works in some other cases. Can someone explain the difference in these two parts of Blaze?

1 Like

I take some time to change from rendered to onRendered and not really notice the difference, but that allows you to now use rendered in several places.

I tried that, but find that changing either one to the other does not work in my case. The must be a small subtle difference in how/when they are called.

You could simle look at the source. As you can see there is a link: blaze/template.js, line 77

OK, so if I understand correctly from the source, rendered is now an array of callbacks. OnRendered simply stuffs the current callback into the rendered array. This suggests that if you mix them, you may get some odd results (as I was seeing)

What do you mean it only works in some cases? Can you make a repro where either rendered or onRendered are not called?

As for the order, rendered fires first then the functions added via onRendered.

btw, here’s an issue I found with the rendered event: https://github.com/meteor/meteor/issues/4410

From what I have seen, if .rendered = function() {} is called after onRendered(function(){}) is called, it will wipe out the onRendered calls you have previously set. This is because .rendered is now defined as an array and onRendered pushes its parameter (the function) onto the array. Setting rendered = function() {} will replace that array by the function you are setting it to, losing what was set in the array.

I saw this issue, but it was resolved by always using onRendered(). The best option going forward is to always use onRendered()

I am getting inconsistent behavior with this. I was trying the Meteor + jQuery-UI sortable list from Differential blog.

The code works fine as is and I am able to sort the list. However when I replace ‘rendered’ with ‘onRendered’, the jQuery sorting does not work, instead when I drag the mouse it simply highlights the items. Trying to debug but not getting anywhere so far. I am still s noob in debugging through the framework. Any help is appreciated.

Do you still have this issue?