Skip to content

Any invisible component in drawer breaks Aura theme in AppLayout #11212

Closed
vaadin/flow
#24037

Description

@mstahv

Description

The light background in the AppLayout dissappears if there is any invisible component in the drawer.

@Route
@StyleSheet(Aura.STYLESHEET)
public class MainView extends VerticalLayout {

    @Layout
    public static class MainLayout extends AppLayout {

        public MainLayout() {
            addToDrawer(new Paragraph("Menu"));
            addToDrawer(new Paragraph("Hidden item"){{
                // Setting something invisible in the drawer breaks Aura theme
                // in app layout, content area color is lost
                setVisible(false);
            }});
        }
    }

    public MainView() {
        add(new H1("It works!? This main part should have light background color"));
    }
}

Expected outcome

Should work

Minimal reproducible example

Use the code above

Steps to reproduce

Use the app above

Environment

Flow: 25.1-SNAPSHOT
Vaadin: 25.1-SNAPSHOT
Spring Boot: 4.0.1
Spring: 7.0.2
Copilot: 25.1-SNAPSHOT
Frontend Hotswap: Pre-Built Bundle
OS: aarch64 Mac OS X 26.3
Java: Azul Systems, Inc. 25
Browser: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/26.3 Safari/605.1.15
Java Hotswap: Hotswap is disabled
IDE Plugin: 1.5.10 IntelliJ

Browsers

No response

Activity

  1. jouni commented on Feb 27, 2026

    @jouni
    Member

    The problem is that even though the paragraph component is added to the drawer, it doesn't get the slot="drawer" attribute in the DOM. Aura adds the background color only if there’s a single content element in the App Layout. Now there are two, the <p> and the <vaadin-vertical-layout>:

    Image

    I wonder if Flow’s implementation for hidden components can be updated to allow certain attributes to be sent to the client?

    One workaround could be to offer a classname in Aura, which you can explicitly add to the App Layout content element, for cases like this when the structural selector doesn't match.

  2. rolfsmeds commented on Feb 27, 2026

    @rolfsmeds
    Contributor

    Omitting the slot attribute can definitely cause issues in any css or js that relies on the existence (or number of) elements in the default slot. Would be good if Flow's hidden mechanism would not omit that attribute at least.

    Thoughts, @mshabarov ?

  3. mshabarov commented on Mar 5, 2026

    @mshabarov
    Contributor

    Flow prevents attributes from being sent to the client for invisible elements for security reasons: if an element is hidden initially, only an empty placeholder should be sent to the client with no value and no other data that may reveal the backend data.

    When an element is set as invisible via setVisible(false):

    1. Server-side: The ElementData.setVisible(false) is called (ElementData.java:112), which sets the VISIBLE property to false in the state node
    2. Client-side: The SimpleElementBindingStrategy detects the invisible state and calls setElementInvisible() (SimpleElementBindingStrategy.java:655), which only sets the hidden attribute and display: none.

    The problem: When an element is initially invisible, it's only partially bound (SimpleElementBindingStrategy.java:718-721). The full binding process (including ELEMENT_ATTRIBUTES which contains the slot attribute) is deferred until the element becomes visible.

    This means the slot="drawer" attribute is never sent to/set on the client DOM for invisible elements, causing the Aura theme's structural CSS selector (:host(:not([overlay])) [slot]:not([slot=navbar]):not([slot=drawer]):only-child) to incorrectly match the content area.

    Possible solutions:

    1. Preserve critical attributes during invisible state: Modify the visibility mechanism to always send certain "structural" attributes (like slot) even when the element is invisible. This could be done by:
      • Always binding ELEMENT_ATTRIBUTES before checking visibility, or
      • Maintaining a whitelist of attributes that should be set even for invisible elements
    2. Change hiding strategy: Instead of deferring the full binding, fully bind the element first (including all attributes), then hide it with hidden and display: none. This ensures all structural attributes are present in the DOM, but violates the security design.

    So I'd go with (1) - collecting the "allowed list" of attributes that are critical for theming and send them even for partially bound elements.

  4. moved this from 🪵Product backlog to 🟢Ready to Go in Vaadin Flow | Hilla | Kits ongoing workon Mar 11, 2026
  5. mcollovati commented on Mar 27, 2026

    @mcollovati

    Option 1 seems a good choice. The allowed list of attributes will probably contain only the slot attribute for now.
    I don't see any security issues in propagating the slot attribute, since it is related to layout and CSS rather than application data.
    I don't know if a hidden element with a slot attribute might cause some visual issues, though.

  6. moved this from 🟢Ready to Go to ⚒️ In progress in Vaadin Flow | Hilla | Kits ongoing workon Mar 27, 2026
  7. added a commit that references this issue on Mar 27, 2026
    50a9030
  8. moved this from ⚒️ In progress to 🔎Iteration reviews in Vaadin Flow | Hilla | Kits ongoing workon Mar 27, 2026
  9. added a commit that references this issue on Mar 27, 2026
    727db64
  10. rolfsmeds commented on Mar 27, 2026

    @rolfsmeds
    Contributor

    I don't know if a hidden element with a slot attribute might cause some visual issues, though.

    Only if the component that the slot is part of would expect it to be empty when hidden, but since that's not expected outside of Flow, I don't think any of our components make such assumptions. And if they do, we can adjust them to take hidden into account.

  11. added a commit that references this issue on Mar 30, 2026
    7285017
  12. added 3 commits that reference this issue on Mar 30, 2026
    0c9e644
    e4285a4
    71b9c58
  13. mstahv commented on Mar 30, 2026

    @mstahv
    MemberAuthor

    Bit late to the party, but to me the fix (vaadin/flow#24037) looks quite a hack for the original issue. I don't doubt it works, but I think our framework is already too complex before this change. I wonder why we are sending the element/component to the client in the first place if it is invisible? Nothing else is sent to the client, why send it at all 🤷‍♂️ Changing that would also fix the original issue 🤔

  14. added a commit that references this issue on Mar 30, 2026
    2572b3d
  15. mshabarov commented on Mar 31, 2026

    @mshabarov
    Contributor

    If it wasn't sent to the client, then what would be the difference between making it invisible and not attaching it? I don't exactly know what were the initial implications of this design, but I guess the semantics is correct - invisible should be a part of the DOM and should be synchronized with the server. If we decide to change this, the major architectural refactoring would be needed on the client side and this could be also a breaking change for end-to-end tests or even production code.

  16. mcollovati commented on Mar 31, 2026

    @mcollovati

    I found this comment, but I don't know if it is still valid or if something has changed in the meantime.

  17. mstahv commented on Mar 31, 2026

    @mstahv
    MemberAuthor

    The first reasoning there is premature optimisation (that can still be done in different way if needed with more control). Don't remember how the "id mapping" related to polymer integration affected this or if that is still relevant 🤷‍♂️

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions