Skip to content

Conversation

mshabarov
Copy link
Contributor

Reverts previously added file watcher for stylesheet files as the static resource folder is already watched by hotswap mechanism.
Updates link tag once a modification is detected so stylesheet is hot reloaded.

Related-to: #22465

Copy link

github-actions bot commented Oct 13, 2025

Test Results

1 271 files  +1  1 271 suites  +1   1h 19m 1s ⏱️ + 1m 0s
8 796 tests  - 1  8 729 ✅  - 1  67 💤 ±0  0 ❌ ±0 
9 248 runs   - 2  9 171 ✅  - 2  77 💤 ±0  0 ❌ ±0 

Results for commit 1b53372. ± Comparison against base commit 1777b02.

This pull request removes 4 and adds 3 tests. Note that renamed tests count towards both.
com.vaadin.base.devserver.PublicResourcesCssLiveUpdaterTest ‑ cssChangeTriggersUpdate
com.vaadin.base.devserver.PublicResourcesCssLiveUpdaterTest ‑ devModeHandler_watchesAllStaticResourcePathsForCss
com.vaadin.base.devserver.PublicResourcesCssLiveUpdaterTest ‑ devModeHandler_watchesNestedCssFilesUnderStaticRoot
com.vaadin.base.devserver.PublicResourcesCssLiveUpdaterTest ‑ nonCssChangeIsIgnored
com.vaadin.flow.hotswap.HotswapperResourcesTest ‑ cssResourceChange_noLiveReloadAvailable_noCrash
com.vaadin.flow.hotswap.HotswapperResourcesTest ‑ cssResourceChange_triggersLiveReloadUpdateWithRelativePath
com.vaadin.flow.server.AppShellRegistryStyleSheetDataFilePathTest ‑ modifyIndex_addsDataFilePathAttributes_normalized

♻️ This comment has been updated with latest results.

@vaadin-bot vaadin-bot added +0.1.0 and removed +0.0.1 labels Oct 13, 2025
Comment on lines 217 to 218
String path = resourcePath
.replace(staticResourcesPath, "");
Copy link
Contributor Author

Choose a reason for hiding this comment

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

To be able to compare with the existing link tag, we should cut off the path part that points to resource dir inside build dir.

@mshabarov
Copy link
Contributor Author

Tried to test with Gradle project, but ended up receiving

HOTSWAP AGENT: 14:06:49.506 INFO (org.hotswap.agent.plugin.spring.reload.SpringBeanReload) - try to add changed property 'file:/.../base-starter-spring-gradle/build/resources/main/application.properties' into org.springframework.beans.factory.support.DefaultListableBeanFactory@1df32c09

while changing src/main/resources/META-INF/resources/styles.css.

@mshabarov mshabarov marked this pull request as ready for review October 13, 2025 15:17
}
String buildFolderName = getBuildFolder();
File buildFolder = new File(projectFolder, buildFolderName);
if (Constants.TARGET.equals(buildFolderName)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

This might not match maven as you can define your own build folder.
Perhaps the better check would be to see if build_folder/classes exist or build_folder/resources

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done, thanks!

mshabarov and others added 4 commits October 14, 2025 11:35
…difications

# Conflicts:
#	vaadin-dev-server/src/test/java/com/vaadin/base/devserver/PublicResourcesCssLiveUpdaterTest.java
@mshabarov
Copy link
Contributor Author

mshabarov commented Oct 14, 2025

I couldn't really test this with Gradle-based project, because HotswapAgent always passes {projectDir}/src/main/resources/application.properties to resourceChanged method as a URI, even for my styles.css file.

Might be a bug in HotswapAgent, but I have no idea why this so specific to Gradle.

@mcollovati
Copy link
Collaborator

I guess the problem with Gradle is how it integrates with IntelliJ.
I think, by default, IDEA delegates the build to Gradle, so most likely it is Gradle that copies application.properties to the build classes folder.
If you change the following setting from "Gradle (default)" to "IntelliJ IDEA" then the application.properties file is not copied anymore, unless you explicitly modify it.
image

@mshabarov
Copy link
Contributor Author

I changed it to "IntelliJ IDEA" and now it doesn't stop on the breakpoint in VaadinPlugin or Hotswapper at all, and doesn't hot reload the CSS 🤔

@mcollovati
Copy link
Collaborator

When I switch to "IntelliJ IDEA", I can see the following logs when I save the CSS file

2025-10-14T15:18:50.518+02:00 TRACE 137735 --- [     Thread-270] com.vaadin.flow.hotswap.Hotswapper       : Created resources: [file:///xxxxx/base-starter-spring-gradle/out/production/resources/META-INF/resources/styles.css], modified resources: [], deletedResources: [file:///home/xxxxx/base-starter-spring-gradle/out/production/resources/META-INF/resources/styles.css].
2025-10-14T15:18:54.725+02:00 TRACE 137735 --- [     Thread-276] com.vaadin.flow.hotswap.Hotswapper       : Created resources: [file:///xxxxx/base-starter-spring-gradle/out/production/resources/META-INF/resources/styles.css], modified resources: [], deletedResources: [file:///xxxxx/base-starter-spring-gradle/out/production/resources/META-INF/resources/styles.css].

@mcollovati
Copy link
Collaborator

Maybe some other IDEA setting, e.g. compile on save (don't know if such a thing exists :) )?

@mshabarov
Copy link
Contributor Author

Maybe some other IDEA setting

Yes, might be it, because even for V24.9 I have the same observation.

Copy link
Collaborator

@mcollovati mcollovati left a comment

Choose a reason for hiding this comment

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

Tested with Gradle and now it seems to work fine.
It happened once that the first modification of the stylesheet was not propagated, but this is probably something related to my IDE or Gradle.
Added some comment for potential improvements

createdResources, modifiedResources, deletedResources);
}

if (anyMatches(".*\\.css", createdResources, modifiedResources,
Copy link
Collaborator

Choose a reason for hiding this comment

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

Just a note for a future improvement: we could refactor a bit of the code to add a onResourceEvent(ResourceEvent event) on VaadinHotswapper interface and move the logic in this method into two separate classes (for styles and translations).

@mshabarov mshabarov requested a review from mcollovati October 15, 2025 06:26
@mshabarov
Copy link
Contributor Author

Re-tested with maven project - works as expected.

Copy link

@mshabarov mshabarov merged commit b091938 into main Oct 15, 2025
29 checks passed
@mshabarov mshabarov deleted the hot-reload-for-css-modifications branch October 15, 2025 07:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants