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

AppLayout does not provide UI in afterNavigation method #5449

Open
stefanuebe opened this issue Sep 11, 2023 · 7 comments · May be fixed by #5543
Open

AppLayout does not provide UI in afterNavigation method #5449

stefanuebe opened this issue Sep 11, 2023 · 7 comments · May be fixed by #5543
Assignees
Labels
DX Developer experience issue refactor Internal improvement requires new major This would be a breaking change vaadin-app-layout

Comments

@stefanuebe
Copy link
Contributor

stefanuebe commented Sep 11, 2023

Description

The design of the afterNavigation method in the AppLayout is contradictory to the one of the AfterNavigationObserver. While in the method of the ANO interface the UI can be accessed via getUI(), the method of the AppLayout does not yet provide it. This is due to the place where the method is called by the class.

This may lead to confusion for devs, as they might expect the same behavior based on the same method naming and similar documentation.

Expected outcome

The UI should be available when calling getUI inside the AppLayouts afterNavigation.

Possible solutions:

  1. Override getUI in the AppLayout to return UI.getCurrent() as an alternative, if the component has not yet been attached to the UI. Not sure if this could lead to a false UI in any normal case?
  2. Let AppLayout implement the AfterNavigationObserver interface and move the call of afterNavigation there. This could be classified as a breaking change as it might interfere with any manual implementation of the interface. It would however align more with our base interfaces and the intended usage.

Minimal reproducible example

public class MainLayout extends AppLayout {
    ...

    @Override
    protected void afterNavigation() {
        getUI().orElseThrow(IllegalStateException::new);
    }
    ...
}

Steps to reproduce

  1. Create a starter app from our website.
  2. Go to the MainLayout.
  3. Call getUI() inside the pre-implemented afterNavigation method. The returned value is an empty optional.

Environment

Vaadin version(s): 24.1.8
OS: Windows

Browsers

Issue is not browser related

@knoobie
Copy link
Contributor

knoobie commented Sep 11, 2023

The UI should be available via event.getLocationChangeEvent().getUI()

@stefanuebe
Copy link
Contributor Author

The AppLayout afterNavigation method does not have an event. The issue targets the AppLayout method, not the AfterNavObserver one.

@knoobie
Copy link
Contributor

knoobie commented Sep 11, 2023

Oh.. now I see what you mean.. you are using the protected method which probably should never been protected.. this is way to early in the router life circle and won't have access to the UI

@stefanuebe
Copy link
Contributor Author

Jep, the method is used by the starter apps as an example. Might be good to also make it private or rename it to something more disambigious, when not using the ANO as a basis for this functionality.

@TatuLund
Copy link
Contributor

Note, you can implement the true afterNavigation by implementing AfterNavigationObserver in your MainLayout. This method in AppLayout is a bit badly named as it is not based on same mechanism.

@yuriy-fix
Copy link
Contributor

I guess it would make sense to make it private.

@yuriy-fix yuriy-fix added DX Developer experience issue refactor Internal improvement labels Sep 13, 2023
@TatuLund
Copy link
Contributor

I guess it would make sense to make it private.

The default implementation sets the mobile behavior of the Drawer, I would assume that method is protected in order to override that behavior if needed.

@ugur-vaadin ugur-vaadin self-assigned this Oct 4, 2023
@ugur-vaadin ugur-vaadin linked a pull request Oct 5, 2023 that will close this issue
9 tasks
@ugur-vaadin ugur-vaadin added the requires new major This would be a breaking change label Dec 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
DX Developer experience issue refactor Internal improvement requires new major This would be a breaking change vaadin-app-layout
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants