Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Serve theme static files from VAADIN/static #9451
feat: Serve theme static files from VAADIN/static #9451
Changes from 1 commit
b088d80
d25cc50
84588d1
25d1292
cb7d2d5
7e63eb7
9563620
File filter
Filter by extension
Conversations
Jump to
There are no files selected for viewing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't that exactly the opposite of #9430? @pleku
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm... but now it's a direct reference from the css file so IDEA (and others) can for instance auto complete and validate the reference file.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's a convenient for developer for "small" projects but can be a huge burden for dev or ops teams in bigger projects when you have requirements to load images from something outside of the app.
At least this "magic" should be configurable(opt-out) if that's something you need to have for vaadin's DX.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Updated so that we only change the url if the file actually exists relative to the css being handled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Interesting idea!
Just a test case to verify: Project setup: Vaadin + Spring Boot
resources/public/img/first.png
resources/META-INF/VAADIN/static/img/second.jpg
resources/VAADIN/themes/my-theme/global.css
global.css:
Spring boot would serve the image
first.png
because it is inside thepublic
folder. Now your change would not change the background-image of the css becausefirst.png
isn't reachable for webpack. And the background-image of main would be rewritten and of course served successfully. Correct?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The theme-loader will now actually check that the file exists relative to the css file handled so: if it can find the file resources/VAADIN/themes/my-theme/img/second.jpg it will be rewritten with VAADIN/static else it's seen as "external" and supplied by someone else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was the missing piece, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think if we check that the file exists either in the folder or inside a the parent theme
.jar
👀 and only modify it then, we would be handling only the URLs that we should. But then ofc. it might be quite hard for the users to detect typos (?) if those only result in 404 on the page. Could do something for that, e.g. make them more visible in development modeThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for dev mode we now log any url not modified.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lets add another test which verifies that `url("../icons/icon.png"); or similar works
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here we have a small problem in that we won't accept static serving for anything that contains
../
What we could do would be to accept navigation inside the theme folder and rewrite those to be absolute to the file target so we wouldn't have ../ e.g.
../icons/icon.png
would fail from/app-theme/global.css
, but would be rewritten toicons/icon.png
inapp-theme/sub/extras.css
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Another option could be to use a magic URL thingy there like
theme://
but not sure if it should resolve totheme/
folderUsually it should resolve to 2) but in some cases when you're creating a reusable theme it should refer to the parent theme and not the currently active theme ... so probably this is just unnecessary complication and thus a bad idea.
I think using e.g.
../icons/icon.png
is common so if we can just automatically handle it, lets go with that.For Java code, we'll expect people to anyway use the full path
"frontend/theme/my-theme/icons/icon.png"
.One thing to note, even though it is not directly part of this issue, that the npm-based imports it is supposed to work with:
"foobar/images/image.png"
when the package has been declared to be imported intheme.json
. These URLs should not be touched even though they are not "external".There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in the format
"foobar/images/image.png"
they won't be touched. Only./
is handled.