News for hackers. Stuff that matters.
Re:Why I don't miss React: a story about using the platform by ng12 on Tuesday May 03, 2022 @05:25PM (#31253786)
> But the web platform isn't perfect, and I suspect most React developers have come across a situation where you’d love to be able to just tweak how your component is being rendered.

Honestly, I haven't. The only potential caveat I can think of is when you have some non-reactive legacy code you want to embed inside a React component... but even then React's escape hatches are more than sufficient.

If you're really worrying about when your component renders or re-renders it's probably because there are other issues with your app.

Re:Why I don't miss React: a story about using the platform by Tarks on Tuesday May 03, 2022 @05:55PM (#31254121)
The escape hatches were one of the first things I used to explain why I initially liked react, called them exactly that too.

"They're smart enough to know they're not smart enough to build perfect abstractions, so they do a great job but leave escape hatches just in case"

Re:Why I don't miss React: a story about using the platform by quickthrower2 on Tuesday May 03, 2022 @10:50PM (#31256208)
This is why I felt out with Elm. It is harder to escape the hatches with it.
Re:Why I don't miss React: a story about using the platform by mejutoco on Wednesday May 04, 2022 @03:18AM (#31257663)
You can use the ports system and interoperate with js in Elm. I used it in the past and it is quite a clean abstraction.
Re:Why I don't miss React: a story about using the platform by bigDinosaur on Wednesday May 04, 2022 @04:08AM (#31257937)
It's frustrating that it forces you to jump into handling async code, though, in all cases. This wasn't always the case, and for good reason: sometimes async code is just vastly more complicated for no actual benefit if you can tolerate the FFI causing a crash at any calling point.

The interest in Elm took a major hit after the compiler banned use of JS.

Re:Why I don't miss React: a story about using the platform by quickthrower2 on Thursday May 05, 2022 @12:55AM (#31269631)
That is what I mean! You need static top-level declarations of every out-of-elm iteration you want to do.

React on the other hand can wrap a JQuery calendar in a React component and from a programming point of view, using that component you would be none the wiser.

Also ports force everything to be async - and I am not talking just promises - I mean a new render per call response! So calculating 1+1 on a port requires generate a new render, and intercepting the result in a Redux-style handler, bubbling that into a component.

While you won't need to do 1+1 via ports, you might need to use a synchronous web-api feature that has not been ported to elm, or even use a math package to multiply some matrices.

Re:Why I don't miss React: a story about using the platform by aliswe on Wednesday May 04, 2022 @02:14AM (#31257273)
you dont escape hatches; you escape THROUGH the hatches
Re:Why I don't miss React: a story about using the platform by quickthrower2 on Thursday May 05, 2022 @12:59AM (#31269658)
So not \h\a\t\c\h\e\s ?
Re:Why I don't miss React: a story about using the platform by nightski on Tuesday May 03, 2022 @05:45PM (#31254003)
The only case I have is I love to use D3 for vis. But the thing is it's trivial to embed D3 into a react component and either let react handle rendering via svg or honestly just let D3 take over the DOM in that component. I do this all the time and it works very well.
Re:Why I don't miss React: a story about using the platform by nawgz on Tuesday May 03, 2022 @05:56PM (#31254129)
I wrote my own React components using D3 to do the underlying math but setting up my own DOM rendering. It's ok, my thoughts

Pros:

* I have generic "zoom/pan" implemented. I did this by making a generic ChartContainer with 5 zones - top, right, bottom, left, content - and you specify just the size of the non-content zones (if displaying them at all) and otherwise it behaves responsively (i.e. CSS style on the container is respected in the internal math). When you scroll the left/content/right vertically, or the top/content/bottom horizontally, it virtually scrolls the other components for you. It also of course handles the math, each area of the 5 is passed a DOMRect describing how big of SVG it can render

* I have smart edge routing component on a graph; if you are doing the math yourself on how to position the SVG elements, you can easily describe that graph, so smart edge routing is free

* my library has themes via CSS vars, and the components written in this way are obviously automatically themed

Cons:

