Live data from Hacker News

Beyond React 16 by Dan Ambramov – Async Rendering and React Suspense

youtube.com

51–60 of 66 posts

Re: Beyond React 16 by Dan Ambramov – Async Rendering and React Suspense

#51
post #3

So glad someone captured this talk! At the 15 minute mark, he introduces a new paradigm for asynchronous IO within render functions; see a screenshot here: https://www.dropbox.com/s/wybqgtftuyqipk8/Screenshot%202018-... . This is groundbreaking, to say the least, as previously this needed to be done by adding higher-order components to inject the result of the fetch as a prop at some higher level; now, it's as simple…

> throws a promise

> ...

> It's...promising to say the least!

^ this guy :finger_guns:

Re: Beyond React 16 by Dan Ambramov – Async Rendering and React Suspense

#52

Earlier quoted context omitted.

What do you think is so painful about styling in React? Genuinely curious. The scoping of stuff? The organization?

There are basically 3 options, and they all have really big downsides: * CSS modules - can use any CSS preprocessors, fast, can be extracted into CSS files, but it's very hard to "theme" and very hard to style/modify 3rd party components. * Css-in-js - uses Js to render, using preprocessors is much more difficult, can't easily extract into CSS files, somewhat easier to theme and share. * Inline styles - even slower,…

Isn't the whole point of CSS-in-JS that you don't need a toy language to do preprocessing if you have a real language like JavaScript?

I haven't really used SASS et. al., but my understanding is that they were hacks to get shared constants, functions, and derived values in a CSS that predated custom properties.

Re: Beyond React 16 by Dan Ambramov – Async Rendering and React Suspense

#53
post #13

FYI: A higher quality version of this video is on the React blog at https://reactjs.org/blog/2018/03/01/sneak-peek-beyond-react-... .

I certainly understand the bias to host it on your own infrastructure, but I really appreciate that I can download from YouTube for offline viewing on the metro. Couldn't find a way to do that with the official version.

Re: Beyond React 16 by Dan Ambramov – Async Rendering and React Suspense

#54
post #13

FYI: A higher quality version of this video is on the React blog at https://reactjs.org/blog/2018/03/01/sneak-peek-beyond-react-... .

I certainly understand the bias to host it on your own infrastructure, but I really appreciate that I can download from YouTube for offline viewing on the metro. Couldn't find a way to do that with the official version.

That's really helpful to know for the future, thanks! We didn't have a strong preference so ended up with FB.

Re: Beyond React 16 by Dan Ambramov – Async Rendering and React Suspense

#55

I’m pretty excited to see how the api could interop with some new native features of js, like for ex async class functions are now possible and I bet a setup like this could remove a lot of IO overhead in the future class Test { async render() {} } Kind of hard to come up with a concrete use-case with how little we know about the new features. Still super interesting though!

Interop with language feature is definitely a thing. It helps people to understand a tool without the need of digging into implementation details, since those details are language features that developers already familiar with.

There is a way to do this kind of things with current React version (16.2): https://github.com/alexeyraspopov/react-coroutine

You can use generators, async functions, and even more, async generators. Worth checking examples in the repo.

Re: Beyond React 16 by Dan Ambramov – Async Rendering and React Suspense

#56

I’m pretty excited to see how the api could interop with some new native features of js, like for ex async class functions are now possible and I bet a setup like this could remove a lot of IO overhead in the future class Test { async render() {} } Kind of hard to come up with a concrete use-case with how little we know about the new features. Still super interesting though!

Interop with language feature is definitely a thing. It helps people to understand a tool without the need of digging into implementation details, since those details are language features that developers already familiar with. There is a way to do this kind of things with current React version (16.2): https://github.com/alexeyraspopov/react-coroutine You can use generators, async functions, and even more, async gene…

Nice, awesome work!

Re: Beyond React 16 by Dan Ambramov – Async Rendering and React Suspense

#57
post #3

So glad someone captured this talk! At the 15 minute mark, he introduces a new paradigm for asynchronous IO within render functions; see a screenshot here: https://www.dropbox.com/s/wybqgtftuyqipk8/Screenshot%202018-... . This is groundbreaking, to say the least, as previously this needed to be done by adding higher-order components to inject the result of the fetch as a prop at some higher level; now, it's as simple…

This seems to me like a workaround for the fact that React requires `render` methods to return React elements. And I suppose it also takes advantage of the fact that the `read` method can `throw` its way out of your `render` function, obviating the need to check its result and manually `return`. But not gonna lie, I'm pretty suspicious of overreliance on creative use of `throw`ing as something that is going to cross through application code's control flow. But perhaps it will prove convenient enough to be worth it.

