helix

https://github.com/Lokeh/helix
Lucy Wang 2020-05-22T14:51:06.434100Z

@lilactown I see you've put up a project template that demos using storybook with cljs, do you have any strong reason to use storybook over devcards or https://github.com/nubank/workspaces ? (other than storybook has a nice out-of-the-box ui)

Lucy Wang 2020-05-22T14:51:25.434500Z

link to your project https://github.com/Lokeh/storybook-cljs

lilactown 2020-05-22T16:31:24.435200Z

yeah, we’re getting ready to build a design library

lilactown 2020-05-22T16:32:26.436200Z

workspaces is fine for developers, but it’s not nearly as good of an interface as a catalogue of components that e.g. a designer or PM could use

dominicm 2020-05-22T16:32:32.436300Z

I can't seem to get fast refresh working, even manually. Even though I call r/refresh! I don't see updates.

lilactown 2020-05-22T16:32:51.436600Z

@dominicm was this working previously?

dominicm 2020-05-22T16:32:55.436700Z

Nope :)

dominicm 2020-05-22T16:33:16.437100Z

this is my first attempt really

lilactown 2020-05-22T16:35:49.438700Z

I’ve run into this a few times, and the checklist I follow is: 1. have I correctly enabled the feature flag. {:helix/features {:fast-refresh true}} 2. have I injected the hook correctly by calling inject-hook! at some top-level / before app start 3. do I have the correct version of react-refresh for the version of react I have installed in my project

lilactown 2020-05-22T16:36:02.438900Z

usually it’s one of those three

dominicm 2020-05-22T16:38:34.439Z

I did just bump react.

dominicm 2020-05-22T16:39:11.439100Z

@lilactown just to check, I shouldn't be calling (mount) again right? Only refresh! now?

lilactown 2020-05-22T16:39:24.439400Z

only refresh! yes

lilactown 2020-05-22T16:39:41.439900Z

if you upgraded react to latest, make sure you bump react-refresh npm i react-refresh@latest

lilactown 2020-05-22T16:39:57.440400Z

that’s the most common reason I run into issues with it just silently not refreshing

dominicm 2020-05-22T16:40:44.441100Z

we only just added react-refresh, so definitely latest.

dominicm 2020-05-22T16:40:48.441200Z

I also did install too

lilactown 2020-05-22T16:46:56.441700Z

there should be some logging in refresh! that reports the number of components that were refreshed

lilactown 2020-05-22T16:47:47.442300Z

does that say it’s refreshing any number of components?

dominicm 2020-05-22T16:48:38.442400Z

@lilactown Yeah, updatedFamilies is of length 1

lilactown 2020-05-22T16:49:10.442700Z

so that tells me that (1) and (2) are probably working

dominicm 2020-05-22T17:00:58.442800Z

wiping target/dev/* just in case.

dominicm 2020-05-22T17:08:14.442900Z

/** @license React v16.13.1
 * react-dom.development.js
 *
 * Copyright (c) Facebook, Inc. and its affiliates.
 *
 * This source code is licensed under the MIT license found in the
 * LICENSE file in the root directory of this source tree.
 */
Okay, I'm certain I'm good

dominicm 2020-05-22T17:19:12.443Z

Hmm, I think it might not be compatible with factory components.

dominicm 2020-05-22T17:19:17.443100Z

I disabled that and it seems to be working

dominicm 2020-05-22T17:22:47.443200Z

current: helix$core$cljs_factory_$factory(varargs) vs before when it had my actual component name in

lilactown 2020-05-22T17:24:27.443400Z

ahhh hmmmm

lilactown 2020-05-22T17:30:31.443600Z

yeah yeah yeah

lilactown 2020-05-22T17:33:55.444400Z

@dominicm if you use :define-feature-flag it changes the var name of the component:

(if flag-define-factory?
                   (symbol (str display-name "-render-type"))
                   display-name)

lilactown 2020-05-22T17:34:52.445Z

but fast-refresh doesn’t take this into account:

