Fork me on GitHub
#klipse
<
2017-03-04
>
pesterhazy17:03:00

I'm trying out cljsjs in Klipse, using react-select as an example

pesterhazy17:03:20

It seems to load fine (window.Select is present when checked in devtools)

pesterhazy17:03:36

But when I render the component, I get an exception

pesterhazy17:03:12

The exception is

Uncaught TypeError: (0 , g.default) is not a function
    at t.render (eval at cljs.js.js_eval (klipse.js:74727), <anonymous>:1:29889)
    at p._renderValidatedComponentWithoutOwnerOrContext (klipse.js:1941)
    at p._renderValidatedComponent (klipse.js:1941)
    at performInitialMount (klipse.js:1941)
    at p.mountComponent (klipse.js:1941)
    at Object.mountComponent (klipse.js:1943)
    at performInitialMount (klipse.js:1941)
    at p.mountComponent (klipse.js:1941)
    at Object.mountComponent (klipse.js:1943)
    at h.mountChildren (klipse.js:1942)

pesterhazy17:03:45

looks like the "classnames" dependency isn't properly loaded

Yehonathan Sharvit18:03:43

Does it work fine on regular cljs?

pesterhazy18:03:21

hm I think so but I should check

pesterhazy18:03:31

I just looked at the minified js

pesterhazy18:03:43

it checks for window.classNames

pesterhazy18:03:05

and window.classNames is indeed set

pesterhazy18:03:13

so not sure what's going on there

pesterhazy18:03:12

window.classNames("a", "b")
"a b"

pesterhazy18:03:16

also works hm hm

pesterhazy18:03:20

OK, updated. I rearranged the requires so that cljsjs.classnames gets loaded before cljsjs.react-select

pesterhazy18:03:31

but I'm getting another error now

Yehonathan Sharvit18:03:49

I cannot look at it now

Yehonathan Sharvit18:03:13

I’m preparing the “Essential Klipse” webinar that is starting in 20 minutes

pesterhazy18:03:54

I'll join in 🙂

Yehonathan Sharvit18:03:40

I’m currently testing the webinar connection with Jay

pesterhazy19:03:31

I can confirm that the react-select gist works when you try it in a lein figwheel environment

clojuregeek20:03:41

Hi, my blog is based on jekyll (octopress.. old version!) and i tried using klipse ... and got this error

clojuregeek20:03:51

Pygments can't parse unknown language: language-klipse

clojuregeek20:03:28

after adding JS to the template and changing a blog post to be like:

16 │ <pre><code class="language-klipse">
  17 │ (defrecord Recipe [name link source])
  18 │ </code></pre>

clojuregeek20:03:59

i was wondering if anybody knows if this can work while using pygments

Yehonathan Sharvit20:03:33

Can you share the HTML code of the page that causes the issue

Yehonathan Sharvit20:03:52

It would be helpful if you can host the page somewhere

clojuregeek20:03:36

I get the error when running rake generate so it doens't get as far as to the html

Yehonathan Sharvit20:03:17

What did you put in your markdown exactly?

clojuregeek20:03:50

i used html tags in like i posted and trid

clojuregeek20:03:55

16 │ 
klipse 17 │ (defrecord Recipe [name link source]) 18 │

clojuregeek20:03:11

