weavejester / hiccup

Fast library for rendering HTML in Clojure
http://weavejester.github.io/hiccup
Eclipse Public License 1.0
2.68k stars 174 forks source link

Somehow syntax error has occured. #157

Closed t-matsudate closed 2 years ago

t-matsudate commented 5 years ago

I tried to use hiccup 2.0.0-alpha2 with following code:

(ns my-project.handler
  (:require
    [ring.util.response :refer [response]]
    [hiccup.page :refer [html5]]))

(defn- hoge-view [...]
  (html5
    (call-a-vector-to-have-17-element-meta-tags)
    [:body
      ; up to 10 nests, arround 40 elements.
    ]))

(defn hoge-handler
  [request]
  (response (hoge-view ...)))

Then, somehow following syntax error has occured:

Exception in thread "main" Syntax error compiling fn* at (my_project/handler.clj:xxx:y).
...
Caused by: java.lang.IndexOutOfBoundsException: Method code too large!

Preconditions:

What is occuring in hiccup 2.0.0-alpha?

weavejester commented 5 years ago

Hiccup pre-compiles the data structure into code in order to speed up execution. It looks like you're hitting the inbuild JVM limits of how much code can be in a single method.

It probably doesn't show in earlier versions because Hiccup 2.0 supports more functionality, and therefore happens to produce more code in your particular case. Hiccup 1.0 would run into the same problem, just at a later point.

If performance isn't an issue, you can wrap your code in a function:

(defn html5* [& data]
  (hiccup/html5 data))

This ensures pre-compilation isn't used. Otherwise, split your Hiccup data into smaller functions. It's generally more idiomatic to write smaller Clojure functions than larger ones.

In future we could potentially solve this by dividing code into functions automatically, but that will need a PR and some significant work.

t-matsudate commented 5 years ago

Thank you for telling how to solve this issue! I'll try to split the code making the html vectors more smaller, and will retry to use hiccup 2.0.0-alpha.