Class ActiveStyleSheetTracker

java.lang.Object
com.vaadin.flow.internal.ActiveStyleSheetTracker
All Implemented Interfaces:
Serializable

public final class ActiveStyleSheetTracker extends Object implements Serializable
Tracks the set of all active stylesheets used by the running application during development time.

The tracker keeps a per-session set of stylesheet URLs that are currently applied via @StyleSheet and a global set for AppShell stylesheets that are applied to all pages.

Per-session tracking is used for component-based annotations and to avoid accidentally adding stylesheets to those UIs not using a given component, when a new stylesheet is added and hot-reloaded.

The data is stored in the VaadinContext and can be retrieved from any module using get(VaadinService).

For internal use only. May be renamed or removed in a future release.

See Also:
  • Method Details

    • get

      public static ActiveStyleSheetTracker get(VaadinService service)
      Returns the tracker instance stored in the given service context, creating it if necessary.
      Parameters:
      service - the active VaadinService
      Returns:
      the tracker instance, never null
    • get

      public static ActiveStyleSheetTracker get(VaadinContext context)
      Returns the tracker instance stored in the given VaadinContext, creating it if necessary.
      Parameters:
      context - the VaadinContext
      Returns:
      the tracker instance, never null
    • trackAddForComponent

      public void trackAddForComponent(String url)
      Register that the given stylesheet URL is active on the page and eligible for hot-reload.
      Parameters:
      url - the stylesheet URL to be hot-reloaded
    • trackRemoveForComponent

      public void trackRemoveForComponent(String url)
      Register that the given stylesheet URL is no longer active on the page and should not be hot-reloaded.
      Parameters:
      url - the stylesheet URL to be skipped during hot-reload
    • trackForAppShell

      public void trackForAppShell(Collection<String> urls)
      Replaces the set of active AppShell stylesheet URLs.
      Parameters:
      urls - the new set of app shell stylesheet URLs to be hot-reloaded
    • getActiveUrls

      public Set<String> getActiveUrls()
      Returns all currently active stylesheet URLs, including AppShell URLs and components.
      Returns:
      a new set containing all active stylesheet URLs to be hot-reloaded