three ` for closing too 🙂

Yehonathan Sharvit20:03:37

The problem is that pygment doesn’t know klipse

Yehonathan Sharvit20:03:51

and it probably has a close list of languages it supports

Yehonathan Sharvit20:03:44

the markdown engine I use (kramdown) doesnt have such a limitation

Yehonathan Sharvit20:03:44

Could you replace klipse by clojure?

clojuregeek20:03:26

ok no errors... but i am not seeing the js in the page... let me see what is going on

Yehonathan Sharvit21:03:49

@pesterhazy could you try to use the non-minified version of react-select?

Yehonathan Sharvit21:03:24

By including this a script in your html page?

clojuregeek21:03:02

@viebel ok no errors, i see the html/css in page .. but it doesn't transform the code snippit

Yehonathan Sharvit21:03:33

did u update the klipse settings - with language-clojure?

clojuregeek21:03:32

I used what the site said for clojure

<script>
    window.klipse_settings = {
        selector: '.language-klipse'// css selector for the html elements you want to klipsify
    };
</script>

Yehonathan Sharvit21:03:08

you need to modify the selector

Yehonathan Sharvit21:03:33

the selector contains the CSS selector of the elements you want to klipsify

Yehonathan Sharvit21:03:56

In your case it should be:

<script>
    window.klipse_settings = {
        selector: '.language-clojure’ // css selector for the html elements you want to klipsify
    };
</script>

clojuregeek21:03:52

ok i can't get it .. i have the selector as clojure as that is wht the class name is of the div containing my clojure code ... the js link and css link is there

Yehonathan Sharvit21:03:49

Can you share the html file?

Yehonathan Sharvit21:03:25

There are a couple of issues here:

Yehonathan Sharvit21:03:10

1. the url of the js file is not the good one. It should be

Yehonathan Sharvit21:03:22

2. the klipse tag should be at the end of the body

Yehonathan Sharvit21:03:18

3. it seems that pygment modifies the DOM at render time. Therefore the element with the clojure class is completly rewritten. And klipse cannot find it

clojuregeek21:03:32

hm so can't use pygment then?

Yehonathan Sharvit21:03:13

Can u show me the source of your klipse snippet?

clojuregeek21:03:41

the clojure code in the div?

Yehonathan Sharvit21:03:11

Including the div as you create it in your source file

clojuregeek21:03:33

markdown

22 │ 
clojure 23 │ (def tacos (->Recipe "Tacos" "http://www.tacorecipes.com" "mom")) 24 │
generated html:
<figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
</pre></td><td class="code"><pre><code class="clojure"><span class="line"><span class="p">(</span><span class="kd">defrecord </span><span class="nv">Recipe</span> <span class="p">[</span><span class="nb">name </span><span class="nv">link</span> <span class="nv">source</span><span class="p">])</span>
</span></code></pre></td></tr></tbody></table></div></figure>

Yehonathan Sharvit21:03:07

What happens if you use three backticks without any language?

clojuregeek21:03:07

looks same without syntax highlighting

Yehonathan Sharvit21:03:54

and the generate html?

clojuregeek21:03:26

<figure class="code"><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
</pre></td><td class="code"><pre><code class=""><span class="line">(defrecord Recipe [name link source])</span></code></pre></td></tr></tbody></table></div></figure>

clojuregeek21:03:01

ok i need to take a call

clojuregeek21:03:54

well in 5 mins 🙂

Yehonathan Sharvit21:03:18

you need to find a way to tell pygment to let you use a language pygment doesn’t know

Yehonathan Sharvit21:03:28

like klipse or eval-clojure

Yehonathan Sharvit21:03:51

it should leave the div as is

Yehonathan Sharvit21:03:23

@clojuregeek there might be a solution

Yehonathan Sharvit21:03:50

It is written that "Passing 'plain' disables highlighting"

Yehonathan Sharvit21:03:57

could you try `plain ?

clojuregeek22:03:57

ok i will do it now

clojuregeek22:03:14

ok i did.. doesn't render

Yehonathan Sharvit22:03:44

you need to find a way to tell pygment to let you use a language it doesn’t know

Yehonathan Sharvit22:03:23

so that it leaves the <pre><code> element as is

Yehonathan Sharvit22:03:50

can you show me the generated html when you used `plain ?

clojuregeek22:03:56

<figure class="code"><figcaption><span></span></figcaption><div class="highlight"><table><tbody><tr><td class="gutter"><pre class="line-numbers"><span class="line-number">1</span>
</pre></td><td class="code"><pre><code class=""><span class="line">(defrecord Recipe [name link source])</span></code></pre></td></tr></tbody></table></div></figure>

clojuregeek22:03:29

looks the same as when i didn't use anything after the `

clojuregeek22:03:56

anyways thanks for your help, i don't want to take too much of your time. I'll try again later and see if i can remove pygments .. i might need to update a few things too

Yehonathan Sharvit22:03:20

can you try to have the div as is in the markdown

Yehonathan Sharvit22:03:28

I mean something like:

Yehonathan Sharvit22:03:47

<div class=”clojure”> (map inc [1 2 3]) </div>

Yehonathan Sharvit22:03:23

The problem with that approach is that if you have < or > inside your code you need to html-escape those characters

Yehonathan Sharvit22:03:57

