-
Notifications
You must be signed in to change notification settings - Fork 59
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
Failed to compile template: constant string too long #25
Comments
Hey @tomholub, thanks for reporting! I always thought this to be a rather theoretical issue :-) I haven't come close to that limit yet. In your case, would it work to extract common parts into their own reusable tags? Or is it really a super big file to include? At work, we have the usecase to include generated css/js files, that are pretty big and don't contain any jte logic at all (they are generated by webpack). Edit: We use a class like this to load those. Maybe this would be useful to add to jte itself? Would this solve your usecase?
|
Definitely - that's what I will be doing (splitting it up). However I didn't expect to run into such limit - you never know what use cases others will run into. For myself, I wanted to have an all-inclusive "samples" page that has all sorts of html elements or components from our html templates that have not yet been transformed into usable jte components. It's like a repository for our devs where they could go to It's not exactly a production scenario so I'll do something else. But others may be in a different situation. |
We're also using this for our styleguide - to display the jte code 'as is' and below the rendered result.
In the styleguide jte template we'd use something like this:
For your usecase you might want to use something like:
|
Thanks! That looks good to me. More generally, I could imagine some folks running into this, then silently walking away thinking jte is "not mature enough". So even if there is a way to work around, I'd recommend to see if this can be addressed in the codebase itself 👍 |
Splitting the generated classes would be pretty hard to do. The entire state of the render() function would have to be passed to the other class. For instance:
This is stuff the jte compiler isn't aware of, since it simply delegates the generated class to javac. It would also not help in your example, since there one single String exceeds the limit. One option would be to load all constant Strings from an external location. However, this would slow down template loading, plus, it would prevent the JVM from String inlining. When I did some benchmarks with this, I noticed that That being said, would it help to add the ability to import file contents in templates to the jte core? Like the |
For myself, I made it a static file and later I'll use You can leave this issue open for a while first - if others have the same issue, they may leave a note here. |
Alright, will do that. Good luck and let me know if you run into any problems with this approach. |
Length calculation is based on modified UTF-8. Reference: https://github.com/openjdk/jdk/blob/a8a2246158bc53414394b007cbf47413e62d942e/src/java.base/share/classes/java/io/DataOutputStream.java#L351-L358 Reference: https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html#jvms-4.4.7 Fixes #25.
Steps to reproduce:
tag/something.jte
@tag.something()
Long templates should be somehow split up to stay under the Java length limit.
The text was updated successfully, but these errors were encountered: