Преглед изворни кода

Fix regression that broke PreserveOnRefresh functionality with Navigator (#11615)

* Fix regression that broke PreserveOnRefresh functionality with Navigator

Fixes https://github.com/vaadin/framework/issues/11614

Old patch https://github.com/vaadin/framework/issues/11416 calls navigateTo allways when Navigator is present, which is wrong, since it is needed only when navigation state has truly changed.

* Add test to the fix
tags/8.9.0.alpha1
Tatu Lund пре 5 година
родитељ
комит
7a453dce17

+ 13
- 2
server/src/main/java/com/vaadin/ui/UI.java Прегледај датотеку

private LoadingIndicatorConfiguration loadingIndicatorConfiguration = new LoadingIndicatorConfigurationImpl( private LoadingIndicatorConfiguration loadingIndicatorConfiguration = new LoadingIndicatorConfigurationImpl(
this); this);


/**
* Holder for old navigation state, needed in doRefresh in order not to call
* navigateTo too often
*/
private String oldNavigationState;

/** /**
* Scroll Y position. * Scroll Y position.
*/ */
page.updateBrowserWindowSize(newWidth, newHeight, true); page.updateBrowserWindowSize(newWidth, newHeight, true);


// Navigate if there is navigator, this is needed in case of // Navigate if there is navigator, this is needed in case of
// PushStateNavigation
// PushStateNavigation. Call navigateTo only if state have
// truly changed
Navigator navigator = getNavigator(); Navigator navigator = getNavigator();
if (navigator != null) { if (navigator != null) {
navigator.navigateTo(navigator.getState());
if (oldNavigationState == null) oldNavigationState = getNavigator().getState();
if (!navigator.getState().equals(oldNavigationState)) {
navigator.navigateTo(navigator.getState());
oldNavigationState = navigator.getState();
}
} }
} }



+ 29
- 0
uitest/src/main/java/com/vaadin/tests/components/ui/RefreshUI.java Прегледај датотеку

package com.vaadin.tests.components.ui;

import com.vaadin.annotations.PreserveOnRefresh;
import com.vaadin.navigator.Navigator;
import com.vaadin.navigator.View;
import com.vaadin.server.VaadinRequest;
import com.vaadin.tests.components.AbstractTestUI;
import com.vaadin.ui.Label;
import com.vaadin.ui.VerticalLayout;

@PreserveOnRefresh
public class RefreshUI extends AbstractTestUI {

@Override
protected void setup(VaadinRequest request) {
final Navigator navigator = new Navigator(this, this);
navigator.addView("", MyView.class);
setNavigator(navigator);
}

public static class MyView extends VerticalLayout implements View {
private static int instanceNumber = 0;

public MyView() {
instanceNumber++;
addComponent(new Label("This is instance no " + instanceNumber));
}
}
}

+ 25
- 0
uitest/src/test/java/com/vaadin/tests/components/ui/RefreshUITest.java Прегледај датотеку

package com.vaadin.tests.components.ui;

import org.junit.Test;

import com.vaadin.testbench.elements.LabelElement;
import com.vaadin.tests.tb3.MultiBrowserTest;

import static org.junit.Assert.assertEquals;

public class RefreshUITest extends MultiBrowserTest {

@Test
public void testUIRefresh_viewNotRecreated() {
openTestURL();
assertEquals("The Label content is not matching",
"This is instance no 1",
$(LabelElement.class).first().getText());

// Reload the page; UI.refresh should be invoked
openTestURL();
assertEquals("The Label content is not matching",
"This is instance no 1",
$(LabelElement.class).first().getText());
}
}

Loading…
Откажи
Сачувај