googlearchive / TemplateBinding

TemplateBinding Prolyfill
290 stars 61 forks source link

A template won't stamp out as expected if it's not in document and Platform.performMicrotaskCheckpoint() is called #126

Closed sorvell closed 10 years ago

sorvell commented 11 years ago

See: http://jsbin.com/ijijuv/2/edit

Specifically where t is a template with the bind attribute set:

t.model = {hello: 'Hi!'};
Platform.performMicrotaskCheckpoint();
document.body.appendChild(t);
Platform.performMicrotaskCheckpoint();

Calling Platform.performMicrotaskCheckpoint() when the template is not in the document causes it to be in a broken state, it never stamps out.

rafaelw commented 11 years ago

So after talking with Steve about this the issues are:

createBinding() will produce an "instance" fragment whose ownerDocument doesn't have a defaultView. that means that you have to adopt it into a document with a defaultView before end of microtask, otherwise any sub-templates will self-destruct.

So the root of the problem is the MDV polyfill has no way to find out when template nodes get adopted into new documents. If they did, they would simply be 'paused' while in a document with no defaultView and 'active' while in a document with a defaultView.

rafaelw commented 10 years ago

Template production now works regardless of defaultView. Please verify this is now fixed.