Skip to content

fix: ensure dense theme CSS is included in production bundle#175

Open
timomeinen wants to merge 1 commit intoFlowingCode:masterfrom
timomeinen:fix/issue-171-dense-theme-production-bundle
Open

fix: ensure dense theme CSS is included in production bundle#175
timomeinen wants to merge 1 commit intoFlowingCode:masterfrom
timomeinen:fix/issue-171-dense-theme-production-bundle

Conversation

@timomeinen
Copy link
Copy Markdown

@timomeinen timomeinen commented Mar 27, 2026

Problem

The DENSE_THEME constant is a static final String, so javac inlines it at the call site. When a consumer only uses the constant (e.g. grid.addThemeName(GridHelper.DENSE_THEME)), no bytecode reference to GridHelper is emitted. The Vaadin production bundle scanner is reachability-based, so it never visits GridHelper and its @CssImport annotations are not processed. The dense theme CSS is missing from the production bundle.

Solution

Add setDenseTheme(Grid<?>, boolean) and isDenseTheme(Grid<?>) static methods to GridHelper. Calling these methods emits an invokestatic instruction referencing GridHelper, making the class reachable to the scanner.

Changes

  • GridHelper.java: Added setDenseTheme / isDenseTheme methods with a private DENSE_THEME_NAME constant for internal use. Deprecated the public DENSE_THEME constant with guidance to use the new methods.
  • GridHelperServiceInitListener.java: Removed (previous approach to the same problem, superseded by the method-based solution).
  • VaadinServiceInitListener services file: Removed along with the listener.
  • DenseThemeDemo.java: Updated to use GridHelper.setDenseTheme(grid, true).
  • AllFeaturesDemo.java: Updated to delegate to GridHelper.setDenseTheme / isDenseTheme.
  • README.md: Updated getting-started example.

Closes #171

Summary by CodeRabbit

  • New Features

    • Added dedicated helper methods for applying and checking dense theme on grid instances.
  • Documentation

    • Updated developer guide examples to use the new dense theme configuration approach.
  • Deprecated

    • Direct use of dense theme constant deprecated; use new helper methods instead.

Add setDenseTheme(Grid, boolean) and isDenseTheme(Grid) methods that
create a bytecode reference to GridHelper, ensuring the Vaadin production
bundle scanner discovers its @CssImport annotations.

The DENSE_THEME constant is a compile-time constant (static final String),
so javac inlines it at the call site. When a consumer only uses the
constant (e.g. grid.addThemeName(GridHelper.DENSE_THEME)), no bytecode
reference to GridHelper is emitted and the scanner never reaches it.

The previous VaadinServiceInitListener approach is removed in favor of
the simpler method-based solution.

DENSE_THEME is deprecated in favor of the new methods.

Closes FlowingCode#171
@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

Walkthrough

Refactored the dense theme configuration in GridHelper to use explicit setter methods instead of direct theme-name manipulation. Removed the VaadinServiceInitListener class and its service registration. Added setDenseTheme() and isDenseTheme() public methods while deprecating the direct constant usage. Updated demo code and documentation to use the new API.

Changes

Cohort / File(s) Summary
Documentation
README.md
Updated developer guide example to use new GridHelper.setDenseTheme(grid, true) instead of grid.addThemeName(GridHelper.DENSE_THEME).
Core API Refactoring
src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelper.java
Introduced private DENSE_THEME_NAME constant; deprecated public DENSE_THEME as an alias; added public setDenseTheme(Grid<?>, boolean) and isDenseTheme(Grid<?> grid) methods.
Service Listener Removal
src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelperServiceInitListener.java, src/main/resources/META-INF/services/com.vaadin.flow.server.VaadinServiceInitListener
Removed GridHelperServiceInitListener class and its registration entry from Vaadin service discovery.
Demo Updates
src/test/java/com/flowingcode/vaadin/addons/gridhelpers/AllFeaturesDemo.java, src/test/java/com/flowingcode/vaadin/addons/gridhelpers/DenseThemeDemo.java
Updated dense theme operations to use new GridHelper.setDenseTheme() and GridHelper.isDenseTheme() methods instead of direct grid theme-name manipulation.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

Suggested reviewers

  • mlopezFC
  • paodb
🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 28.57% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately summarizes the main change: ensuring the dense theme CSS is included in the production bundle through architectural refactoring.
Linked Issues check ✅ Passed The PR directly addresses issue #171 by implementing the required fix to ensure dense theme CSS is included in production builds through new helper methods.
Out of Scope Changes check ✅ Passed All changes are directly related to solving the dense theme production bundle issue; no unrelated modifications are present.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (2)
src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelper.java (2)

117-119: Same null-safety consideration applies to isDenseTheme.

For consistency, consider applying the same null check here.

Proposed null check
 public static boolean isDenseTheme(Grid<?> grid) {
+  java.util.Objects.requireNonNull(grid, "grid cannot be null");
   return grid.hasThemeName(DENSE_THEME_NAME);
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelper.java`
around lines 117 - 119, The isDenseTheme method currently calls
grid.hasThemeName(DENSE_THEME_NAME) without guarding against a null grid; add
the same null-safety check used elsewhere (e.g., return false if grid is null)
before calling Grid.hasThemeName to avoid NPEs—update the isDenseTheme(Grid<?>
grid) implementation to check grid for null and only call
grid.hasThemeName(DENSE_THEME_NAME) when non-null.

103-109: Consider adding null-safety for the grid parameter.

The method will throw a NullPointerException if grid is null. While callers are expected to pass a valid grid, adding a null check would provide a clearer error message and align with defensive coding practices seen elsewhere in Vaadin components.

Proposed null check
 public static void setDenseTheme(Grid<?> grid, boolean dense) {
+  java.util.Objects.requireNonNull(grid, "grid cannot be null");
   if (dense) {
     grid.addThemeName(DENSE_THEME_NAME);
   } else {
     grid.removeThemeName(DENSE_THEME_NAME);
   }
 }
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelper.java`
around lines 103 - 109, The setDenseTheme(Grid<?> grid, boolean dense) method
lacks null-safety and will NPE if grid is null; add a defensive check at the top
of setDenseTheme to validate the grid parameter (e.g., if grid == null) and
throw a clear IllegalArgumentException or NullPointerException with a concise
message like "grid must not be null" before referencing DENSE_THEME_NAME or
calling grid.addThemeName/removeThemeName; this keeps behavior explicit and
consistent with other Vaadin defensive checks.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelper.java`:
- Around line 117-119: The isDenseTheme method currently calls
grid.hasThemeName(DENSE_THEME_NAME) without guarding against a null grid; add
the same null-safety check used elsewhere (e.g., return false if grid is null)
before calling Grid.hasThemeName to avoid NPEs—update the isDenseTheme(Grid<?>
grid) implementation to check grid for null and only call
grid.hasThemeName(DENSE_THEME_NAME) when non-null.
- Around line 103-109: The setDenseTheme(Grid<?> grid, boolean dense) method
lacks null-safety and will NPE if grid is null; add a defensive check at the top
of setDenseTheme to validate the grid parameter (e.g., if grid == null) and
throw a clear IllegalArgumentException or NullPointerException with a concise
message like "grid must not be null" before referencing DENSE_THEME_NAME or
calling grid.addThemeName/removeThemeName; this keeps behavior explicit and
consistent with other Vaadin defensive checks.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 1a469487-95d9-4d53-8fe4-a3b433ae41d2

📥 Commits

Reviewing files that changed from the base of the PR and between 8ae8fea and f44363c.

📒 Files selected for processing (6)
  • README.md
  • src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelper.java
  • src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelperServiceInitListener.java
  • src/main/resources/META-INF/services/com.vaadin.flow.server.VaadinServiceInitListener
  • src/test/java/com/flowingcode/vaadin/addons/gridhelpers/AllFeaturesDemo.java
  • src/test/java/com/flowingcode/vaadin/addons/gridhelpers/DenseThemeDemo.java
💤 Files with no reviewable changes (2)
  • src/main/resources/META-INF/services/com.vaadin.flow.server.VaadinServiceInitListener
  • src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelperServiceInitListener.java

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

Labels

None yet

Projects

Status: To Do

Development

Successfully merging this pull request may close these issues.

Grid Helper Dense Mode does not work with productive build

2 participants