@PreserveOnRefresh drops stylesheet on refresh

Here is the definition of a particular page on my web app:

@Route(value = "game", layout = MainLayout.class)
@PageTitle("Page Title")
@StyleSheet("./my-styles/game.css")
@JavaScript("./js/game.js")
@Log4j2
@PreserveOnRefresh
public class GamePage extends VerticalLayout {

And here is MainLayour:

@Theme(value = Lumo.class, variant = Lumo.DARK)
@StyleSheet("https://fonts.googleapis.com/css2?family=Fredoka+One&family=Rubik:wght@300&family=Roboto")
@StyleSheet("./my-styles/game.css")
@JavaScript("https://kit.fontawesome.com/829bed66ec.js")
@Push
public class MainLayout extends Div implements RouterLayout, PageConfigurator {

I notice that when I navigate to this page from the signin page:

@Route(value = "", layout = MainLayout.class)
@PageTitle("Page Title")
@Log4j2
public class SignInPage extends VerticalLayout {

the css (game.css) loads fine. But when I’m on the game page and hit refresh in my browser, that css is dropped. Removing @PreserveOnRefresh fixes this, but it seems to be a nice feature to help the UI stay consistent over refreshes.

Any tips on how I can fix this?

@PreserveOnRefresh does not work for me. I detect the page myself. if loaded, I just setvisible true.
I use JavaScript to prevent page refresh or close. ( Message will pop up)

If u r interested this JS, u may refer this link.
https://vaadin.com/forum/thread/17800495/vaadin-14-javascript

Hope it help…

Hi Elle,
This is a bit late reply. I bumped myself on this issue and going through the documentation https://vaadin.com/docs/v14/flow/advanced/tutorial-preserving-state-on-refresh.html it states that in case when a router layout is used and you want to preserve also its state you can use PreserveOnRefresh on the router layout class. I tried it myself and it works.