CanJS4.2 upgrade issues (again ..)


Woes with Template aquisition now resolved with help from Justin, many thanks.

Another couple of issues where behaviour changes between 2.x and 4.2 :slight_smile:

import stache from ‘can-stache’
import Map from ‘can–map’ (legacy code …)
import Control from can-control

First issue

creating a simple controller barfs if the DOM mount point is not available, eg

const Test = Control.extend({
‘a click’: function($el, ev) {
new Test(‘div.entry’);

if div.entry does not exist you are TOAST and it’s not just the new Test() you need to guard it’s the whole thing. AFAICR this did not happen in 2.x ?? But it is easy to work around …

Second issue

With a working template + controllers etc add a custom tag to the stache template eg but without any supporting code

TOAST again … jQuery Deferred exception node.attibutes is undefined …
this definitely did not happen in 2.x

Surely the custom tag should just render as an empty placeholder ??

Taking a wild guess from renderer code signature in the docs ( perhaps the nodelist should be created as empty if undefined ???
Can I do anything to avoid this ??



This doesn’t barf …

What error are you seeing?

Btw, you need quotes around:

import Control from "can-control"


Regarding your first issue … This was by design, but we can probably produce a better warning. Creating a control on null almost certainly was a bug, but failing silently didn’t seem be a good idea.

On the second issue, can you give more details about what you are trying? What do you mean by supporting code?

Do you mean you created a custom element like <foo-bar>, but didn’t define it and inserted it into the page via can-stache?

The example app might look like:

document.appendChild( can.stache("<foo-bar>")({}) )




Second issue

I have a template that includes a custom tag but nothing else to define it, no Component.extend, nothing

Template will not render

Remove the custom tag from the template and all is ok

I can dynamically add the component to the DOM as per your example with no problem but that’s not what I need

The template knows at compile time what component to put where … I could do this ok in 2.x



I create a template with a custom tag that is not defined, the template renders:,js,output

var result = can.stache("start - <custom-el></custom-el> end ")()


What error are you seeing?



Travelling today I’ll get back to you ASAP