No video

React Compiler: In-Depth Beyond React Conf 2024

  Рет қаралды 77,143

Jack Herrington

Jack Herrington

Күн бұрын

Is the React Compiler the most advanced frontend compiler? Let's dig in and see just what it's doing to our code!
Compiler REPL: github.com/jherr/compiler-repl
Meta REPL: playground.react.dev/
Rules of React: react.dev/reference/rules
👉 Upcoming NextJS course: pronextjs.dev
👉 Don't forget to subscribe to this channel for more updates: bit.ly/2E7drfJ
👉 Discord server signup: / discord
👉 VS Code theme and font? Night Wolf [black] and Operator Mono
👉 Terminal Theme and font? oh-my-posh with powerlevel10k_rainbow and SpaceMono NF
00:00 Introduction
00:26 Simple Compiler Examples
03:53 Getting Under The Hood
06:36 This is a COMPILER
07:23 Is This Too Far?
08:57 Removing useMemo/useCallback
09:25 Safe Fallback
11:23 Fixing useEffect?
12:59 Key Takeaways
14:20 Outroduction
Logo by @sawaratsuki1004

Пікірлер: 239
@cooldude3010
@cooldude3010 3 ай бұрын
Thanks for making high quality indepth videos! I know this kind of content takes a lot of time.
@jherr
@jherr 3 ай бұрын
Thank you.
@ISKLEMMI
@ISKLEMMI 3 ай бұрын
Thanks for the video! I'm really glad to see 'React Forget' coming close to a usable state. React's use of stateful render functions for its components (vs Solid's constructor functions) makes the framework inherently less performant, but kudos to the folks on the React team, who are obviously making a monumental effort to close that gap. Being able to write less crazy workaround code is going to be a real boon.
@incarnateTheGreat
@incarnateTheGreat 3 ай бұрын
Lol Mobx getting the shaft. Thanks for the video and, specifically, the compiled explanations. I'm glad the React team has done their due diligence by making the great leap into compiler world. Always appreciated it as a DOM library, but we all gotta change sometime.
@TJVanToll
@TJVanToll 2 ай бұрын
Good stuff Jack! Love the technique you’re using to highlight individual sections of code.
@monnicore5245
@monnicore5245 3 ай бұрын
Love all your videos, been watching for a couple years now. Your key takeaways in this video answered my concerns with MobX! Keep up the awesome work Jack !
@riddixdan5572
@riddixdan5572 3 ай бұрын
oh god, I can already imagine so much of our code breaking because we do some dumb usememos where we want to recompute the value only when one of the 2 values changes.
@sealone777
@sealone777 3 ай бұрын
Amazing! I had to use why-did-you-render for this. Hope they include some debug mode for unnecessary rendering tool.
@YasinAkimura
@YasinAkimura 2 ай бұрын
This is huge! I am somehow worried but I think the compiler is great but I also think it takes alot from beginners where you have to learn that this can't work if the ref is changing and why it's changing. Also we need to keep in mind that there is a bunch of stuff happening in the background I'd say because react was and still is just JavaScript using all its rules but now some things get hidden so some could get a dumb down effect where they will wonder why its not working. So we need to encourage people to still write good structured code I think this will benefit my react native projects too. I am worried that too much caching might push the memory usage of the apps but I think it will be fine as its only for the mounted states and pointing to something is just fine.
@JuanJuan-sq7hu
@JuanJuan-sq7hu 3 ай бұрын
Incredible video! I hope you can cover the new patterns/best practices for building react19.
@OdradasMarch2027
@OdradasMarch2027 3 ай бұрын
Yeah Design pattern and System Design as relative to FE.
@phantom7132
@phantom7132 2 ай бұрын
Can we appreciate the custom repl Jack just built? This is such a good content quality.
@adityaanuragi6916
@adityaanuragi6916 3 ай бұрын
9:22 if the calculation is gonna be done this way doesn't that mean it'll be computed every single time? Whereas in useMemo it's only calculated on mount. So if it was a very long computation then the app can feel much slower with the compiler rather than the just the transpiler
@user-xn5do6xc1u
@user-xn5do6xc1u 2 ай бұрын
Hey Jack, Nice meeting you at react 2024 conf. As usual great content.
@mertdr
@mertdr 3 ай бұрын
It feels like we’ll have a stable flow around this fall or christmas due to other libraries’ dependency incompatibilites to work with react 19 and new compiler. But it’s pretty exciting news whatsoever because after getting used to server components and server actions with nextjs, the only cumbersome approach left is memoizing functions and calculated values. Thanks for sharing the experience and the mental model under the hood!
@philipfisher8853
@philipfisher8853 3 ай бұрын
Why not put gpt on the task and gace it out sooner?
@nickytonline
@nickytonline 2 ай бұрын
Thanks for the breakdown of the React compiler Jack! 🔥
@KevinRidgway
@KevinRidgway 2 ай бұрын
❤ Great content, Jack! Dang saw you at React Conf, should’ve said hello. Next time!
@jherr
@jherr 2 ай бұрын
Definitely!
@thisweekinreact
@thisweekinreact 2 ай бұрын
Nice vid. What I'm most afraid of is if the compiler changes the semantics of a program. If it works with the compiler it should rather not be buggy without it. Also regarding the const name optim, Babel AST has a node.evaluate() and is already able to do such optimizations where one variable can be substituted by a const in the same file. I use this on Docusaurus to extract semi-static translation strings from the codebase.
3 ай бұрын
Debugging will be tricky. You are going it hit breakpoints only on the first render or the updated render, where the breakpoint is at exact location where the update is happening.
@yousefkhalil7540
@yousefkhalil7540 3 ай бұрын
But this might result in a larger app size because it will add extra code when compiled compared to signals which are runtime based. From my perspective signals are better but still this is a good change.
@Booyamakashi
@Booyamakashi 3 ай бұрын
Who cares. React apps are boated hogs for years, nobody in that community cares about network performance.
@bumbletastic
@bumbletastic 3 ай бұрын
I'd be very surprised if it makes any material difference. At the end of the day, if you're deploying an app with server rendering/code splitting/lazy loading/minification it'll be a tiny amount of code for a huge payoff. 99% of all bundle problems come from the packages added (and typically only use a fraction of) anyway. As always, better focus on the big improvements, instead of worrying about what your code has compiled too
@yousefkhalil7540
@yousefkhalil7540 3 ай бұрын
Valid points and also with gzip the increase in app size might be minimal.
@noymorgenshtein9191
@noymorgenshtein9191 2 ай бұрын
Hey! glad I bumped into your video, high quality stuff! I do have one question tho - are you sure that the compiler is not part of React 19?
@jherr
@jherr 2 ай бұрын
100% sure.
@riddixdan5572
@riddixdan5572 3 ай бұрын
with the rearranging of the code, I expect it to build its sourcemap as well then?
@avanisindhav7195
@avanisindhav7195 2 ай бұрын
Thanks for the video!! 🙏🙏🙏
@TheHeadlets
@TheHeadlets 2 ай бұрын
Fantastic video - thanks!
@wonkyw
@wonkyw 2 ай бұрын
Thanks for the video. Considering dependency arrays are linted for which dependencies should be present, and they can be updated in an IDE using a keyboard shortcut, why should we need to maintain a dependency array? Speaking in general, if you are following the principles of react, you shouldn't need to bypass the type hints with extraneous dependencies. It would be nice if they were optional and we didn't even have to bother wrapping things with useMemo/useCallback.
@Bricefriha
@Bricefriha 3 ай бұрын
Amazing video thanks!
@djcardwell
@djcardwell 2 ай бұрын
unrelated but what camera are you using? has great detail on shadows AND highlights!
@jherr
@jherr 2 ай бұрын
A7SIII with a 35MM GM lens.
@devchannel5359
@devchannel5359 3 ай бұрын
I don't get how this compiler would be better than for example vue build tool to manage re render. It's seems more like react catching up on that front. Vue's reactivity is op out by default
@jjw2844
@jjw2844 3 ай бұрын
One thing I can think of that makes this POTENTIALLY better than runtime signals is that it MIGHT be more deterministic. Signals can sometimes fail based on not following the rules of signals, which can vary based on framework. E.g. destructuring too early or something. Even if you follow the rules it can be hard to track reactivity and why things are not reacting in signals. React has a ton of rules too yet this compiler does remove some of the worst of them.
@jherr
@jherr 2 ай бұрын
Agreed. The perf metrics will be very interesting.
@zayne-sarutobi
@zayne-sarutobi 3 ай бұрын
What's the reason it can't optimize the Sortedlist component at @11:09?
@afaceinacloud
@afaceinacloud 2 ай бұрын
Good golly is it nice to see React finally answering Solid and Svelte in this way. This is going to make our code so much cleaner.
@dan-vasilearion2537
@dan-vasilearion2537 2 ай бұрын
I am curios what happens with code that should not be memoized - derived state which dependens on most or even all of the component's props - cases when memoization is actually worse for performance than simply computing the value everytime.
@jherr
@jherr 2 ай бұрын
The overhead of useMemo is minimal. And it's even less here because the compiler is using the new useMemoCache hook just once to create an array that manages the memoization. Personally I can't think of a case where not memoizing at all would be significantly faster than this. There has been a lot of FUD over the years about over-memoization and I've never actually seen that in practice. What I've seen is performance issues when stuff is NOT memoized when it should be, or when folks are hacking, doing crazy stuff like using JSON.stringify in their dependency arrays.
@josephnaru363
@josephnaru363 2 ай бұрын
You are greate Jack! keep it like that
@NoorOctavianAnwar
@NoorOctavianAnwar 3 ай бұрын
Great as always!
@abhishek_k7
@abhishek_k7 2 ай бұрын
your videos are very insightful and I always learn some new things
@koksikskkj7937
@koksikskkj7937 3 ай бұрын
Thats cool they saw the preact signal and think about it that way
@DanAbramov8
@DanAbramov8 2 ай бұрын
The work on React Compiler started way before Preact Signals and has nothing in common with that approach.
@rijkvanwel
@rijkvanwel 3 ай бұрын
9:06 your useMemo should have [count] as a dependency
@Robin-zo3hp
@Robin-zo3hp 3 ай бұрын
Great video, very interesting!
@maxziebell4013
@maxziebell4013 3 ай бұрын
Optimizing compiler for JS… Google Closure rebuilds based on AST as well (old school)
@fadfooood
@fadfooood Ай бұрын
I noticed the compiler is not memoizing functions from custom hooks. I had to useCallback my functions in my custom hooks to avoid rerenders. Any idea why?
@jherr
@jherr Ай бұрын
Is it not optimizing any custom hooks? Or just that one custom hook? If it's just that one then it's possible that the compiler assessed some issue with it that wouldn't allow for optimization. The compiler is very conservative. If it doesn't think it can safely optimize the code without a change in behavior it will just leave the component or hook as is.
@fadfooood
@fadfooood Ай бұрын
@@jherr Thank you for your reply. Yes I noticed it is not optimising any functions destructed from custom hooks. I thought the compiler will do so but when I brought back useCallback to memoize functions in custom hooks then components using these functions stopped re-rendering.
@consoledoterror971
@consoledoterror971 3 ай бұрын
Really appreciate this 👍
@mytvhome7394
@mytvhome7394 3 ай бұрын
Great video Jack! I just notice that React Compiler is written in Rust !!! I hope some day you make a video about Rust...
@jherr
@jherr 3 ай бұрын
It’s not. It’s written in node. It’s a babel plugin
@kristianlavigne8270
@kristianlavigne8270 3 ай бұрын
They are writing an optimised version in Rust as well but current version is in Node
@dereksniper
@dereksniper 2 ай бұрын
What about state management, would context or signals need be somewhat taken away?
@jherr
@jherr 2 ай бұрын
Context works just fine. As for signals, depends on what you mean by that. If you are talking about preact-signals then that's really on them to figure out. Last time I looked preact-signals was directly altering the DOM nodes when a signal change and the signal was bound to a text element. If you are doing that then... well... who knows. Your fighting the framework and you get what you get. If what you mean is just using signals as a data management and dependency graph, then using something like useSignal to integrate it into your components, then that will work just fine. MobX is really the exception here since components are wrapped in an observer, and it's that observer that manages what changes. The compiler doesn't understand the semantics of the observer function and so it just falls back on not optimizing the component.
@somewonderfulguy
@somewonderfulguy 3 ай бұрын
Hi Jack! You mentioned that MobX won't work because of Proxies. All right, am I correct if I say that the same goes with Valtio? Another Proxy based library created by Daishi Kato.
@somewonderfulguy
@somewonderfulguy 3 ай бұрын
I hope I'm going to finish reading No BS TS before No BS Next.js comes (and I hope Next.js course coming very soon!)
@jherr
@jherr 3 ай бұрын
Yeah. My hunch is that valtio is also incompatible.
@mahmoudzakria6946
@mahmoudzakria6946 2 ай бұрын
**EDIT** Does it compile the react code and while building is the React vendor/dependency opted-out from the final production bundle like Svelte?
@jherr
@jherr 2 ай бұрын
I don’t fully understand the question. All it’s doing is optimizing the components and hooks. It’s not doing any kind of bundling or tree shaking. The code shown in the video is a decent view of what the compiler is doing.
@mahmoudzakria6946
@mahmoudzakria6946 2 ай бұрын
@@jherr Ok ma bad, I made an edit and will also rephrase it better here, but I think the answer is no based on the examples you provided, but anyway, what I mean is when it comes to the building/bundling time for production I thought it will just compile the react code into JS code and no need to generate the vendor chunk file which included in /dist because the code is compile from declarative to imperative, I hope I made it more clearer 💙
@badbabybearbots8968
@badbabybearbots8968 2 ай бұрын
Ultimately fixing the memo problem in the compiler is simply returning `() => __jsx(...)` instead of `__jsx(...)`. This way you just need to call whatever function is returned vs its parent function on re-render.
@YasinAkimura
@YasinAkimura 2 ай бұрын
Quick Question: Do you know if manual memoization / callback will be unrecommended in the future? I know react loves to keep backwards compatibility but maybe the compiler is smarter then us and also knows how to do it better. Which means do we just write beautiful clean code without any memos and useCallbacks in the future or is it completely up to us if we don't break any rules the result may be the same or at least better?
@jherr
@jherr 2 ай бұрын
I think it will be. It's not there now. According to the folks I talked with the hooks API was always designed to be automatable by a sufficiently sophisticated compiler. That's not actually what's happening here though. They created a new hook that the compiler uses that is more efficient than creating lots of useMemo/useCallbacks. You invoke the component once to get a set of memoized slots that they then use to manage the memoization.
@ragnarlothbrook8117
@ragnarlothbrook8117 3 ай бұрын
Great video! thanks!
@MICHAELZ50
@MICHAELZ50 3 ай бұрын
Great video! Can't wait to use React Compiler! Have a question here. Why React Compiler could not "compile" SortedList component in 11:02? isn't it as simple as removing the useMemo in the Compiler code?
@jherr
@jherr 3 ай бұрын
Thanks for the reminder. I’ll talk with the team about that.
@YasinAkimura
@YasinAkimura 2 ай бұрын
My guess is the sortedNames.map it would need to know what the javascript function does and that could be difficult on lower level without putting some edge cases?
@paweciosek489
@paweciosek489 3 ай бұрын
great content, bravo! 👏 👏 👏
@sawaratsuki
@sawaratsuki 2 ай бұрын
Thank you for using my kawaii logo for the thumbnail!
@jherr
@jherr 2 ай бұрын
And thank you for making that logo. You are credited in the description.
@sawaratsuki
@sawaratsuki 2 ай бұрын
@@jherr Thank you~!!!!
@dylanthony1
@dylanthony1 2 ай бұрын
Are you the goat who’s been rewriting everyone’s logo in kawaii?
@sawaratsuki
@sawaratsuki 2 ай бұрын
@@dylanthony1 yes :)
@aymanechaaba
@aymanechaaba 2 ай бұрын
You deserve to get your chance to speak at that conf ♥👍
@jherr
@jherr 2 ай бұрын
Yeah, I submit a paper but it didn't get picked. :(
@user-ik7rp8qz5g
@user-ik7rp8qz5g 3 ай бұрын
So how do we get it if not with 19? Will it be separate package that we need to install into project? Or will we have to wait for next version?
@StephenRayner
@StephenRayner 2 ай бұрын
How are you getting the boarders to show when state changes?
@StephenRayner
@StephenRayner 2 ай бұрын
To visually track state changes and re-renders of React components within Google Chrome, you can use the "Highlight updates when components render" feature in the React Developer Tools extension. Here's how to enable it: Install the React Developer Tools extension for Chrome. Open your React application in Chrome. Open the React Developer Tools panel (usually found under "Developer Tools" > "React"). In the React Developer Tools panel, click on the settings icon (gear icon). Check the "Highlight updates when components render" option. With this option enabled, whenever a React component re-renders due to a state change or prop update, a colored border or rectangle will flash around that component in the browser window. This visual highlighting helps identify which components are re-rendering and when, making it easier to debug performance issues or unnecessary re-renders.
@collinoly
@collinoly 2 ай бұрын
Will the compiler really ever be able to fix the need for a dependency array in useEffect? How would you opt out of it reruns. I might use a reactive value in the useEffect that isn’t meant to be part of the dependency array. That’s why solidjs provides an opt out array not an opt in array
@jherr
@jherr 2 ай бұрын
My hunch is that at some point there will be an option al have the compiler manage the arrays and you can opt out when you need to. That’s not in there now though.
@zb4238
@zb4238 2 ай бұрын
I'm just slightly confused... first "react forget" was the big hype of React 19 release but now we have "compiler" and that is supposedly NOT coming in React 19? is react forget now called compiler or are those two separate features?
@jherr
@jherr 2 ай бұрын
Forget was the code name, React Compiler is the real name. React 19 is just the version of the library. React Compiler is a set of tools, including babel and eslint plugins, that optimizes components and hooks in React 19 code.
@yunusemrekavi1218
@yunusemrekavi1218 2 ай бұрын
Can you share your VS Code settings.json and theme with us please :)
@sights2
@sights2 3 ай бұрын
React compiler is more of a band-aid over a deeper design flaw. Caching is great, but it isn't free.
@BurgerBurglar8964
@BurgerBurglar8964 3 ай бұрын
What’s the alternative? Solid?
@meka4996
@meka4996 3 ай бұрын
@@BurgerBurglar8964 Try Svelte I think...
@FunctionGermany
@FunctionGermany 3 ай бұрын
the software industry is all about bandaids. software continually evolves, but the industry can't wait forever for the perfect library or framework or language, so at some point they place long-term bets so you get huge "legacy" applications written in Java 1.8, PHP 5, jquery, or recently react, and there is a large demand for getting better performance without spending a lot of money and time rewriting entire projects.
@follantic
@follantic 3 ай бұрын
Compile React to SolidJS and you get mad perf gains bro.
@rand0mtv660
@rand0mtv660 3 ай бұрын
I'm sure they did weigh in the tradeoffs with this and decided it was worth doing. React team moves slowly and quite deliberately. Yes I don't think React is perfect, but with big changes in React, the team usually knocks it out of the park in my opinion.
@luka1790
@luka1790 3 ай бұрын
Huh is the counter component from 8:49 different then 0:33? Because I don't see props being passed. Does React Forget make and object argument a stable ref now? Is the memo already applied in the parent component? That would be great tho! I guess legend state would break if I upgrade to 19 because it proxy based?
@jherr
@jherr 3 ай бұрын
Yeah the state space is going to be changing.
@thevutv2349
@thevutv2349 3 ай бұрын
Legend state works I’ve upgraded to 19
@jherr
@jherr 3 ай бұрын
@@thevutv2349 it’s not just 19 you also have to add the compiler. 19 does NOT include the compiler.
@MrJellekeulemans
@MrJellekeulemans 3 ай бұрын
Now we have a use case for use effect without a dependency array 🎉🎉 - which is to run some code every time the component re-renders
@mattvicent
@mattvicent 3 ай бұрын
Well, now you could just do it directly in the body of the component hehe
@aldeywahyuputra5719
@aldeywahyuputra5719 3 ай бұрын
​​@@mattvicentActually not quite. Yes, you are allowed to directly code it in the render phase, however there are some cases where you do need to still use useEffect without dependencies. For instance, you are not allowed to access and mutate useRef mutable reference as this can lead to "UB" (see "Pitfall" on the useRef documentation). Note the subtlety here: this does not change the fact that there is still a distinction between the render phase (which React will expect your components to be free of side effects) and when effects are actually being run. React Compiler does not change this fact.
@karolbielen2090
@karolbielen2090 2 ай бұрын
All that knowledge about memoization, dependency arrays and reconciliation I've gathered over the years is now becoming obsolete.
@majorhumbert676
@majorhumbert676 2 ай бұрын
No, it's important to understand how the technologies work.
@resetengineering
@resetengineering 2 ай бұрын
I am sorry but I don't think I was able to connect dots when you move in b/w the normal version and compiler version that much. It was moving too fast.
@jherr
@jherr 2 ай бұрын
Just FYI, you can slow the video down by setting the playback speed to be slower. You can also use the scrubber to replay certain sections multiple times.
@sourishdutta9600
@sourishdutta9600 3 ай бұрын
It’s still running though 😂 still watching
@snowsnowy677
@snowsnowy677 2 ай бұрын
Why in the first example all components refender ? We just setstate first counter, we don’t touch second one
@jherr
@jherr 2 ай бұрын
Because react by default renders everything in a component on a state change in the parent component.
@Krishnasaini
@Krishnasaini 2 ай бұрын
Which extension is used here to highlight components which are rerendered?
@jherr
@jherr 2 ай бұрын
That's React Devtools for Chrome.
@gauravkumarsharma5904
@gauravkumarsharma5904 2 ай бұрын
👍
@Shyam_Mahanta
@Shyam_Mahanta 3 ай бұрын
Great Content.
@bibahbibah5108
@bibahbibah5108 2 ай бұрын
Thanks, but there are one point that have not appeared, the performance impact and specially when the memorization the components
@jherr
@jherr 2 ай бұрын
That wasn't in there because I don't have the data on that. Meta showed the data in their presentation because they have the data on the impact when they ported all of Instagram to it. It was 12% faster UI performance overall, with no change in memory footprint.
@tasin5541
@tasin5541 3 ай бұрын
From the looks of it, react compiler basically adds memoization to everything. Isn't it bad to add usememo and usecallback to everything?
@jherr
@jherr 3 ай бұрын
It's not using useCallback and useMemo specifically. There is a single useMemoCache hook that it uses that is run once and is used for all the memoization of the whole component. So that's going to be faster than a set of individual useMemo/useCallback calls. But one hook vs many hooks is in the noise performance wise. The big win is in the memoization of the elements which reduces whole code paths of execution as the memoized code is smart enough to avoid re-rendering component trees that don't need re-rendering.
@FunctionGermany
@FunctionGermany 3 ай бұрын
9:50 i don't understand the names example. the prop is passed as-is to useState, so the value of the state should automatically update when the prop changes because useState will receive a new reference. what's the point of the useMemo..? it looks like a very wrong useEffect...
@whoman7930
@whoman7930 3 ай бұрын
That's not how it works. `useState` takes the default value only for the first time when the component is mounted.
@matyascsoti1788
@matyascsoti1788 3 ай бұрын
nope, name will be passed to the usestate only in the initial render, afterwards the name constant will not be updated anytime the usestate function receives a new value. It is called initial value for a reason
@FunctionGermany
@FunctionGermany 3 ай бұрын
@@whoman7930 wow. i've worked with react a ton and always had this wrong assumption... thanks for letting me know. so the only oddity of that code example is that useMemo was used instead of useEffect? or how would you implement a state variable that's both updateable by the component itself as well as it's parent component?
@whoman7930
@whoman7930 3 ай бұрын
@@FunctionGermany The best way is to use global state, and use the state through props. And yes we can use useEffect for this, but its not much ideal.
@phantazzor
@phantazzor 2 ай бұрын
Does it work with Vite?
@jherr
@jherr 2 ай бұрын
Yes.
@dimasheiko
@dimasheiko 3 ай бұрын
Hey Jack, great video, thanks! Is there any source I can read about MobX incompatibility with compiler in more depth?
@sebastianchaca00
@sebastianchaca00 3 ай бұрын
I need that info too. Cant find anything about that. Thanks !
@jherr
@jherr 3 ай бұрын
The source on that one was a talk I have with Joe Savona directly. Basically the compiler doesn't get that this value can magically change, so it memoizes it for performance. Thus... bug.
@dimasheiko
@dimasheiko 3 ай бұрын
@@jherr Thanks! I also run compiler health check on my MobX project and it indeed told me that MobX isn’t supported ☹️
@jacqueskorb879
@jacqueskorb879 3 ай бұрын
Thanks
@imarya7329
@imarya7329 2 ай бұрын
From Jquery to Frontend needing compilers...yea I grew up.
@bhavyajain638
@bhavyajain638 3 ай бұрын
Could there be a case where we do want components to re-render but it is optimized by the compiler and now they do not re-render? I can't think of a situation where it is required, but I wouldn't be surprised.
@jherr
@jherr 3 ай бұрын
I can't think of any legitimate circumnstance underwhich this would be the case. React components re-render when state, props, or context change. If you aren't changing any of those, why would the component need to re-render?
@bhavyajain638
@bhavyajain638 3 ай бұрын
@@jherr Yes, makes sense. Thank you so much, amazing video.
@VigneshwarDev
@VigneshwarDev 2 ай бұрын
wow react compiler looks really great though!!. Still has a lot of scope for improvements. I wonder why they didn't think of it atleast while introducing functional components. was it like they didn't think of the worst case scenario that this library can be pushed into? What React team gonna build next ? Maybe a custom react JS engine on top of browser's JS engine to efficiently execute JS functions produced by the Babel with React compiler.. I think its time to challenge backend developers for a battle of complexity😅.
@darth1anyan
@darth1anyan 3 ай бұрын
There is a "DONT_USE_OR_YOU_WILL_BE_FIRED" export in the react code? 😂
@katanaut
@katanaut 3 ай бұрын
The moment there were rumours about react forget, I stopped using memoization wrappers in my code so I don’t have to remove them all over again 😄
@larsfaye292
@larsfaye292 3 ай бұрын
madlad
@Gaijin101
@Gaijin101 3 ай бұрын
Glad to see react didnt forget react forget. But its definitely not the most advanced compiler, still great tho.
@rmdashrfv
@rmdashrfv 3 ай бұрын
This is beautiful ... 🥹
@LarsRyeJeppesen
@LarsRyeJeppesen 3 ай бұрын
So like Angular
@jherr
@jherr 3 ай бұрын
Actually, Angular requires a compiler. This is an optional optimizing compiler.
@bedirhandincer3448
@bedirhandincer3448 3 ай бұрын
Which state management library would the compiler work with?
@jherr
@jherr 3 ай бұрын
Redux, zustand, recoil, jotai, those are all fine. It’s just proxied state managers like mobx and valtio and maybe legend.
@bedirhandincer3448
@bedirhandincer3448 3 ай бұрын
@@jherr thanks for mentioning it I was not aware of this!
@o_glethorpe
@o_glethorpe 3 ай бұрын
Its nice but to make this work, it will use more memory right? since they cache everithing now.
@jherr
@jherr 3 ай бұрын
Not significantly. This will hold references to elements, which are just pointers, so they are small. And we were already keeping those in the VDOM. Also, it's pretty smart about not memoizing every single element. It groups elements together based on their data, or lack thereof.
@o_glethorpe
@o_glethorpe 3 ай бұрын
@@jherr I see, thanks for sharing. :)
@archamedis
@archamedis 3 ай бұрын
🔥🔥🔥
@jpcafe
@jpcafe 2 ай бұрын
How is it the most advanced compiler? Svelte literally exists because of the compiler, there’s no runtime in v4
@360nickx
@360nickx 3 ай бұрын
Wow. 🤯
@billybest5276
@billybest5276 2 ай бұрын
exciting
@Stefoux
@Stefoux 2 ай бұрын
It should be Nice to add credit to logo creator …
@jherr
@jherr 2 ай бұрын
Correct, my bad and fixed.
@karlgustav9960
@karlgustav9960 3 ай бұрын
I was kind of hoping that the compiler would decrease bundle size, but it looks like it actually bloats the code, what about memory, the code may run faster (react always assumed that the real bottleneck is Dom operations and repaint), but doesn’t memoization use quite a lot if ram?
@GurbyTheGreat
@GurbyTheGreat 3 ай бұрын
Just run a minifier after it compiles for prod builds.
@neociber24
@neociber24 3 ай бұрын
Just see the output of Svelte code after compiled, it's a similar process. You are not suppose to ship directly that code but use a bundler.
@aashayamballi
@aashayamballi 3 ай бұрын
thank you!
@dominikzmudziak8340
@dominikzmudziak8340 2 ай бұрын
kzfaq.info/get/bejne/hr94dat8mJ3cnHk.html , doesn't sortNames function depend on names property?
@WilliamShrek
@WilliamShrek 3 ай бұрын
Mobx: my bad. 😭
@papa_ethan
@papa_ethan 3 ай бұрын
But when you disable the React.Strict mode the code will update only once. Why is this so?
@user-to8yn2sn6j
@user-to8yn2sn6j 2 ай бұрын
Will they no longer need Babel?
@jherr
@jherr 2 ай бұрын
What does that mean? Who is they? I don't understand the question.
@betagroobox
@betagroobox 3 ай бұрын
Why can't it turn jsx into plain js? Doesn't svelte do this?
@SeanJMay
@SeanJMay 3 ай бұрын
React, itself, doesn't do that, because then it wouldn't be viable in React Native or server-side. React generating an optimized AST means that ReactDOM can generate JS/DOM, React Server Components can generate HTML text, and React Native can generate whatever the native platform expects, so long as you are using middle of the road, interchangable components.
@BurgerBurglar8964
@BurgerBurglar8964 3 ай бұрын
1 minute 5 comments already
@AbdulMajeed-lp1fk
@AbdulMajeed-lp1fk 3 ай бұрын
where is react rules link ??
@jherr
@jherr 3 ай бұрын
react.dev/reference/rules And added to the description
@AbdulMajeed-lj3zi
@AbdulMajeed-lj3zi 3 ай бұрын
Thanks !! But i already got it from react conference video 😊
@sahajranipa
@sahajranipa 3 ай бұрын
How is this compiler guy changing the nextjs scenarios plz make a video about it.
@jherr
@jherr 3 ай бұрын
Outside of one small next specific issue around their font support requiring SWC (which means no babel, which means no compiler) Next is completely compatible.
@aizensoskue3880
@aizensoskue3880 3 ай бұрын
a compiler that just adds usememo and use callback is better than svelte compiler lol
@neociber24
@neociber24 3 ай бұрын
Seeing the resulting code, I think both do similar things
@tomm5765
@tomm5765 3 ай бұрын
Yeah nah. Svelte5 has deep fine grained reactivity, meaning if you change just one property in an object, there is no component updates at all. only exactly where the property is used is updated
@masteringmui
@masteringmui 3 ай бұрын
@@tomm5765holy shit. That’s actually amazing
@reold
@reold 3 ай бұрын
1:10 It feels funny when he says all this. He’s talking like this is new tech that hasn’t been used in a framework like svelte. Rich was right from the very start. I remember how the react community criticised Svelte heavily due to its compiler
@DanAbramov8
@DanAbramov8 2 ай бұрын
@@tomm5765If you update a deep property, and that property is used only for some subcomponent, React Compiler will bail out of it just fine. You should try the live playground. If we have to compare to Svelte here, I think it’s worth noting that if a derived computation from two inputs (eg list1.length + list2.length) produces the same results (e.g. list1 increased by one item but list2 decreased by one item), React Compiler would be able to bail out, while Svelte, afaik, would not.
@imkir4n
@imkir4n 3 ай бұрын
Awesome the margin btw senior amd jr is lessser now
@nahfamimgood
@nahfamimgood 3 ай бұрын
no its not lol
@imkir4n
@imkir4n 3 ай бұрын
@@nahfamimgood jk
@xreed8
@xreed8 3 ай бұрын
Why are we calling it a React Compiler when it would be far more accurate to call it React Transpiler (converts JavaScript to a more optimized form of JavaScript)
@jherr
@jherr 3 ай бұрын
IMHO, it's really more of a compiler since, at least to me, I view a transpiler as making small code modifications for compatibility. Where these are more profound refactorings of code. For example the inline onClick callback function is moved into the memoization block where it's memoized with the data that it references. And then connected to its tag in a different memoization block later on when appropriate. That's a much more profound code modification than a simple transpilation.
@clusterdriven
@clusterdriven 2 ай бұрын
Compilation definition by dictionary: processed through software that translates a complete set of high-level computer instructions into machine language before executing any of them. So I don't think it's correct to say "React Compiler". It does not matter what it does. If it does not generate machine code, it's not a compiler.
@jherr
@jherr 2 ай бұрын
@@clusterdriven Cool. What's the dictionary definition of "machine"? I'm pretty sure that most folks consider the Java compiler a compiler, and it compiles code to the Java virtual "machine". Ruby also has a virtual machine. And it interprets from raw text and only has the bytecode model in memory. But that transformation step is "compilation" because it's compiling to a machine. So depends on what your definition of a machine is. BTW, this is the reason that many folks consider the structure and function of the compiler to be the arbiter of the definition, and not the target.
@ersinbasaran
@ersinbasaran 3 ай бұрын
I thought useState/Effect/Memo/Callback were already complex enough. With the new React compiler, I might need a PhD in Reactology to understand what's going on!
@isaiah2672
@isaiah2672 3 ай бұрын
Skill issue
@follantic
@follantic 3 ай бұрын
React team: Do not use useEffect for api calls. Me: 🤔🤷‍♂️
@rand0mtv660
@rand0mtv660 3 ай бұрын
The thing with this compiler is now you will actually have to know less about this because some of it should hopefully be automatic and abstracted away.
@nahfamimgood
@nahfamimgood 3 ай бұрын
cursed as fuck lol @@rand0mtv660
@david.thomas.108
@david.thomas.108 3 ай бұрын
The point is you don’t need to know about many of those hooks and don’t even need to add them. The compiler will optimise the code automatically.
Finally Fix Your Issues With JS/React Memory Management 😤
20:13
Jack Herrington
Рет қаралды 83 М.
React 19's useOptimistic: EVERYTHING you NEED to know
25:24
Jack Herrington
Рет қаралды 14 М.
Son ❤️ #shorts by Leisi Show
00:41
Leisi Show
Рет қаралды 10 МЛН
小天使太有爱心了#天使#小丑#家庭#搞笑
00:32
家庭搞笑日记
Рет қаралды 25 МЛН
Советы на всё лето 4 @postworkllc
00:23
История одного вокалиста
Рет қаралды 5 МЛН
So You Think You Know Git - FOSDEM 2024
47:00
GitButler
Рет қаралды 1,1 МЛН
What's new in React 19 | Lydia Hallie
20:04
React Conf
Рет қаралды 29 М.
Learn Web Development And ACTUALLY Get A Job | Ultimate Guide
1:33:52
James Cross
Рет қаралды 1,3 МЛН
Выжимка первого дня React Conf: Краткий обзор
8:59
React Compiler: It's Stranger Than You Think
27:37
Theo - t3․gg
Рет қаралды 34 М.
Five React App Killing Anti-Patterns 🪦😱
12:47
Jack Herrington
Рет қаралды 32 М.
React for Two Computers - Dan Abramov | #ReactConf2024
28:13
The Code Critical
Рет қаралды 6 М.
Why Signals Are Better Than React Hooks
16:30
Web Dev Simplified
Рет қаралды 469 М.
I Was Wrong About React Router.
19:06
Theo - t3․gg
Рет қаралды 59 М.
Son ❤️ #shorts by Leisi Show
00:41
Leisi Show
Рет қаралды 10 МЛН