What is the scope of re-rendering?

I’m curious of that scope of re-rendering html, when the reactive data source is changed in reactive computation. Is it up to certain template ? or whole body section ?

When a reactive change occurs, only a few HTML nodes are usually re-rendered (not the full template).

@Steve So do you mean that the scope is different depending on case-by-case situations? Is there any way to control the scope ?

@Steve or Is there any way to check which template is re-rendered?
I attempted to check which template is re-rendered whenever reactive data source is changed, by using Template.myTemplate.onRendered, but it was called only for the first time rendered.

In Meteor, there is no such concept as “template re-rendering”. The DOM is updated localy. As you noticed, onRendered is called when the template is first rendered.

What do you want to achieve?

Oh only DOM nodes update. That make sense. Thank you @Steve !!
I think I misunderstood the process until now.

And also, I wanted to check two things.

Firstly, I wanted to check which template is updated since the reactive data source is changed. But, I understood now, it doesn’t make sense.

Secondly, I wanted to see and check which items are re-rendered, since a user changes an item to another such as normal HTML radio button.

In the docs, under template.data:

This property provides access to the data context at the top level of the template. It is updated each time the template is re-rendered.

If there is no such concept as “template re-rendering”, how should we understand this? When exactly is template.data updated?

Thanks in advance.

when data context change
but that does not mean that whole template instance need to update. Or that anything need to update.
Only that part is re-computed which use reactive resource. And result of this re-computation very often end up as changing DOM.

I understand that sometimes nothing needs to be updated. But when some updates are needed, could you please clarify on what kind of changes would cause the “whole template” to update, and what kind of changes not? If a part of the template that uses reactive sources is updated, isn’t the whole template that contains this part considered updated (or re-rendered)?

No1 is stopping you to try.
There is onRendered function.
But I am not sure if it is ever run twice. For me it is similar as onCreated with 1 difference : onCreated is called before DOM part is rendered. And in onRendered you can count on DOM being rendered.

So from my point of view Template is never re-rendered. If you need something like that, just put child template in {{#if shouldReRender}} {{>templateChild1}}{{/if} and it will be created when shouldReRender is true and destroyed if it is false. So by changing simple helper result you can re-render the templateChild1. but it is not re-rendered. It is re-created.

1 Like

This is also how I understand it.

But then what does the docs on template.data mean? It says it’s updated each time the template is re-rendered. If the template is never re-rendered, does it mean template.data never changes in value?

I dont know which docs you are reading, but the 1 I read say that data context is changed, not template re-rendered.

http://docs.meteor.com/#/full/template_data

Hmm, well actually it does say that in the docs.

EDIT: Reading between the lines (which is sometimes necessary) I think what it means is that a template can be rendered (or re-rendered) as a new template instance. Each template instance can have its own data context.

This makes sense, but I still don’t understand the mechanism.

template.data is a property on a template instance, right? If a new instance is created, why is the data property of the old instance updated? Or are we suddenly (magically) accessing a new instance with the old reference? That would be confusing though.

I don’t think that’s what the docs are meaning (based on observation). I think we should go with what we know happens and try to understand what the docs maybe should say, rather than accept the docs at face value and try to understand what must therefore follow.

  • We know that a template instance gets its own data context.
  • We know that a template instance doesn’t magically get access to its parent’s context.

So, perhaps the docs should say

This property provides access to the data context at the top level of the template instance. It is set each time the template is rendered as a new instance. Access is read-only and non-reactive.

1 Like

Thanks, this makes perfect sense.

So this means, for each template instance instance, instance.data never changes, right?

Well, I’ve never seen it change. As the docs say it’s read-only and non-reactive. At the end of the day it’s an object within a closure and with enough diligence it could be hacked … but that would be crazy :wink:

1 Like