News for hackers. Stuff that matters.
Re:React Concurrent Mode by danabramov on Thursday October 24, 2019 @05:16PM (#21349265)
While this page went to the top, I see a lot of comments that show people haven’t seen the other pages.

I know it’s a lot to ask. But this really is a different programming model. It takes some time to see what it allows.

I spent the last 48 hours documenting it. Here are the most important two pages:

1. https://reactjs.org/docs/concurrent-mode-suspense.html

2. https://reactjs.org/docs/concurrent-mode-patterns.html (especially this one!)

It would mean a lot to me if you could go through both of them (including the examples) before forming a final opinion. Thank you.

Re:React Concurrent Mode by andrewstuart on Thursday October 24, 2019 @09:11PM (#21350845)
Thanks to Dan and the React team - great work as always.

The most useful thing to provide with this would be a small self contained example of the absolute core of all web programming - a form that gets data, submits it to the back end, and then displays a list of records. Nothing more. Super simple. All web development knowledge derives from this start point - for me anyway.

This is what underpins all web development and when I come into a new approach like this I always aim to implement that basic display/submit/list form workflow.

It would be SO helpful if that existed as a small standlone application.

The profile stuff is in the right direction but not it.

When there is not a basic example of that exact workflow then the cognitive load instantly skyrockets because I now need to work out how to do that and even then I don't know if I got it right because it's my guess using a technology I do not understand. So much better for the technology designers to show how to do the core of all development "the new way". Ideally with a standard form and not graphql.

Re:React Concurrent Mode by danabramov on Thursday October 24, 2019 @11:29PM (#21351609)
It’s a bit tricky because as the docs explain, the only Suspense integration we currently use in production is Relay. I definitely agree we need a complete Relay example that people can run (maybe Relay docs have one already?). But a lot of people don’t know Relay so it would be hard to teach both new UI patterns like useTransition and Relay at the same time. This is why we didn’t do it in the main docs.

How a form would work really depends on how your data solution manages a cache. Relay has one answer for that, some other solution may have completely different answers. So I wanted to keep the first examples simpler and less opinionated.

As more libraries start to integrate Suspense I think you’ll see more such complete examples. But this release wasn’t for the end users as much — it was more for people who would create those libraries.

Hope that makes sense.

Re:React Concurrent Mode by kylehardgrave on Friday October 25, 2019 @03:41PM (#21358518)
Maybe I just missed this, but I couldn't find any kind of guidance for library maintainers on implementing Suspense. Reading the demo code + React-Cache it seems that it's basically about providing an interface that throws unresolved promises, but is there any more detailed documentation?
Re:React Concurrent Mode by danabramov on Saturday October 26, 2019 @10:23PM (#21367525)
We'll likely add more documentation about this -- however, indeed, the contract fits in those 10 lines. There's not much more that's needed on the integration side.

The real questions (where and for how long do you cache, what triggers are fetch, how to avoid waterfalls) are something that the library itself is better positioned to answer and figure out. We don't have a particular suggestion there (although the docs mention our recommendation).

Re:React Concurrent Mode by PKop on Friday October 25, 2019 @08:26PM (#21360602)
> depends on how your data solution manages a cache

> But this release wasn’t for the end users as much — it was more for people who would create those libraries.

Where is the documentation to create these libraries (cache integration, etc)?

Re:React Concurrent Mode by danabramov on Saturday October 26, 2019 @10:25PM (#21367530)
Every example on those pages has a reference toy implementation in `fakeApi.js`. You can use it as a base -- that's the whole contract that React cares about. We'll describe it in more detail later.
Re:React Concurrent Mode by PKop on Sunday October 27, 2019 @01:01PM (#21370917)
Thanks a lot Dan
Re:React Concurrent Mode by eropple on Thursday October 24, 2019 @09:39PM (#21351003)
This is one of the real bummers about the growth of the "ToDoList" app as the "Hello World" of these frameworks. It's really important to demonstrate backend communication.
Re:React Concurrent Mode by jpochtar on Thursday October 24, 2019 @10:26PM (#21351267)
Rails is probably a better fit for your needs. If you're primarily concerned with sending forms to and showing data from a server, React isn't going to give you much.

React is great for Figma, Dropbox Paper, Coda, and Pagedraw: apps that are basically entirely local, and may or may not happen to be syncing with a server in the background.

CRUD is a special case of app, and the modern HTML/CSS/JS browser is pretty well tailored to handle all the needs for the client side of one. Maybe sprinkle in some Turbolinks [1] if you want some fancier page transitions.

It'll take time before someone makes a good CRUD framework on top of React. Until then, Rails is a great CRUD framework, and isn't missing much I'd expect to see React solve.

[1] https://github.com/turbolinks/turbolinks

Re:React Concurrent Mode by egeozcan on Friday October 25, 2019 @01:48AM (#21352235)
If you're not living in a first world country (or living in Germany lol), you usually don't have a stable internet connection. I've developed a lot of CRUD apps that are core to many businesses on field and without ServiceWorkers (or the manifest based appcache before) and client side databases that are better suited to use from SPAs, I'd rarely have success in any of those projects.

You don't really need a framework for this. Forms are incredibly easy to handle from React. A framework for declaratively caching relational data with server side components (like poachdb but for SQL server) would have been amazing though.

I don't know Turbolinks enough but it doesn't help with the connection problems I assume?

Re:React Concurrent Mode by d_k_f on Friday October 25, 2019 @02:14AM (#21352370)
No, it does not. Turbolinks keeps a local cache of previously visited pages so transitions to those seem instantaneous, but this is session-only and can't be populated in advance.
Re:React Concurrent Mode by nightnight on Friday October 25, 2019 @12:05AM (#21351772)
From your second link:

> if we switch from one page to another, and none of the code or data for the next screen has loaded yet, it might be frustrating to immediately see a blank page with a loading indicator.

IDK what's the best or most accepted UX. But my gut feeling says an instant transition to the new page with light grey pulsating placeholders rectangles for the still to load contents gives the highest user satisfaction. This feels super responsive and is learned by the users for years (and it's perfectly do-able just with Suspense).

So, I wonder if the solution of clicking, seeing no change but a small loading sign or spinner next to button till the page really is transitioning is actually that more responsive/satisfying? I really don't think so, it rather makes the app feel more sluggish, reminiscent of the old days with server-rendered pages and not feeling like a actual SPA.

This is of course debatable but are there any other significant/killer use cases React Concurrent makes possible? I don't want to sound snarky but I've the feeling Concurrent is a solution with a slick name searching for a problem. I hope I am wrong.

Edit: To the pro downvoter, just try to articulate your thoughts and contribute to a discussion than pure downvoting

Re:React Concurrent Mode by danabramov on Friday October 25, 2019 @02:33AM (#21352463)
As the page mentions, we actually do move to the Skeleton state (which you’re describing) as soon as it’s possible.

We’re only delaying the transition for as long as we have nothing good to show at all. When we have a decent loading state, we immediately transition to it.

I do recommend you to play with it more in a tiny project.

Re:React Concurrent Mode by nightnight on Friday October 25, 2019 @04:46AM (#21353040)
> Skeleton state

There is a name for this? Didn't know.

> I do recommend you to play with it more in a tiny project.

Ok, will do.

Re:React Concurrent Mode by danabramov on Saturday October 26, 2019 @10:27PM (#21367537)
>There is a name for this? Didn't know.

Yes, and it's described here: https://reactjs.org/docs/concurrent-mode-patterns.html#the-t...

Re:React Concurrent Mode by sktrdie on Thursday October 24, 2019 @05:57PM (#21349618)
Hi Dan! Thanks for the great work. I wanted to discuss a few use-cases where React's new runtime model makes things less predictable:

* Suppose you want a :hover CSS selector to be applied at the same instant as a state change triggered by that hover. It's no longer reliable. Hence you're stuck with having to change the DOM in response to the state change to match a different selector.

* The browser may often set component state via its own behavior. (Small contrived ex: setting the scrollTop position of an inner element based on tabbing to a link.) Pretending that virtual DOM represents DOM, especially at X time, can get you in a lot of trouble.

How would you deal with these contrived (yet realistic) examples?

Re:React Concurrent Mode by danabramov on Thursday October 24, 2019 @06:08PM (#21349696)
>Suppose you want a :hover CSS selector to be applied at the same instant as a state change triggered by that hover. It's no longer reliable. Hence you're stuck with having to change the DOM in response to the state change to match a different selector.

Not sure I understand the problem. Can you make a CodeSandbox demo? That said you can always wrap an update in `ReactDOM.flushSync(() => { ... })` to force it to run synchronously. But I'm not sure I understand the scenario or which problem you're referring to without a concrete example I could run.

>The browser may often set component state via its own behavior. (Small contrived ex: setting the scrollTop position of an inner element based on tabbing to a link.) Pretending that virtual DOM represents DOM, especially at X time, can get you in a lot of trouble.

I don't understand what this means. Again, a concrete demo would help ground the conversation. I think you might have some flawed assumptions about what React does, but I can't tell for sure because I don't understand what you're saying.

Thank you!

It's worth saying we've been using Concurrent Mode in production for about a year now. There are some snags we still need to solve, but they don't sound a lot like what you're describing.

Re:React Concurrent Mode by tarjei on Friday October 25, 2019 @03:59AM (#21352806)
Hi, the docs are great - and cover a lot of ground.

The React team is doing amazing work!

Two questions / inputs:

1. Are the "Progressive Hydration" and "Selective Hydration" related to SSR? I could not find any info on what functionality is hiding behind the terms.

I've been wondering about how selective hydration could work with SSR.

2. In general I often find it hard to navigate the API part of the React docs - for example to find the definition of a lifecycle method (for example componentDidUpdate). There is no fast way to get to a single method.

I think this might be because the pure API docs feel a bit mixed into the rest of the documentation and therefore read more as complete articles than single packets of information.

Re:React Concurrent Mode by danabramov on Saturday October 26, 2019 @10:27PM (#21367534)
>1. Are the "Progressive Hydration" and "Selective Hydration" related to SSR? I could not find any info on what functionality is hiding behind the terms.

Yea. We'll need to expand the docs on this. Progressive Hydration means React won't block the thread while hydrating HTML. Selective Hydration means you can tell React to prioritize hydrating a particular subtree (e.g. because the user interacted with it).

>2. In general I often find it hard to navigate the API part of the React docs - for example to find the definition of a lifecycle method (for example componentDidUpdate). There is no fast way to get to a single method.

I'm not sure what this means. If I type "componentDidUpdate" in top right search bar, it jumps directly to it.

Re:React Concurrent Mode by wjmao88 on Thursday October 24, 2019 @11:06PM (#21351478)
Hi Dan, this is great and I really like this. But, I think what made me appreciate this is mostly your algebraic effects blog post. My issue with the examples in the reactjs doc pages is that it compares a naive and (intentionally)buggy implementation to a working implementation, so to evaluate the benefits I have to mentally fix the buggy version with existing react and compare that to the working version. It would be easier to see the difference if it could have a working implementation with current react to compare to the implementation with concurrent react.

Also, I'd love to read something about why throwing promises was chosen over other possibilities.

Re:React Concurrent Mode by danabramov on Thursday October 24, 2019 @11:33PM (#21351628)
There is more than one way to fix the buggy versions, so if we compared with a particular non-buggy version, people would complain we didn’t compare with their preferred fix. But that’s fair feedback.

Regardless of the comparison, the features described on the “Concurrent UI Patterns” as the real deal. The “old” ways of doing things don’t allow to do any of them as expressively.

Re:React Concurrent Mode by daxaxelrod on Thursday October 24, 2019 @05:34PM (#21349435)
I'll be reading these on the subway home. Thanks for all that you've done!!
Re:React Concurrent Mode by coldfire on Friday October 25, 2019 @12:43AM (#21351961)
great writeup! Very easy and to the point. But if I have to suggest something (and I'm just nitpicking here), an example/section summarising everything at the end would've been the "icing on the cake". May be because I read the entire three pages in one go, I got a bit lost in the "Concurrent UI Patterns" examples, primarily when to use `useTransitions`, `useDeferredValue`, `Suspense` and various anti-patterns/edge cases that the examples mentioned :)
Re:React Concurrent Mode by nightnight on Thursday October 24, 2019 @11:36PM (#21351636)
@Dan, fyi, useTransition is already used as a hook name by the quite popular react-spring animation lib. I mean, I can migrate old code bases to import { useTransition as useSpringTransition } or I just import yours as { useTransition as useReactTransition }.

Not a big thing but also not really elegant. How would you deal with this?

Re:React Concurrent Mode by danabramov on Friday October 25, 2019 @02:30AM (#21352452)
Yeah that’s kind of unfortunate. Unintentional. I think one of us will have to rename.
Re:React Concurrent Mode by wayneftw on Friday October 25, 2019 @10:53AM (#21355576)
You only have to rename if people import each hook separately.

I prefer to use React.useWhatever(); so I don’t have to keep going to the top of the file and importing new things.

Is my preference wrong? Much of the code that I see online does not use my preference...

Re:React Concurrent Mode by alfonsodev on Thursday October 24, 2019 @05:31PM (#21349412)
Thanks a lot for taking the time to write this up, it really makes a difference.
Re:React Concurrent Mode by johnfn on Thursday October 24, 2019 @05:49PM (#21349557)
Thanks, Dan. You’re a hero!