Why is VaadinSession preventing getElement.appendChild() from working dynamically

please guys I need quick assistance here:
I have a dynamically created and populated table that works perfectly until I implement Login Authentication.
So once a user is logged in, the table still gets created and populated in the background but does show on the UI. If no user is logged in, then the same process creating and populating it runs and it this time appears on UI.
I suspect the vaadinSession.getCurrent.setAtribute(User.class,user);
Why?
because it works well on vaadinSession.getCurrent.setAtribute(User.class,null);

Hard to tell without seeing code, but using getElement().appendChild() sounds already like you are doing something unorthodox.

It’s a vague question. If your login recreates the session (which is not a bad idea, as protection against session fixation attacks) and a component is created for the original session, you can’t reuse the component. A component can only belong to one session, and more specifically, one UI.

Generally speaking, avoid creating components in background threads, just use threads for data

thanks for the response @vital-koala , particularly realising the question is vague. So, I meant: So once a user is logged in, the table still gets created and populated in the background but does NOT show on the UI. But without the user logging in (that’s just merely using the app without logging in like using stack overflow even without having an account), the table gets created, populated and shows on UI.

You should create a minimal reproducible example.

ok give me just a moment

@Tag(“createTable”)
@Route(“”)
public class CreateTable extends litTemplate{
private final UsersRepository usersRepository;
Element makeDynamicTabelButton = new Element(“button”);
makeDynamicTabelButton.addClickListener(click → {
Element table = new Element(“table”);
table.setAttribute(“slot”, “tableSlot”);
Style tableStyle = table.getStyle();
tableStyle.set(“border-color”, “black”);
Element tr = new Element(“tr”);
Element td = new Element(“td”);
td.setText(“example”);

        tr.appendChild(td);
        table.appendChild(tr);
        getElement().appendChild(table);

    });

    public void userLogin(){

        LoginForm loginForm = new LoginForm();
        loginForm.addLoginListener(loginEvent -> {
            String username = loginEvent.getUsername();
            String password = loginEvent.getPassword();

            try {
                authenticate(username, password);
            } catch (UserAuthenticationService.AuthException e) {
                Notification.show("wrong credentials");
            }
        });
    }

    public void authenticate(String username,  String password) throws UserAuthenticationService.AuthException {
        User user = usersRepository.getByUsername(username);  if(user!=null&&true){VaadinSession.getCurrent().setAttribute(Users.class,user);
            //return them to null, so the check doesn't pass even when wrong credential comes from UI
            passwordHash = null;
            passwordSalt = null;
        }else {
            throw new UserAuthenticationService.AuthException();
        }
    }
}

I don’t think writing the example in a Discord message is a particularly good way to go about it. Write it in your IDE and copy-paste it.

I can see two syntax errors in that example already

ok great…let me speed it up in IDE

@vital-koala i just sent in the edited code

That’s still not correct syntax

please what part, Olli?

At least @Tag("createTable") is not a valid tag. public class CreateTable extends litTemplate{ is not correct, either, and your IDE should tell you why.

authenticationService.authenticate(username, password); authenticationService is not defined

etc.

i’ve taken that part out, thanks

usersRepository is not defined

checkPassword is not defined