* it's a bit verbose for sure, takes some small time and focus. After the initial investment in ChartContainer though, they work freaking awesome

* D3 graphs often come with sweet animations and such, I don't have any capability to emulate this today, I hate to do performance-heavy things like manually doing math every frame in a hooks-based way, and I don't want MobX in my component library

* you sort of lose access to the D3 ecosystem, nothing is free

To be honest, I think I have made a top-tier Gantt with the smart edge routing and zoom, my Graph looks sharp too, and for overhead views it's super nice to be able to zoom and pan and show rulers on the side (imagine showing factory layout, or a board layout, etc). Otherwise, if you are doing more traditional pretty eye-catching stuff, it's not quite meant for that approach

Re:Why I don't miss React: a story about using the platform by cyral on Tuesday May 03, 2022 @06:18PM (#31254325)
I also went this route and used d3 for the math but my own hand-made SVGs for the rendering so that the DOM is all in "react land".

You may want to check out this library: https://airbnb.io/visx/ They converted a ton of d3 features into proper React components

Re:Why I don't miss React: a story about using the platform by davidbarker on Tuesday May 03, 2022 @08:21PM (#31255376)
I’m a huge fan of visx after discovering it a few years ago. I recently needed to create a custom line chart and looked into numerous React-based libraries but none fit exactly what I wanted, so I went back to visx again. It requires more planning, but the results you can get (just like with d3) are incredible.
Re:Why I don't miss React: a story about using the platform by nawgz on Tuesday May 03, 2022 @07:19PM (#31254849)
Nice link, thanks! I built my own axes / legends / mouseovers but this other stuff looks awesome, really nice to be able to compose their parameters too if I offer something like a line chart etc. I will definitely try to integrate some of this
Re:Why I don't miss React: a story about using the platform by nazka on Wednesday May 04, 2022 @06:48AM (#31258738)
Awesome library. I used it back when it was named Vx with react-spring and d3. You can’t beat this combo.
Re:Why I don't miss React: a story about using the platform by whimsicalism on Tuesday May 03, 2022 @06:09PM (#31254250)
Does d3 have a typescript wrapper?
Re:Why I don't miss React: a story about using the platform by eyelidlessness on Tuesday May 03, 2022 @08:13PM (#31255302)
As in a wrapper with an API more geared towards statically typed usage? Or just type definitions for the existing D3 APIs? The former is really uncommon (or at least not a particularly commonly idiom), but the latter is typically a quick search for @types/${packageName}. If that’s what you’re after, I was curious and saved you a search, because it would be quite surprising to me if something as popular as D3 was missing type defs: https://www.npmjs.com/package/@types/d3
Re:Why I don't miss React: a story about using the platform by ricardobeat on Tuesday May 03, 2022 @07:01PM (#31254709)
React doesn’t offer any render optimizations by default, so not worrying about it sounds like blissful ignorance - you’re just ignoring a ton of unnecessary renders because they don’t visibly affect performance (on your development device). After a certain level of complexity the issues will start to show.
Re:Why I don't miss React: a story about using the platform by srcreigh on Tuesday May 03, 2022 @08:24PM (#31255398)
React offers tons of optimizations for not re-rendering. useEffect, useMemo, useCallback.
Re:Why I don't miss React: a story about using the platform by mycall on Wednesday May 04, 2022 @12:36AM (#31256803)
React 18 even will have batching built into all state.
Re:Why I don't miss React: a story about using the platform by Izkata on Wednesday May 04, 2022 @07:55AM (#31259247)
"by default". You still have to use those manually.

One of the promises of switching from class-based components to function-based was supposed to be an automatically applied version of shouldComponentUpdate, which AFAIK was never fulfilled.

