helix

JonR 2021-09-10T19:51:13.107500Z

Hey @lilactown, when you have a sec, could explain why I see re-renders due to helix/props often in the profiler? I'm wondering if I am doing something wrong or this is expected

JonR 2021-09-10T19:51:18.107600Z

JonR 2021-09-10T19:52:29.109100Z

Also, related to our previous convo around hook tracing/debugging, I have realized that react has improved the hook tracing a bit. Reading up on the GH issues it seems that the first step is what we see now in the debugger where you can a hook index but no name yet...

JonR 2021-09-10T19:53:27.109700Z

It's not too useful though since you often end up with many hooks, some of which call other hooks, etc...

lilactown 2021-09-10T19:54:37.110100Z

are you using factory functions?

JonR 2021-09-10T19:54:38.110200Z

e.g.

JonR 2021-09-10T19:55:02.110900Z

I am not sure actually, I didn't make our defnc macro. Let me double check

lilactown 2021-09-10T19:55:16.111200Z

how do you create an element out of a component?

lilactown 2021-09-10T19:55:27.111500Z

($ foo) or (foo)?

JonR 2021-09-10T19:56:57.111800Z

(defmacro defrc
  [type params & body]
  (let [[docstring params body] (if (string? params)
                                  [params (first body) (rest body)]
                                  [nil params body])

        ; Handle an optional map of options to toggle feature flags
        opts? (map? (first body))
        opts (if opts?
               (first body)
               {})
        body (if opts?
               (rest body)
               body)

        ;; feature flags to enable by default
        default-opts {:helix/features
                      {:fast-refresh true
                       :define-factory true}}]

    `(helix.core/defnc ~type ~@(when docstring [docstring]) ~params
       ; `merge` to allow consumers to override feature flags in special cases
       ~(merge default-opts opts)

       ; Wrap the body in html macro to convert hiccup to react components
       (sablono.core/html (do ~@body)))))

lilactown 2021-09-10T19:57:43.112200Z

gotcha, ok

lilactown 2021-09-10T19:58:08.113Z

when you see re-renders due to helix/props it means that new props were passed in

lilactown 2021-09-10T19:59:29.114400Z

the way that factory functions work is:

(foo {:foo "bar})
is equivalent to
(react/createElement foo #js {"helix/props" {:foo "bar"}})

JonR 2021-09-10T20:00:09.114600Z

ok

JonR 2021-09-10T20:00:37.115100Z

hmm... I'm seeing that on a component which has one prop and the data isn't changing...

lilactown 2021-09-10T20:01:07.115600Z

react (and helix) will re-render your component anytime its parent is rendered by default

lilactown 2021-09-10T20:02:26.116100Z

are you wrapping the component in helix.core/memo?

JonR 2021-09-10T20:03:18.116700Z

no, I'm trying to heed the warnings of not over memoing unless needed. Maybe I need to though?

JonR 2021-09-10T20:03:35.117100Z

The debugger says when re-render is due to the parent re-rendering and I'm not seeing that on most of these

lilactown 2021-09-10T20:04:28.117400Z

if props are changing the someone must have changed it 😛

JonR 2021-09-10T20:05:31.117800Z

I think that someone is me obviously 🙂

JonR 2021-09-10T20:06:30.118100Z

Thanks for duckie ing

lilactown 2021-09-10T20:06:54.118300Z

yeah i hope it helped