Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a system property -Dvaadin.hotswap.fullPageReload=true #20844

Open
sveinnetnordic opened this issue Jan 15, 2025 · 4 comments
Open

Add a system property -Dvaadin.hotswap.fullPageReload=true #20844

sveinnetnordic opened this issue Jan 15, 2025 · 4 comments

Comments

@sveinnetnordic
Copy link

Describe your motivation

When using HotSwapAgent 2.0.1 the new page merge/update has led to multiple problems/bugs. It is fine for some tasks when changing margins, padding, color, etc - and for Vaadin Copilot.

HotSwapAgent 1.4.2 will do a full refresh. It is always working, and every part of the page is run. It is safe and acts like a real situation when a user loads the page. The page reload also "flash" the page, make me sure it is fresh loaded. I use to add helpers, so I don't need to click on every reload. They will not always work in the new mode. E.g. element.executeJs("setTimeout(()=>{$0.click()},100)", btn.element)

hotswap.fullPageReload default to false

Today I have a duplicate of my SDK, one with HotSwapAgent 2.0.1, the other with HotSwapAgent 1.4.2. Not sure if 1.4.2 will work on newer JDK.

Describe the solution you'd like

With a system property -Dvaadin.hotswap.fullPageReload=true it's easy to switch mode

Also doing the switch in Vaadin Copilot in runtime would be nice, but not necessary

@Artur-
Copy link
Member

Artur- commented Jan 15, 2025

A workaround for this should be to add a custom VaadinHotswapper implementation that just returns true for all changes (a class + a file META-INF/services/com.vaadin.flow.hotswap.VaadinHotswapper containing the name of the class)

@sveinnetnordic
Copy link
Author

class CustomVaadinHotswapper : VaadinHotswapper {
    companion object {
        var fullPageReload = true
    }

    override fun onClassLoadEvent(vaadinService: VaadinService, classes: Set<Class<*>>, redefined: Boolean): Boolean {
        return if (fullPageReload) true else super.onClassLoadEvent(vaadinService, classes, redefined)
    }
}
if (!VaadinService.getCurrent().deploymentConfiguration.isProductionMode) {
            extraInfoBottomLeft.add(Checkbox(CustomVaadinHotswapper.fullPageReload) { CustomVaadinHotswapper.fullPageReload = it.value }.style("--vaadin-checkbox-size: 0.7rem"))
}

This seems to work! Can turn on/off full page reload at runtime

Hope this will be added by Vaadin, with the toggle on the Vaadin Copilot button i browser

@mcollovati
Copy link
Collaborator

A minor drawback of this approach is that the page will be reloaded even if the class change does not affect the UI directly.

@sveinnetnordic
Copy link
Author

Found that returning true made pages reload twice (not on reload). Returning redefined seems to work

public class CustomVaadinHotswapper implements VaadinHotswapper {
    public static boolean fullPageReload = true;

    @Override
    public boolean onClassLoadEvent(VaadinService vaadinService, Set<Class<?>> classes, boolean redefined) {
        return fullPageReload ? redefined : VaadinHotswapper.super.onClassLoadEvent(vaadinService, classes, redefined);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants