This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-10
Channels
- # announcements (2)
- # babashka (20)
- # beginners (381)
- # calva (16)
- # chlorine-clover (21)
- # cider (1)
- # clj-kondo (18)
- # cljs-dev (107)
- # cljsrn (2)
- # clojure (161)
- # clojure-dev (5)
- # clojure-europe (2)
- # clojure-losangeles (3)
- # clojure-nl (3)
- # clojure-uk (35)
- # clojurescript (22)
- # conjure (48)
- # cursive (8)
- # datascript (11)
- # datomic (6)
- # figwheel-main (10)
- # fulcro (85)
- # hoplon (112)
- # jobs (1)
- # kaocha (5)
- # luminus (5)
- # malli (1)
- # off-topic (96)
- # onyx (1)
- # pedestal (1)
- # perun (1)
- # reagent (5)
- # reitit (1)
- # shadow-cljs (34)
- # specmonstah (1)
- # sql (6)
- # tools-deps (3)
- # xtdb (23)
has anyone experienced hoplon's prerendering turning <
in inline scripts into <
?
i'm running into trouble with my app's content security policy because the prerender step is changing the content of an inline script that contains <
so that it contains <
instead
it looks like it's probably happening here: https://github.com/hoplon/boot-hoplon/blob/3e0fdb799c505dc54a2e5953798262538fef2ec4/src/hoplon/boot_hoplon/tagsoup.clj#L86-L87 via https://github.com/hoplon/boot-hoplon/blob/3e0fdb799c505dc54a2e5953798262538fef2ec4/src/hoplon/boot_hoplon/impl.clj#L40
@dave look here though: https://github.com/hoplon/boot-hoplon/blob/3e0fdb799c505dc54a2e5953798262538fef2ec4/src/hoplon/boot_hoplon/impl.clj#L33
i think it's been broken the whole time, we just didn't notice in this particular project because the existing scripts we had with :prerender-keep
happened not to contain &, <, or >
since we're getting caching via cloudfront, i'm not sure if prerendering is helping much beyond that
my first thought was that it might be an advanced optimizations issue, but that wasn't it
hmm, it looks like \x3C
is the escape sequence for <
, but it doesn't seem to work outside of javascript string literals
i've only experimented in the JS console, though. not sure if it behaves differently in an inline script tag
what does it look like when you do "show source" (not the elements pane of the devtools)
i changed the offending part of the code to for(w=0,x=v.length;w\\x3Cx;++w)
whereas the \\x3C
used to be <
the easiest thing to do really is to make your own html file and then mount the app in a div inside there
then you don't need prerendering because you can pull out the things you want to have prerendered into the html file
making our own html file is a good suggestion. i've been thinking about that in the back of my mind
i would just need to do some post-processing to insert the right cache keys for cache busting
could another solution be to put the inline JS into a file instead? or would that potentially screw up the load order?
just catching up,was the problem literla JS inside a script tag in a cljs file?
i think i've run into that before,with google analytics or something
i wonder about using js* to inline JS strategically
that would roll it into the cljs source
i guess sometimes you need JS to run before the cljs kicks in tho
like is the load order for this:
<script>alert("lol");</script>
<script src="index.cachekeygoeshere.html.js"></script>
any different than the load order for this?
<script src="alert_lol.js"></script>
<script src="index.cachekeygoeshere.html.js"></script>
should be no different
i was suggesting using js* to put alert("lol") in index.cachekeygoeshere.html.js
it's just that it only works because the inline JS doesn't include &, <, or > which hoplon's prerenderer would escape
seems to me like the prerender shouldn't escape script tag innards
from a pure xml sense it make sense, and is a good default. maybe a bug in prerender?
absolut nyet
anothre option is golf that code to not use any escaped chars like goog did
partially as entertainment 😆
function lt(x, y) { var z = (y - x); return z != "0" && z.toString()[0] !== "-"; }
crap,ampersand
that would be <= because if x == y, [0] !== "-"
close but no banana
oh i see, yes, it should work
my thing was lte, yours is lt
x is < y iff (y - x) < 0, e.g. its string rep. has a leading dash
i bet google did that intentionally man
i wonder if a tool of theirs does this kind of rewriting even
aha that =>
tho
gotta keep it es3
ha yeah
a few years ago at my new job i spent a few weeks relearning JS starting from 2012 or something
it has all the things now pretty much
in addition to all the crazy things it always had
you know, i guess you can't make a real short-circuting &&
as a function, because the real one delays evaluation
the best you could do is wrap every argument in a function at the call site
lol this is unfolding into a great big tech company interview question
oh sweet, yes good point
you could even say it's not a contrived question, it actually came up in the course of work haha