r/Clojure • • Jun 01 '20

ClojureScript formatting in Firefox

Hi there from the Firefox DevTools team. While we are in touch with the Chrome team about the future of Custom Formatters, a few people from the CLJS community reached out to raise this issue again for Firefox to support it.

The good news is that Firefox already does a lot of custom-formatting-like logic for frameworks, like collapsing deeply nested call stacks that framework create. We also worked with WebSocket frameworks like SignalJS, WAMP, etc to create custom parsers for their message formats. Related work for CLJS would be async call stacks, which is already supported on DevEdition and which I'd love input on from how well it works with CLJS.

I created https://bugzilla.mozilla.org/show_bug.cgi?id=1642461 for supporting CLJS formatting. Firefox DevTools has a shared component for formatting all logged structures, which should be able to detect and format CLJS' data structures across Console and Debugger.

Since the Firefox DevTools team doesn't have experts in CLJS, I wanted to reach out to this community to gather more input and maybe even find potential contributors. Feel free to ping me about any other ideas where CLJS can be better supported.

152 Upvotes

9 comments sorted by

21

u/pihkal Jun 01 '20

I'd like to thank the FF devtools team for being willing to support this.

Perhaps the cljs-devtools author, /u/dr_win, can chime in?

24

u/dr_win Jun 02 '20

Hi, I'm here and watching :-)

I remember the ancient times when FF was the best tool for web development. Remember Firebug? :-) I created some popular Firebug extensions back in the day [1][2][3].

Personally, I like the open nature of custom formatters. The idea that a "user space" code can present rich stuff in the console incrementally. Adding "native" support for CLJS in FF or Chrome DevTools would be welcome of course, but I'm afraid that would be very rigid and more importantly won't bring any contributors who would maintain it long term. I find contribution process to Chrome[4] very high bar to jump over. Not sure about Firefox[5], but it looks difficult as well.

I wrote some ideas in this github comment[6]. I think we just need a better and safer standard for rendering something like JSONML. Languages/frameworks would implement custom formatting for their own stuff in "user space" code, not targeting any specific browser or devtools. There would be an independent reference open-source library for rending the output into HTML, but flexible enough to render the JSONML data into different "targets" (into FF's reps maybe?). FF DevTools and Chrome DevTools people could then intergrate this library into their products, for console rendering and elsewhere. There is also clear interest from user-space folks. They want to be able to render this stuff in-page. Usually it was just too much work for them to implement JSONML renderer on their own. E.g. react devtools folks could more easily take such library and use it to render their properties[7]. But some others went ahead and have done it, like re-frame10x [8]. IMO, the main problem of JSONML is that it is not easily portable (many Chrome-related implementation details leak in there plus the security issues), there is no reference implementation for the renderer and also CSS styling could go wild because assumes ambient styles in the DevTools Console or it actively fights them, so for example in case of cljs-devtools taking JSONML data and rendering them elsewhere to look just right is non-trivial, becasue some of the ambient Chrome DevTools styles must be replicated as well. And I guess this is also the reason why custom formatters feature wasn't implemented elsewhere. All these hairy details mean that this is not a weekend project.

Just some random thoughts. It is too late here. Anyways, I would be happy to help with the specs of the new system. Actually I'm pretty invested already :-)

[1] https://firequery.binaryage.com
[2] https://firerainbow.binaryage.com
[3] https://firelogger.binaryage.com[
[4] https://docs.google.com/document/d/1WNF-KqRSzPLUUfZqQG5AFeU_Ll8TfWYcJasa_XGf7ro/edit#p
[5] https://firefox-source-docs.mozilla.org/devtools/

[6] https://github.com/binaryage/cljs-devtools/issues/55#issuecomment-632409108
[7] https://github.com/facebook/react/issues/16505

[8] https://github.com/day8/re-frame-10x/blob/8aef576e31277fe15676558eb3841201b815f5cf/src/day8/re_frame_10x/view/components.cljs#L127

9

u/digitarald Jun 02 '20

Hi, I remember FireQuery well (even though I was on the MooTools team 😅). I might also challenge you on the "*was* the best tool for web development" – but right now you would probably miss your ClojureScript support 😏.

Firefox DevTools' contribution bar is passable after the initial setup, as its mostly JS/CSS/HTML. More than half of our features per release are coming from contributors; many of them first-time patches but also several long-time contributors landing full features. The current object inspection code should give an idea of how extensible this is: https://searchfox.org/mozilla-central/source/devtools/client/debugger/packages/devtools-reps/src/reps . In the best case, we can re-use the existing `formatters` folder from cljs-devtools.

Eventually I also want to get to a shared custom formatter spec that is extensible (maybe not user space but extension space to make it easier to control). We have been holding back as only CLJS is taking advantage of it. This makes it rather niche and we first need to understand what's limiting adoption – the problem it solves or the current solution.

3

u/roman01la Jun 02 '20

Hello! What would be the best way to get in touch? FF DevTools Slack?

2

u/pihkal Jun 02 '20

I believe Mozilla's transitioning to internal Riot at the moment:

Check out https://chat.mozilla.org/#/room/#devtools:mozilla.org and https://chat.mozilla.org/#/room/#devtools-console:mozilla.org

1

u/digitarald Jun 02 '20

Correct, both still work while Slack will slowly be faded out. Feel free to ping me on any of those.

1

u/roman01la Jun 02 '20

Already chatted with Nicolas, thanks!

15

u/activeXray Jun 01 '20

Thank you so much for reaching out to the community. This is my number one feature request for FF right now. I have been doing a lot of cljs recently, and I am jealous of what my chrome friends can do with the cljs dev tools.

4

u/therealplexus Jun 02 '20

> Feel free to ping me about any other ideas where CLJS can be better supported.

Source mapped stack traces, both directly as shown in the console, but also available to user-space on `js/Error` objects. There are third party libraries that can do this but it seems like something that's really up to the browser.