Re:Why I don't miss React: a story about using the platform by ricardobeat on Thursday May 05, 2022 @05:35PM (#31278660)
Not true. Even if you memoize all the values and props used, your component will still execute, generate vdom and go through reconciliation. You must use React.memo in addition to memorizing everything in order to completely prevent a no-op re-render.
Re:Why I don't miss React: a story about using the platform by 5Qn8mNbc2FNCiVV on Tuesday May 03, 2022 @07:15PM (#31254818)
What's there to optimize? If you don't use state, it doesn't rerender. If you click a button to add another element for example, it does exactly that. If you have a reactive variable in your HTML and update it it rerenders that part only. What's there to optimize further?
Re:Why I don't miss React: a story about using the platform by eyelidlessness on Tuesday May 03, 2022 @09:03PM (#31255612)
Depending on the complexity of your computations and state, what you just described can basically become unusable. For example, an app I work on implements a spec which:

- Models state as an arbitrary DAG

- With arbitrarily deep dependency chains

- Which may trigger dependent nodes based on only subsets of their state

- Based on computations of arbitrary XPath expressions, sometimes containing non-native extensions; these can be expensive whether implemented as a hybrid wrapper around native XPath or fully in userland

- Which in turn may trigger recomputation of their own dependent nodes

A naive implementation of this according to the algorithm you described will cause real world usage to block sometimes for several seconds until the app becomes responsive again.

Being able to have greater control over when to commit state and when to render intermediate state are crucial to usability for this app. Being able to defer the entire computation for state without a path to an associated view is even better. Being able to batch state -> render updates based on priority even better still. All of this can be accomplished with React’s APIs, but it certainly wouldn’t be the default behavior. And it’s all from a real world use case where SolidJS—which has a similar DX to React but significantly better performance, and which I’ve been prototyping for gradual adoption—also needs more optimization than its dependency tracking alone can achieve.

Even trivial demo apps with well designed pre-hydration state (note: already optimized beyond the default) and otherwise find performance at runtime can suffer significant lag between LCP and TTI by running far too much code for stuff that’s nowhere near needed for immediate interaction.

Granted in most cases this tradeoff is reasonably acceptable. In many cases it’s not. Prematurely optimizing it isn’t a great idea, but there’s a wealth of room for optimizing when it’s valuable to do so.

Re:Why I don't miss React: a story about using the platform by gitgud on Tuesday May 03, 2022 @10:19PM (#31256038)
> Being able to batch state -> render updates based on priority even better still.

Mobx [1] is pretty good for this, it batches updates that happen, making rendering more efficient.

Also regarding rendering, react will update a component it it's state changes. It might update its children components, but if you pass them in as props, they won't be updated, as they're rendered in the parent component's context.

This allows you to create complex applications with thousands of interactive components, and have quite good performance, as minimal rendering is performed.

[1] https://mobx.js.org/react-integration.html

Re:Why I don't miss React: a story about using the platform by eyelidlessness on Tuesday May 03, 2022 @10:56PM (#31256243)
Yep. Solid is too! Even so all of these abstractions need help when the computation itself is expensive and knowing whether to perform it is too. The ones best designed for that provide really clear APIs for how to take control where they’d otherwise handle it.
Re:Why I don't miss React: a story about using the platform by porker on Wednesday May 04, 2022 @03:07AM (#31257596)
Would love to know what the app does. From the mentions of xpath all I can think is "visual xml editor"?
Re:Why I don't miss React: a story about using the platform by eyelidlessness on Wednesday May 04, 2022 @01:49PM (#31263633)
It’s an implementation of ODK[1] extensions to the XForms specification[2]. The specific implementation is Enketo[3], which I was brought on to ODK to help maintain. Not exactly the spec I’d go with greenfield, but it’s been successfully in use for a decade with great impact.

1: https://getodk.org/

2: https://getodk.github.io/xforms-spec/

3: https://enketo.org/

Re:Why I don't miss React: a story about using the platform by bryanrasmussen on Wednesday May 04, 2022 @04:35AM (#31258079)
ideas:

could be using data returned in XML format because there is no JSON endpoint for that particular data source.

XPath is also nice for dealing with just about any complex markup tree, for example if you needed to extract data from serialized DOMs that were sent to your application somehow.

How about SVG tools using XPath?

Re:Why I don't miss React: a story about using the platform by porker on Wednesday May 04, 2022 @07:46AM (#31259182)
Thanks, great ideas and I'd never considered XPath for SVG. I need to delve into that one further.
Re:Why I don't miss React: a story about using the platform by shrimp_emoji on Tuesday May 03, 2022 @10:30PM (#31256095)
>what you just described can basically become unusable

