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

Component create location do not change after hotswapping for static components #20928

Open
abdullahtellioglu opened this issue Jan 28, 2025 · 5 comments

Comments

@abdullahtellioglu
Copy link
Collaborator

Description of the bug

When you have a component defined as static, changing the statement line does not have any effect on ComponentTracker.Location

Expected behavior

Component create location should return the line of the new position.

Minimal reproducible example

Create a sample view with the following code

public class HelloWorldView extends HorizontalLayout {

    private static final TextField myTextField = new TextField();

    public HelloWorldView() {
        if (myTextField.getParent().isPresent()) {
            myTextField.removeFromParent();
            myTextField.getElement().removeFromTree();
        }
        add(myTextField);
        ComponentTracker.Location create = ComponentTracker.findCreate(myTextField);
        System.out.println(create.toString());
    }

}

ComponentTracker returns the correct line at first, then after moving textField definition to the below constructor it still returns the same line

public class HelloWorldView extends HorizontalLayout {

    public HelloWorldView() {
        if (myTextField.getParent().isPresent()) {
            myTextField.removeFromParent();
            myTextField.getElement().removeFromTree();
        }
        add(myTextField);
        ComponentTracker.Location create = ComponentTracker.findCreate(myTextField);
        System.out.println(create.toString());
    }

    private static final TextField myTextField = new TextField();
}

Logs :

2025-01-28T16:45:40.713+03:00  INFO 70526 --- [v-server-output] c.v.b.devserver.DevServerOutputTracker   : [TypeScript] Found 0 errors. Watching for file changes.
Component 'test.vaadin.copilot.flow.views.helloworld.HelloWorldView' at 'HelloWorldView.java' (<clinit> LINE 18)
HOTSWAP AGENT: 16:46:29.377 RELOAD (org.hotswap.agent.config.PluginManager) - Reloading classes [test.vaadin.copilot.flow.views.helloworld.HelloWorldView] (autoHotswap)
Component 'test.vaadin.copilot.flow.views.helloworld.HelloWorldView' at 'HelloWorldView.java' (<clinit> LINE 18)
Component 'test.vaadin.copilot.flow.views.helloworld.HelloWorldView' at 'HelloWorldView.java' (<clinit> LINE 18)
2025-01-28T16:46:30.736+03:00  WARN 70526 --- [nio-8082-exec-9] c.v.f.s.c.UidlRequestHandler             : Invalid security key received from 0:0:0:0:0:0:0:1
2025-01-28T16:46:30.781+03:00  WARN 70526 --- [nio-8082-exec-1] c.v.f.s.c.UidlRequestHandler             : Invalid security key received from 0:0:0:0:0:0:0:1
HOTSWAP AGENT: 16:47:26.746 RELOAD (org.hotswap.agent.config.PluginManager) - Reloading classes [test.vaadin.copilot.flow.views.helloworld.HelloWorldView] (autoHotswap)
Component 'test.vaadin.copilot.flow.views.helloworld.HelloWorldView' at 'HelloWorldView.java' (<clinit> LINE 18)
Component 'test.vaadin.copilot.flow.views.helloworld.HelloWorldView' at 'HelloWorldView.java' (<clinit> LINE 18)

Versions

Hilla: 24.7.0.alpha9
Flow: 24.7.0.alpha8
Vaadin: 24.7.0.alpha6
Copilot: 24.7-SNAPSHOT
Frontend Hotswap: Enabled, using Vite
OS: aarch64 Mac OS X 14.7.1
Java: JetBrains s.r.o. 21.0.5
Browser: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36
Java Hotswap: Java Hotswap is enabled
IDE Plugin: 1.4.6 IntelliJ

@knoobie
Copy link
Contributor

knoobie commented Jan 28, 2025

That happens because static components are not supported. Try to open your application with a second tab / browser / user and you are going to see why 😉

@abdullahtellioglu
Copy link
Collaborator Author

I know that singleton scoped and static components are not supported but the location should be updated when class is reloaded.

Copilot could not find the location where component is created so it creates a false exception

@mshabarov
Copy link
Contributor

Why you need this component to be declared as static, is there any requirement for it in Copilot?

@abdullahtellioglu
Copy link
Collaborator Author

No, there is no requirement. I realized the component location does not change while trying to reproduce a bug. We can close this as singleton/ session scoped beans are not supported, but component location should change in my opinion even though it is not supported.

@mshabarov
Copy link
Contributor

Thanks! I'd keep this in the backlog for future, but would threat this as an enhancement for ComponentTracker.

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

No branches or pull requests

3 participants