Fork me on GitHub
#reagent
<
2022-10-21
>
mkvlr08:10:29

running into TypeError: Cannot assign to read only property 'reagentRender' of object '#<Object>' when calling reagent.core/set-default-compiler! in node from an esm module build. Full trace in ๐Ÿงต Anybody know how else I should set this?

mkvlr08:10:44

this is my call, it works if I take it out

(reagent.core/set-default-compiler!
 (reagent.core/create-compiler {:function-components true}))

mkvlr08:10:05

node ssr.js
file:///Users/mk/dev/clerk/public/js/cljs-runtime/reagent.impl.component.js:640
(c.reagentRender = f__$1);
                 ^

TypeError: Cannot assign to read only property 'reagentRender' of object '#<Object>'
    at Object.reagent$impl$component$functional_wrap_render [as functional_wrap_render] (file:///Users/mk/dev/clerk/public/js/cljs-runtime/reagent.impl.component.js:640:18)
    at Object.reagent$impl$component$functional_do_render [as functional_do_render] (file:///Users/mk/dev/clerk/public/js/cljs-runtime/reagent.impl.component.js:660:35)
    at Object.reagent$impl$component$functional_render [as functional_render] (file:///Users/mk/dev/clerk/public/js/cljs-runtime/reagent.impl.component.js:665:31)
    at nextjournal.clerk.sci_viewer.error_boundary (file:///Users/mk/dev/clerk/public/js/cljs-runtime/reagent.impl.component.js:739:31)
    at processChild (file:///Users/mk/dev/clerk/public/js/cljs-runtime/module$node_modules$react_dom$cjs$react_dom_server_browser_development.js:46:378)
    at resolve (file:///Users/mk/dev/clerk/public/js/cljs-runtime/module$node_modules$react_dom$cjs$react_dom_server_browser_development.js:53:91)
    at _proto.render (file:///Users/mk/dev/clerk/public/js/cljs-runtime/module$node_modules$react_dom$cjs$react_dom_server_browser_development.js:123:484)
    at _proto.read (file:///Users/mk/dev/clerk/public/js/cljs-runtime/module$node_modules$react_dom$cjs$react_dom_server_browser_development.js:122:192)
    at exports.renderToString (file:///Users/mk/dev/clerk/public/js/cljs-runtime/module$node_modules$react_dom$cjs$react_dom_server_browser_development.js:148:504)
    at Function.cljs$core$IFn$_invoke$arity$2 (file:///Users/mk/dev/clerk/public/js/cljs-runtime/reagent.dom.server.js:35:57)

Node.js v18.11.0

p-himik08:10:12

> nextjournal.clerk.sci_viewer.error_boundary What's there?

mkvlr08:10:18

ah, still have a class-component here, is that the issue?

(defn error-boundary [!error & _]
  (r/create-class
   {:constructor (fn [_ _])
    :component-did-catch (fn [_ e _info] (reset! !error e))
    :get-derived-state-from-error (fn [e] (reset! !error e) #js {})
    :reagent-render (fn [_error & children]
                      (if-let [error @!error]
                        (error-view error)
                        [view-context/provide {:!error !error}
                         (into [:<>] children)]))}))

p-himik08:10:24

Not sure but slightly doubt that that's the issue.

p-himik08:10:15

And that call to set-default-compiler! is the very first thing that happens, right?

mkvlr08:10:34

yep, it works if I take that out

p-himik08:10:09

Is there a way for me to reproduce it locally without too much hassle?

mkvlr08:10:42

yes, let me push what I have

mkvlr08:10:50

do you have babashka installed? If yes, do:

git clone ; cd clerk; git checkout esm-target; bb dev

mkvlr08:10:52

also download this to the working dir

mkvlr08:10:13

confirm that node ssr.js works (outputs some html)

p-himik09:10:52

Given that condition - does it work just fine in a browser?

p-himik09:10:51

I meant the ssr.js script. Although no clue whether it's possible to run it in a browser at all.

mkvlr09:10:23

oh, just out for lunch, will try later

๐Ÿ‘ 1
p-himik10:10:15

Trying to run it in a regular way but using a source dep (without an explicit dep on clerk) and getting ReferenceError: nextjournal is not defined in the browser.

p-himik10:10:24

Ah, I probably have to use bb...

p-himik10:10:21

Aha, got it. Although, had to add (devtools/install!) to devtools.cljs.

p-himik10:10:35

Debugged it for a bit. Seems like Reagent has some hacks for its function components to work, but those have a blindspot of rendering to string + class components. Created https://github.com/reagent-project/reagent/issues/581

mkvlr11:10:10

@U2FRKM4TW oh, wow, thank you so much! ๐Ÿ™

๐Ÿ‘ 1
caleb.macdonaldblack14:10:23

Are there any docs or blog posts on how reagent works under the hood?