Another option is to try `text

Yehonathan Sharvit22:03:11

It might live the dom element as is

clojuregeek22:03:01

yeah i already tried it that way

clojuregeek22:03:08

so i dunno! 🙂 i give up for now 🙂

Yehonathan Sharvit22:03:40

maybe after a good night of sleep, things will come up in a nicer way...

Yehonathan Sharvit22:03:26

@clojuregeek I just tried to use pygment instead of rouge in my jekyll blog and it works fine

pesterhazy22:03:37

wow, I got react-select to work

Yehonathan Sharvit22:03:02

So the issue is with the minified js?

pesterhazy22:03:11

kind of hacky though, I went around cljsjs

pesterhazy22:03:27

well using the unminified js was definitely helpful in debugging

Yehonathan Sharvit22:03:52

did you discover the root cause of the issue?

clojuregeek22:03:09

@viebel i am going to have to look at this another day but thanks for your help 🙂

pesterhazy23:03:14

because react-input-autosize/dist/react-input-autosize.js wasn't loaded

pesterhazy23:03:33

or not loaded early enough

pesterhazy23:03:18

YES, that's it, it works with cljsjs too

Yehonathan Sharvit23:03:51

whne u explicitly loads it?

pesterhazy23:03:48

that really wasn't obvious from the error though

Yehonathan Sharvit23:03:20

and in regular cljs the bug did not occur?

Yehonathan Sharvit23:03:39

Can u send the working snippet with cljs

pesterhazy23:03:32

I had to specify classnames and react-input-autosize explicitly

Yehonathan Sharvit23:03:31

And in regular cljs you don’t need to specify them?

pesterhazy23:03:59

it's specified as a dependency

Yehonathan Sharvit23:03:11

So this is a bug inside klipse

pesterhazy23:03:04

In debugging this I learned many things

pesterhazy23:03:21

how to load javascripts files using goog.net.Xhr and eval

pesterhazy23:03:27

how to load css files

pesterhazy23:03:39

the fact that unpkg is awesome

pesterhazy23:03:23

do you want me to create an issue?

Yehonathan Sharvit23:03:58

And I’d love to see a PR with your load-many function

pesterhazy23:03:52

it's kind of suboptimal because it loads js/css files sequentially

Yehonathan Sharvit23:03:57

Don’t worry about that

Yehonathan Sharvit23:03:02

we can optimize later

Yehonathan Sharvit23:03:58

Also, we need to think about the CSS

pesterhazy23:03:15

yeah I agree

Yehonathan Sharvit23:03:18

for the klipse plugin, it’s not an issue, you can add them to the page

Yehonathan Sharvit23:03:26

But the klipse app, it’s a big issue

pesterhazy23:03:27

plunkr etc have a way to add stylesheets

pesterhazy23:03:46

but that may be overkill I don't know

Yehonathan Sharvit23:03:21

Without that you cannot demo react-select at all!

Yehonathan Sharvit23:03:59

It means that you don’t need unpkg at all

pesterhazy23:03:23

hm yes I can also get it from there

pesterhazy23:03:35

still need to create a <link> tag

Yehonathan Sharvit23:03:37

(Why did you write that unpkg is awesome? Is it more than a cdn that hosts js/css)

pesterhazy23:03:56

well I think it contains everything that is in npm

Yehonathan Sharvit23:03:10

Oh! That’s great

pesterhazy23:03:41

Hence, u*npkg*

pesterhazy23:03:56

hmm that doesn't make as sense as it did in my head 🙂

Yehonathan Sharvit23:03:58

This is great news for klipse

Yehonathan Sharvit23:03:31

Think about the js klipse snippets

Yehonathan Sharvit23:03:51

We could serve any js package by just getting its name

Yehonathan Sharvit23:03:47

You could have data-js-package=d3 and boom

pesterhazy23:03:18

if they provide a standalone package in their npm bundle? (not sure I know what I'm talking about)

Yehonathan Sharvit23:03:43

who are “they”?

pesterhazy23:03:19

the author of the npm package

Yehonathan Sharvit23:03:37

Sometimes the npm package contains only the source and you need to build it

Yehonathan Sharvit23:03:29

But I think that most of the popular packages include a bundle

Yehonathan Sharvit23:03:47

And unpkg is smart:

If you omit the file path, unpkg will try to serve the browser bundle if present, the main module otherwise.

Yehonathan Sharvit23:03:59

Feel free to open an issue also for this feature (loading js package from unpkg)