react

"mulling over state management stuff"
orestis 2020-05-07T18:50:31.486200Z

Having a blast with concurrent mode. Heads up - the latest builds prefixed everything with unstable_ because apparently people are already using this in libraries with polyfills 🤦

😂 2
orestis 2020-05-07T18:51:50.487800Z

I need to find some demo code that would exhibit tearing without useMutableSource just to see what it looks like. Hard to evaluate this stuff in trivial apps.

Aron 2020-05-07T18:53:23.490100Z

@orestis can you help me a bit with my experiment? : )

Aron 2020-05-07T18:53:38.490800Z

https://github.com/ashnur/sierpinski-cljs-fiber-demo this one

orestis 2020-05-07T18:54:55.493Z

One very very very interesting pattern which emerges is the useTransition hook. You are supposed to wrap state changes that will trigger a suspense with this. They demo this by putting in directly in a click handler, but that seems the wrong place. But dispatching a reframe-like event feels also the wrong place to deal with that, if you’re doing sync state updates as I’m doing. So it feels like the event router needs to know which events might trigger suspense.

orestis 2020-05-07T18:55:47.494600Z

I think I need to build a proper application with this to get a proper feeling. Any suggestion public APIs I can use to get interesting dummy data and images is welcome.

lilactown 2020-05-07T18:56:16.495400Z

the app I’ve been using to experiment is a hacker news reader

lilactown 2020-05-07T18:59:03.498400Z

in the spirit of https://hnpwa.com/

orestis 2020-05-07T18:59:49.499900Z

@ashnur I have a holiday long weekend ahead with family stuff so no promises :) one obvious thing I see is that you’re calling render on the root to step forward the simulation. That seems wrong (though I’m not sure). I’d use a useEffect on the top level component to start the loop and a setState call to let React rerender as needed.

Aron 2020-05-07T19:02:56.001200Z

I just need someone to check for obvious mistakes why the code is slow

orestis 2020-05-07T19:03:09.001800Z

@lilactown meh, hacker news :) in this period I want something with baby goats

😂 1
lilactown 2020-05-07T19:03:18.002Z

hahahaha fair

orestis 2020-05-07T19:13:46.002600Z

Baby goat api in google doesn’t give promising results :)

orestis 2020-05-07T19:14:00.003Z

@ashnur see above, that’s the first thing I’d try.

Aron 2020-05-07T19:14:12.003200Z

thanks

Aron 2020-05-07T19:14:57.003800Z

afaik, calling render on the root should not make a difference compared to calling this.setState on the root

Aron 2020-05-07T19:15:12.004500Z

and the original was written in this style exactly

orestis 2020-05-07T19:15:13.004700Z

Some context in what you trying to test might be useful :)

Aron 2020-05-07T19:15:35.005100Z

I just want to make the demo go fast at this point in time : D

orestis 2020-05-07T19:17:10.006700Z

Yeah but for what? Testing CLJS performance, react performance? CLJS will be always slower than JS for sure. By how much, well, 🤷

Aron 2020-05-07T19:20:43.010400Z

Ok, I think I understand your question. It's a series, one built on the other. First, I subscribed very early on CM and would like to know if it is still as good as it was in 2016, so I would like to see the same performance benefits demonstrated with latest experimental code, otherwise it might've been a one time fluke. Second, I also believe that most of the performance, if React is still as good as it was 4 years ago, comes from the reconciler and I should be able to just feed global state to it without slow down, but this will require custom code that I need to still write, after the first step is over. Third, well, that's even more work, it involves a lot of specs.

Aron 2020-05-07T19:21:59.011700Z

The sierpinski stuff shouldn't be any slower even in cljs, I don't know anything that would warrant it. Sure, if I use complex datastructures then the overhead might be significant, but that's a question for future me.

orestis 2020-05-07T19:24:24.013400Z

Ok that makes it clearer :) I’m on my phone so can’t do much analysis. Why are you creating fragments around the children of the triangle? Wouldn’t passing in the text as a prop make things clearer?

orestis 2020-05-07T19:24:41.013800Z

I mean you probably don’t need fragments anyway

Aron 2020-05-07T19:24:51.014100Z

good point

orestis 2020-05-07T19:25:16.014900Z

I haven’t used helix yet so I can’t comment much more without actually running the code locally...

Aron 2020-05-07T19:25:35.015200Z

oh, I thought you had, sorry about that

orestis 2020-05-07T19:26:04.015800Z

What’s the js version look like? Perhaps something will jump out on direct comparison.

Aron 2020-05-07T19:26:36.016400Z

in the public dir, there is fiber.html that has the original version, but you can check it here too https://claudiopro.github.io/react-fiber-vs-stack-demo/

Aron 2020-05-07T19:27:46.016900Z

original returned an array, but I don't know if I can just do (vector ($) ($) ($))

Aron 2020-05-07T19:28:39.017200Z

as for the children, I probably was too tired

orestis 2020-05-07T19:30:51.018600Z

That fiber is probably using a much older version of React. You need to wrap the three returned triangles in a fragment, but their children shouldn’t be wrapped in a fragment.

orestis 2020-05-07T19:31:29.019700Z

In the fiber demo the triangles use key (left right center) which can impact performance greatly.

orestis 2020-05-07T19:32:41.021200Z

Finally I’d double check the memo wrap - not sure if it works out of the box, I’d add some debugging there to see what it does.

Aron 2020-05-07T19:33:40.021600Z

it doesn't appear to do anything. You are right about the keys, I forgot to add them

Aron 2020-05-07T19:34:48.023300Z

what I don't understand is the createRoot thing, I am afraid I still re-create it too often. Because at every update for the text in the dots, the animation freezes a bit, exactly like in Sync/Legacy mode

orestis 2020-05-07T19:34:52.023500Z

I was just reading about keys in react, I always thought it’s just for arrays but apparently not. https://kentcdodds.com/blog/understanding-reacts-key-prop

Aron 2020-05-07T19:35:14.024Z

yeah, it's a bit like the order for hooks

orestis 2020-05-07T19:36:36.025Z

You only create the root once. I think I saw warning when calling render multiple times, might be a recent thing.

orestis 2020-05-07T19:36:51.025400Z

Recent: today’s experimental build.

Aron 2020-05-07T19:37:58.025900Z

dunno, I have code to check if the root doesn't exist so I can create it again, I think 😄

Aron 2020-05-07T19:38:17.026400Z

let me check again, I just started

orestis 2020-05-07T19:39:07.027600Z

I might remember wrong. I need to log off now. If I have time over the long weekend I might play around.

Aron 2020-05-07T19:39:47.027900Z

thanks for helping out!

Aron 2020-05-07T20:23:23.028600Z

well, if what I got now is not tearing, I don't know what 😄 I have two versions rendered at once, both wrong

alidlorenzo 2020-05-07T20:45:07.028700Z

yea this has saved me a few times in cases where components were poorly composed and had to make sure they rerender

Aron 2020-05-07T20:48:14.029300Z

so, I cut some corners too early, I should update my code

Aron 2020-05-07T20:48:30.029800Z

but, good news, I found it in the official repo https://github.com/facebook/react/blob/master/fixtures/fiber-triangle/index.html bad news, 2 years old 😄

Aron 2020-05-07T22:45:25.030800Z

so, one thing is sure, you can still block react experimental while using createRoot API, more than one way. With the old API afaik you could block the window but not react