~(when flag-fast-refresh?
            `(when ^boolean goog/DEBUG
               (when ~sig-sym
                 (~sig-sym ~display-name ~(string/join hooks)
                  nil ;; forceReset
                  nil)) ;; getCustomHooks
               (register! ~display-name ~fully-qualified-name)))

lilactown 2020-05-22T18:43:37.446100Z

per dominic’s feedback, I tried using transients instead of JS arrays for building the rows in the benchmark I linked a few days ago

1👏
lilactown 2020-05-22T18:46:33.447200Z

my simple tests show no difference in perf, which is pretty good!

cljs.user> (simple-benchmark
 []
 (s/build-data 1000)
 10)
[], (s/build-data 1000), 10 runs, 7 msecs
cljs.user> (simple-benchmark
 []
 (s/build-data-array 1000)
 10)
[], (s/build-data-array 1000), 10 runs, 7 msecs

lilactown 2020-05-22T18:47:18.447500Z

this is after warming up a few times for both

lilactown 2020-05-22T18:47:33.447900Z

at 10000 rows the JS array does pull ahead by about 10%

lilactown 2020-05-22T18:48:16.448600Z

cljs.user> (simple-benchmark
 []
 (s/build-data 10000)
 10)
[], (s/build-data 10000), 10 runs, 67 msecs
(simple-benchmark
 []
 (s/build-data-array 10000)
 10)
[], (s/build-data-array 10000), 10 runs, 62 msecs

dominicm 2020-05-22T19:30:20.449300Z

Nice :) that's good to know.

Aron 2020-05-22T22:21:06.449800Z

are you also using shadow-cljs? may I ask what are your usual bundle sizes?

Aron 2020-05-22T22:21:28.450200Z

specifically a helix project, but I also use material-ui which is not small

lilactown 2020-05-22T23:27:07.450800Z

I just did a build report of the benchmark (which is admittedly small) and it looks like this:

| Resource                              |   Optimized |  Total % |          JS |      Source |
|---------------------------------------+-------------+----------+-------------+-------------|
| npm | react-dom                       |    117.7 KB |  45.15 % |    118.4 KB |    120.2 KB |
| jar | cljs/core.cljs                  |    101.9 KB |  39.09 % |      1.2 MB |    334.4 KB |
| jar | cljs_bean/core.cljs             |     13.6 KB |   5.22 % |     75.0 KB |     21.0 KB |
| npm | react                           |      6.3 KB |   2.43 % |      6.4 KB |      7.0 KB |
| jar | helix/dom.cljc                  |      5.6 KB |   2.16 % |      7.7 KB |      1.7 KB |
| npm | scheduler                       |      4.3 KB |   1.66 % |      4.8 KB |      5.4 KB |
|     | demo/main.cljs                  |      4.1 KB |   1.56 % |     13.7 KB |      3.2 KB |
|     | demo/state.cljs                 |      3.1 KB |   1.19 % |     16.1 KB |      2.4 KB |
| jar | cljs_bean/from/cljs/core.cljs   |      1.5 KB |   0.58 % |     11.9 KB |      5.9 KB |
| jar | goog/base.js                    |    500.0 B  |   0.19 % |    139.3 KB |    139.3 KB |
| npm | object-assign                   |    461.0 B  |   0.18 % |    955.0 B  |      2.2 KB |
|     | shadow/js.js                    |    451.0 B  |   0.17 % |      2.5 KB |      2.5 KB |
| jar | helix/core.cljs                 |    319.0 B  |   0.12 % |     10.1 KB |      4.7 KB |
| jar | goog/string/stringbuffer.js     |    308.0 B  |   0.12 % |      2.7 KB |      2.7 KB |
| jar | goog/object/object.js           |    301.0 B  |   0.12 % |     23.0 KB |     23.0 KB |
| jar | helix/hooks.cljc                |    159.0 B  |   0.06 % |     13.8 KB |      7.9 KB |
| jar | goog/string/internal.js         |     40.0 B  |   0.02 % |     12.5 KB |     12.5 KB |

Nolan 2020-05-26T13:11:09.029500Z

@lilactown this is really helpful. is this output from shadow? itd make my week to know how to do this...

Nolan 2020-05-26T13:13:01.029700Z

(totally aside, very excited about the prospect of using helix. really exciting work.)

Nolan 2020-05-26T13:17:17.029900Z

found it! i had not encountered this feature of shadow—changes everything 😂

Nolan 2020-05-26T13:17:54.030100Z

🙏 thank you!!! (and thomas)

lilactown 2020-05-26T15:36:40.032700Z

sure thing! glad you found the info you needed