Client side exception when hiding an element and replacing Grid contents

I encountered a peculiar problem that prevents me from hiding an element. Example code that demonstrates the problem:

Label label = new Label("Some text");
Layout hideable = new HorizontalLayout(label);
Grid grid = new Grid(buildAContainerWithData());
VerticalLayout wrapper = new VerticalLayout(hideable, grid);
Button button = new Button("Hide that label!", e -> {
    hideable.setVisible(!hideable.isVisible());
    grid.setContainerDataSource(buildAContainerWithData());
});

So what I’m doing is toggling the visibility of a Layout element and replacing the container of a Grid in one go when a button is clicked. When the button is clicked, the Layout component is hidden alright, but the grid gets filled with empty rows. When running the page in the debug mode, an error message is shown; see the attached screenshot. The same thing happens if instead of toggling visibility I add/remove the layout to/from the wrapper layout.

The combination of toggling the visibility and replacing the container seems to be the key, since if I only do one of them it works fine. I tried only toggling the visibility of the label contained in the layout, but then the empty layout still takes the same amount of space as before, and that’s no good; I need it to disappear.

I’m guessing this is a bug? If not, what am I doing wrong here? I’m running Vaadin 7.6.2.
23014.png

I managed to solve the problem by rearranging my layouts. Apparently the problem only occurs when the grid and the component that is hidden are siblings. Or, if you hide a layout that is a sibling of the layout that holds the grid. The component/layout that is hidden also needs to be before the grid for this to happen; it works just fine if the grid is first.