Skip to content

PiT 24.2: error in console when customizing vaadin-button with @CssImport #17345

Closed

Description

@manolo

When running the app there are errors in browser console

Compile and run the app for production

git clone https://github.com/vaadin/bookstore-example.git
cd bookstore-example
mvn -ntp -B clean install -Pproduction,it 
mvn -ntp -Pproduction -B jetty:run-war 

See browser's console error

The custom element definition for "vaadin-button" was finalized before a style module was registered. Make sure to add component specific style modules before importing the corresponding custom element. - http://localhost:8080/VAADIN/build/generated-flow-imports-6b832631.js

Activity

  1. manolo commented on Aug 2, 2023

    @manolo
    MemberAuthor
  2. changed the title [-]PiT 24.2: error in console when using vaadin-button[/-] [+]PiT 24.2: error in console when customizing vaadin-button with @CssImport[/+] on Aug 2, 2023
  3. TatuLund commented on Aug 2, 2023

    @TatuLund
    Contributor

    See also #17221

  4. mcollovati commented on Aug 8, 2023

    @mcollovati
    Collaborator

    Although using @CssImport and themeFor is not recommended with Vaadin 24 (https://vaadin.com/docs/latest/styling/legacy/css-import), it should still work.

    The problem seems to be that because of bundle lazy loading, the CSS from the annotation is loaded too late.

    I'm not sure if it is a proper fix, but forcing an eager load for chunks that has CSS loaded with themeFor seems to work

    abstract class AbstractUpdateImports implements Runnable {
    
        private Map<File, List<String>> process(Map<ChunkInfo, List<CssData>> css,
                Map<ChunkInfo, List<String>> javascript) {
    
            ....
    
            for (Entry<ChunkInfo, List<CssData>> entry : css.entrySet()) {
                boolean hasLegacyStyling = entry.getValue().stream()
                        .anyMatch(cssData -> cssData.getThemefor() != null);
                if (!hasLegacyStyling && isLazyRoute(entry.getKey())) {
                    List<String> cssLines = getCssLines(entry.getValue());
                    if (!cssLines.isEmpty()) {
                        lazyCss.put(entry.getKey(), cssLines);
                    }
                } else {
                    eagerCssData.addAll(entry.getValue());
                }
            }
    
           ...
      }
    }
  5. knoobie commented on Aug 8, 2023

    @knoobie
    Contributor

    Note: Sadly CssImport / themeFor (especially for add-ons) is still a must have because of some limitation documented by Rolf here: vaadin/docs#2552

  6. added a commit that references this issue on Aug 9, 2023
    7920122
  7. added a commit that references this issue on Aug 12, 2023
    9e3d938
  8. added 2 commits that reference this issue on Aug 12, 2023
    0315f72
    4e8ca61
  9. vaadin-bot commented on Aug 17, 2023

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with Vaadin 24.2.0.alpha7 and is also targeting the upcoming stable 24.2.0 version.

  10. vaadin-bot commented on Aug 22, 2023

    @vaadin-bot
    Collaborator

    This ticket/PR has been released with Vaadin 24.1.6.

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

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions