r/FlutterDev • • Jan 09 '22

Discussion Can Flutter/Dart replace JavaScript and React? If no, then Why

[removed] — view removed post

43 Upvotes

58 comments sorted by

View all comments

44

u/gaspard-m Jan 09 '22 edited Jan 09 '22

Flutter is still not that mature when it comes to the web. So I do not think that it would be able to replace React in the near future. Furthermore, JavaScript still has the advantage of running natively in a browser while Dart needs « compilation » to JavaScript…

But what is sure is that Flutter is becoming better and better each day that passes and I don’t think the same can be said about React… And if fuschia continues growing, Flutter will start to be way bigger than React. But not replacing it since React also comes with it shares of advantages. Like written in JavaScript which is a very popular language as opposed to dart.

I love Flutter and I am not that experienced with React so my opinion is clearly not impartial ! :)

4

u/Only-Split82 Jan 09 '22

As nobody is using React.createElement but JSX, React is not running natively as well ( the real "native" React interface is too uncomfortable to use it in real apps ). So this is not an advantage over Flutter.

I think the biggest disadvantage of Flutter for Web is that the app runs in canvas instead of using html elements ( please correct me if it is also possible to use html elements in Flutter ). So if it comes to SEO and Browser optimizations it will be worse than the other frameworks. Another disadvantage is debugging as it is imo much more difficult in Flutter Web than in React for example. Maybe it is just that i am used to a certain debugging style that i cant apply to the new technology.

For hybrid mobile apps i think Flutter is much better than the other players. And you can be very productive with it. Super nice technology for this niche.

2

u/qualverse Jan 09 '22

Flutter web uses (by default) a hybrid of canvas and HTML elements to render, although you can also use canvaskit which renders using only canvas. The biggest issue with it though, imo, is the lack of native scrolling.

3

u/Charly_ZA Jan 10 '22

The default auto mode uses the HTML renderer on mobile and the CanvasKit renderer on desktop.

Edit link: https://docs.flutter.dev/development/tools/web-renderers#command-line-options

0

u/[deleted] Jan 10 '22

[deleted]

0

u/[deleted] Jan 10 '22

[deleted]

0

u/[deleted] Jan 10 '22

[deleted]

2

u/Only-Split82 Jan 10 '22

Imo JSX is one main feature of React. Without it, it wouldnt be as popular as it is. Just don't use React without JSX!!!

→ More replies (2)

3

u/gaspard-m Jan 09 '22

That’s quite true! But I would like to point out that for web app such as Google Analytics, Uber, … and many others you don’t really need seo.

The usual approach being to have a static website written in another language for seo purposes that gives access to the web app.

1

u/Snirdude Jan 09 '22

please correct me if it is also possible to use html elements in Flutter

I know seo_renderer is trying to fix that. It's under development and I haven't tried it myself but you're welcome to try.

1

u/bc_odds Jan 09 '22

please correct me if it is also possible to use html elements in Flutter

I just remembered the Flutter youtube channel doing a short on package:html. I'm really curious what it renders to on web. Something to try out tonight!

1

u/ImpossibleReality903 Jan 09 '22

As nobody is using React.createElement but JSX, React is not running natively as well

What does this mean?

That if I used `React.createElement("Text"` ... or whatever, the views/etc wouldn't be in the JS thread but native? But with JSX it has to be "parsed" then sent to native?

1

u/[deleted] Jan 09 '22

JSX is compiled, so the argument that Dart doesn't work because it's compiled is the same as JSX, no one uses React without some form of compiler anyway.

0

u/miyoyo Jan 10 '22

That's kind of disingenuous, React's JSX is not going to majorly affect the final code, its effectively just converted to create Elements, whereas Dart brings entirely new semantics, different runtime type checks, and more, that's like saying an airplane and a shopping cart are the same because they both have wheels.

1

u/[deleted] Jan 10 '22 edited Jan 10 '22

That is not a great straw man argument. It misses the entire point that it's not comparing whether or not a base compiler is needed. It is fact that JSX does, regardless of how much it actually does. No one cares about the additional checks that dart2js will add when compiling dart, as it in no way changes the actual functionality of javascript as a language, so there is no point in comparing how much each actually changes, except for the difference in it needing to exist at all, or not.

To prove the point further, people don't even just use a jsx "compiler", they use babel, with like 50 plugins installed, that does hundreds of polyfills, manipulations, checks, and TypeScript or whatever else you want to support.

-3

u/miyoyo Jan 10 '22

The amplitude of change, and the resulting performance hits, are definitely things to consider, "compiled" JS is pretty much still the same, and acts similar to the original source, whereas Dart compiled to JS effectively runs into a VM written in JS, you can't just pretend that these are equivalent.

3

u/[deleted] Jan 10 '22

Except if you had done just a little research into what you’re saying instead of pulling stuff out your arse, you’d know that there isn’t really a Dart VM in browsers, nor does Dart itself run directly in a browser. Dart code gets compiled into optimized JavaScript, which in turn means that you’re still running JavaScript.

1

u/Only-Split82 Jan 10 '22

I just mean that JSX is not part of vanilla Javascript. So either you use createElement syntax or you need a compilation step to compile JSX to vanilla JS.

1

u/cesarfrick Jan 10 '22

Well, React does run natively on the web. JSX is just sugar syntax, and it's transpiled to plain Javascript in the building process, so I wouldn't say that's a disadvantage of React. The transpiled code won't include any JSX on it

1

u/Only-Split82 Jan 10 '22

I never said that! I just said that "Flutter needs to be compiled" is not a disadvantage when comparing it to React as it needs to be compiled ( or rather transpiled ) as well.

1

u/Slonik923 Jan 09 '22

More and more developers uses Typescript, which also needs transpilation to Javascript. Moreover transpiled code can be and usually is faster than Javascript code written by a developer. Unless developer spend a lot of time optimizing the code.

2

u/gaspard-m Jan 09 '22

And does react typescript allow for easy debug? Because that’s one of the drawback with Flutter web… It does not have a good stack trace when the issue is a bit complex… Of course you usually dev using android emulator or other but when some issue are only web related it becomes quite hard..

2

u/Samurai___ Jan 10 '22

Yes, it can be debugged in browser or in vscode properly.

2

u/Slonik923 Jan 10 '22

In TS you can tell compiler to declare TS to JS maps, which are then used for debugging. Now you now on which line the error occured. Not sure if you can do this in Dart, but Dart have pretty cool tooling on mobile, so I wouldn't be worried about that.

Flutter Web is using canvas, which could be reason why stack traces are that complex. Flutter Web is still in beta, so maybe this will be improved.

On the other hand you still can use AngularDart, which is not as cool as Flutter, but does the job. And maybe we get Flutter Web with html elements support.