Skip to content

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

Merged
javier-godoy merged 3 commits intoFlowingCode:masterfrom
timomeinen:fix/issue-171-dense-theme-production-bundle
Apr 8, 2026
Merged

fix: ensure dense theme CSS is included in production bundle#175
javier-godoy merged 3 commits 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

    • New helper methods to enable/disable and check a grid's dense styling at runtime.
  • Documentation

    • Developer guide examples updated to demonstrate the new dense theme configuration approach.
  • Deprecated

    • Direct use of the dense theme constant is deprecated; prefer the new helper methods going forward.

@coderabbitai
Copy link
Copy Markdown

coderabbitai bot commented Mar 27, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 50fba558-4189-442c-8b08-342da5879dec

📥 Commits

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

📒 Files selected for processing (7)
  • README.md
  • pom.xml
  • 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
✅ Files skipped from review due to trivial changes (2)
  • pom.xml
  • README.md
🚧 Files skipped from review as they are similar to previous changes (2)
  • src/test/java/com/flowingcode/vaadin/addons/gridhelpers/DenseThemeDemo.java
  • src/test/java/com/flowingcode/vaadin/addons/gridhelpers/AllFeaturesDemo.java

Walkthrough

Replaced direct theme-name usage with explicit APIs for dense styling in GridHelper (added setDenseTheme and isDenseTheme, deprecated the public constant), removed the Vaadin service init listener and its service registration, updated demos and README, and bumped project version.

Changes

Cohort / File(s) Summary
Documentation
README.md
Updated example to use GridHelper.setDenseTheme(grid, true) instead of grid.addThemeName(GridHelper.DENSE_THEME).
Core API
src/main/java/com/flowingcode/vaadin/addons/gridhelpers/GridHelper.java
Made dense theme name private (DENSE_THEME_NAME), reintroduced DENSE_THEME as a deprecated alias, and added public setDenseTheme(Grid<?>, boolean) and isDenseTheme(Grid<?> grid) methods.
Service registration
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 META-INF service registration entry.
Demos / Tests
src/test/java/com/flowingcode/vaadin/addons/gridhelpers/AllFeaturesDemo.java, src/test/java/com/flowingcode/vaadin/addons/gridhelpers/DenseThemeDemo.java
Switched demo/test code to use GridHelper.setDenseTheme(...) and GridHelper.isDenseTheme(...) instead of direct theme-name manipulation.
Build
pom.xml
Bumped project version from 2.0.1-SNAPSHOT to 2.1.0-SNAPSHOT.

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 describes the main objective of the PR: ensuring dense theme CSS is included in the production bundle, which is the core problem being addressed.
Linked Issues check ✅ Passed The PR successfully addresses issue #171 by implementing static methods that create invokestatic bytecode references to GridHelper, ensuring the class is reachable to Vaadin's production bundle scanner for CSS inclusion.
Out of Scope Changes check ✅ Passed All changes directly support the PR objective: API additions (setDenseTheme/isDenseTheme), DENSE_THEME deprecation, removal of the now-unnecessary GridHelperServiceInitListener, demo/README updates, and version bump to 2.1.0 reflect the API change scope.

✏️ 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.

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

javier-godoy and others added 3 commits April 8, 2026 12:17
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.

DENSE_THEME is deprecated in favor of the new methods.

Closes FlowingCode#171

Co-authored-by: Javier Godoy <11554739+javier-godoy@users.noreply.github.com>
@javier-godoy javier-godoy force-pushed the fix/issue-171-dense-theme-production-bundle branch from f44363c to eccbdf0 Compare April 8, 2026 16:19
@sonarqubecloud
Copy link
Copy Markdown

sonarqubecloud bot commented Apr 8, 2026

@javier-godoy javier-godoy merged commit a16fa63 into FlowingCode:master Apr 8, 2026
5 checks passed
@github-project-automation github-project-automation bot moved this from To Do to Pending release in Flowing Code Addons Apr 8, 2026
@timomeinen timomeinen deleted the fix/issue-171-dense-theme-production-bundle branch April 9, 2026 11:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Pending release

Development

Successfully merging this pull request may close these issues.

Grid Helper Dense Mode does not work with productive build

3 participants