Oh, so like every JS interface ever. :D

Re:Why I don't miss React: a story about using the platform by eyelidlessness on Tuesday May 03, 2022 @10:52PM (#31256221)
I mean, not really? My naive implementation in Solid required a few tweaks understanding the model and performs updates perceptually instantaneously on a perf sensitive input I use as a smoke test, without any of the tricks I expected to need, just its built in reactive primitives. The existing implementation performs the same computations on that data in about half a second, which feels like an eternity without special care to unblock the UI. JS is really fast. You just have to know how to use it, and when not to.
Re:Why I don't miss React: a story about using the platform by bryanrasmussen on Wednesday May 04, 2022 @02:05AM (#31257209)
Every programming language and application has the chance to become unusable, thus every JavaScript application has the opportunity to become unusable, obviously most do not because otherwise nothing would be usable on the Internet which, snark aside, things are usable even if they might annoy me.

>You just have to know how to use it, and when not to.

So, you have never had a JS application delivered over the web become unusable despite your attempts to only use it how and when you need to?

Okay, well, congratulations either or in order or you've not been forced to use it for something you didn't want to or have just never been building something big with the technology and made a mistake?

I mean my stuff generally doesn't become unusable, but generally is not always.

Re:Why I don't miss React: a story about using the platform by eyelidlessness on Thursday May 05, 2022 @01:23AM (#31269831)
> So, you have never had a JS application delivered over the web become unusable despite your attempts to only use it how and when you need to?

Of course I have, that’s not the point I was making. My point was that JS and the VMs it runs on are very fast, if you know how to use the language and when not to use it. That couldn’t possibly apply to apps you didn’t build. If I’d said C or whatever is fast if you know how to use it, I don’t think I’d get this comment about some horribly inefficient downloaded printer driver.

Re:Why I don't miss React: a story about using the platform by DiggyJohnson on Wednesday May 04, 2022 @08:09AM (#31259360)
I take your point, and can appreciate how more familiarly will lead to greater ability to address these sorts of things, but I do feel like your last two paragraphs / “caveats” could represent a massive edge case.
Re:Why I don't miss React: a story about using the platform by deepstack on Wednesday May 04, 2022 @04:24AM (#31258017)
>If you're really worrying about when your component renders or re-renders it's probably because there are other issues with your app.

that's why I prefer Solid instead of React. For client side stuff, Solid is sooo much better than React.

Re:Why I don't miss React: a story about using the platform by dvt on Tuesday May 03, 2022 @10:07PM (#31255983)
This has got to be gaslighting at the highest level: oh you're doing something wrong because that's not how you're supposed to do it in React. Not since Java's Spring have I encountered such weird zealotry for a relatively mediocre (but widely popular) framework.
Re:Why I don't miss React: a story about using the platform by mondaygreens on Tuesday May 03, 2022 @10:59PM (#31256255)
Too many folks' livelihoods depend on it at this point. The other side of the same coin is the gaslighting that you can't build anything sufficiently complex without react. If you did build it without react, it obviously wasn't sufficiently complex.
Re:Why I don't miss React: a story about using the platform by ng12 on Wednesday May 04, 2022 @12:03AM (#31256611)
I'm fairly certain you're trolling but as a good rule of thumb if you find yourself fighting your framework you picked the wrong one.
Re:Why I don't miss React: a story about using the platform by gopher_space on Wednesday May 04, 2022 @03:33AM (#31257749)
I'd suggest thinking about dismantling your framework if you've been happy with it for a bit. If you've been rewriting or authoring large chunks and disabling features it might be informative to spend a slow day looking at what you've found useful.
Re:Why I don't miss React: a story about using the platform by dmitriid on Wednesday May 04, 2022 @01:08AM (#31256955)
> Not since Java's Spring have I encountered such weird zealotry for a relatively mediocre (but widely popular) framework.

You've now described the Web Components crusade which, among other things, engages in actual gaslighting.