Issues with itemTemplate/itemArray after upgrading to goJS 2.2

Hello,

I have some issues with our existing code after upgrading to goJS 2.2.2.
Are there any breaking changes to be considered?

goJS 2.1.56:

goJS 2.2.2:

Basically this is a spot panel, to which I add a chartPanel (the line which is drawn corrctly), and then I set the itemTemplate and itemArray on the spot panel, which will display the numbers/durations:

const panel = new go.Panel(go.Panel.Spot);
const chartPanel = new go.Panel(go.Panel.Horizontal);
...
panel.add(chartPanel);
const numberPanel = this.createDurationTextPanel();
panel.itemArray = segments;
panel.itemTemplate = numberPanel;

Any idea why this stopped working?

There wasn’t supposed to be a breaking change.
Does your template use alignmentFocusName Panel | GoJS API ?

Not alignmentFocusName but alignment.
Here is the function which creates the itemTemplate:

private createDurationTextPanel() {
        const textPanel = new go.Panel();
        textPanel.bind(
            new go.Binding("visible", "", (segment: LeadTimeChartSegment) => segment.durationInSec !== undefined)
        );
        textPanel.bind(
            new go.Binding("alignment", "", (panel: go.Panel) => {
                const segment = panel.data as LeadTimeChartSegment;
                return new go.Spot(
                    0,
                    1,
                    segment.startX + segment.width / 2,
                    this.getYPosition(segment) - this.BOTTOM_Y - this.TEXT_OFFSET
                );
            }).ofObject()
        );
        const textBlock = new go.TextBlock();
        textBlock.bind(new go.Binding("text", "", (segment: LeadTimeChartSegment) => this.getDurationText(segment)));
        textBlock.font = this.LABEL_FONT;
        textPanel.add(textBlock);
        return textPanel;
    }

Let me know if there is anything I can try out.

That still isn’t enough code for us to try to reproduce the problem. Could you please give us the whole node template, its supporting functions, and some data to demonstrate the problem?

Hello walter,
it’s quite difficult to extract the code into a reproducible example.
But I just saw that there is a log in the console which says:

No item template Panel found for category "" on Panel(Spot)#11014
go-debug.js:17   Using default item template.

And then I figured out that this doesn’t work:

panel.itemArray = segments;
panel.itemTemplate = numberPanel;

But this works:

panel.itemTemplate = numberPanel;
panel.itemArray = segments;

Hope that is enough information for you?

By “works”, are you saying that by providing the Array of data after setting the Panel.itemTemplate, everything is working again as you expected?

Yes exactly.
So for me this is fine now as the old functionality is restored but I assume it shouldn’t work only this way.

Well, it’s normally the case that one assigns the template and then one provides the data, perhaps repeatedly. But it ought to work, inefficiently, assigning the template after the data, also perhaps repeatedly.

We’ll look into it, at a lower priority. Thanks for reporting the problem and finding yourself a work-around.

OK, that was due to an improper optimization introduced in 2.0. I’ve removed that optimization when Panel.rebuildItemElements is called, i.e. whenever item templates change. That will be in the next build, 2.2.3.

Thanks for reporting the problem. I’m sorry it caused you some annoyance.