Re: Beyond React 16 by Dan Ambramov – Async Rendering and React Suspense

#58

Earlier quoted context omitted.

There are basically 3 options, and they all have really big downsides: * CSS modules - can use any CSS preprocessors, fast, can be extracted into CSS files, but it's very hard to "theme" and very hard to style/modify 3rd party components. * Css-in-js - uses Js to render, using preprocessors is much more difficult, can't easily extract into CSS files, somewhat easier to theme and share. * Inline styles - even slower,…

Isn't the whole point of CSS-in-JS that you don't need a toy language to do preprocessing if you have a real language like JavaScript? I haven't really used SASS et. al., but my understanding is that they were hacks to get shared constants, functions, and derived values in a CSS that predated custom properties.

But with the downside of basically replicating a lot of what the CSS engine does in Javascript, further polluting the already stressed "main" thread in many JS applications. And doing it in a slower, less battery efficient, and less cacheable way.

And in my opinion, a language like SASS isn't a "hack" but is a very specific and extremely powerful language which is dedicated to one use (styling) and therefore most styling-specific code is very natural with SASS, however with JS it gets more difficult (want to extend another style defined elsewhere? You kind of need to work with JS that wasn't really designed to make that an easy task, in SASS it's `@extend %other-class`)

Re: Beyond React 16 by Dan Ambramov – Async Rendering and React Suspense

#59
post #42

So if I understand it correctly, anything after this line inside the render... const movie = movieDeatailsFetch.read(props.id); ... ... will block rendering and will defer to a parent component to render instead? Interesting magic I'd say, since I wouldn't expect such a line to block my rendering. Wouldn't it be a more "React way" to have HOC component or a render prop that would work exactly like this .read() API? {…

>will block rendering and will defer to a parent component to render instead?

Yes, but only after the delay period passes. Before that, nothing will happen on the screen (at least not until I add an inline spinner as one of the last steps). Preventing a spinner from appearing and instantly disappearing on fast connections is exactly what this feature enables.

>Interesting magic I'd say, since I wouldn't expect such a line to block my rendering.

It works by throwing a Promise (and React catches it and waits for it before retrying rendering). So it’s not really magic, just an unfamiliar pattern. Conceptually this is similar to algebraic effects in languages that have them.

>Wouldn't it be a more "React way" to have HOC component or a render prop that would work exactly like this .read() API?

No. If you watch the demo closely you’ll notice we don’t show the spinner if the load is fast enough. React prevents updating the whole tree. This is impossible to express with a HOC without reimplementing the whole React in it.

>There's lots of magic, especially in the IO part, and would've loved if he went more into detail on how it's actually done - it's a JS-conf afterall.

As I said earlier the actual mechanism is quite straightforward. We throw and later React retries.

We’ll be posting an RFC with details. But for now we felt it was important to motivate this work, and even the motivation barely fit into 30 minutes.

>Observables might be a more interesting abstraction for IO-kind of things.

The core purpose of this feature is to suspend rendering until data is ready to avoid flicker and things jumping around. You can use observables in your code but I’d argue that, save for a few use cases, having components jump around as new items “come in” is a janky experience. You can always build a Promise interface that coalesces those observable updates into Promises of a final list before rendering.

>Also, testing this seems rather complex since the render is effectively doing a side-effect.

I actually think testing will get easier because now you can wrap your tree with a fake cache in tests. Then even components that do data fetching won’t attempt to reach the real network.

>Also, how's race-conditioning done? Does the fetcher library have the logic to only render the last fetcher, or is it more complicated than that?

The fetcher library doesn’t have much logic. It’s basically a cache backed by two Maps (for pending and resolved data).

React just retries rendering after Promise has resolved (or re-render happened due to another reason, like prop change). So there is no need for explicit logic handling race conditions. Instead of keeping continuations “in flight” we just abort rendering and retry when data is ready. So there’s nothing to race for.

Re: Beyond React 16 by Dan Ambramov – Async Rendering and React Suspense

#60
post #50
post #34

Earlier quoted context omitted.

Wow, I never would have considered throwing anything other than an Error. On the face of it, this seems like an incredibly powerful technique, but is it an abuse of a language feature?

Python “abuses” exceptions in a similar way every time you iterate over a generator: https://softwareengineering.stackexchange.com/questions/1124... At the end of the day it’s just a control flow mechanism. And theoretically, if you lack data needed to render, it’s an exceptional condition.

It's a very interesting technique; I will definitely be keeping an eye out for appropriate use cases.
Post reply on HN