New React DevTools
reactjs.org
reactjs.org
But only because React, with transpiling and the shadow DOM and all that is so inscrutable.
There’s no hope of understanding the DOM with React, no hope of understanding styles with styled-components. There’s no hope of placing a breakpoint in your code and tracing forward through events. No hope of understanding stack traces.
The DevTools begin to address some of those deficiencies. It does help, but still leaves me thinking the tradeoffs weren’t worth it. You can never reach simplicity, only manageable complexity. In the long run it leaves an opportunity for a new generation of tools that respect JavaScript and the DOM.
You can still understand the DOM in a React driven app though. The component output is there for anyone to read. I do that every day. All React is doing is generating DOM content and then working out the smallest update necessary when the state changes. The problem that React Devtools addresses is that it's the component output that's there, not the components themselves. There's more information behind the scenes, and that is what React Devtools lets you peek in to.
It does help, but still leaves me thinking the tradeoffs weren’t worth it.
You have to reason about the way you write code, what your apps need, and what works best for your users. If the tradeoff is that using React's features means you can no longer work with the complexity of what's happening in the browser and that's slowing down your development process then don't use React. Your development process and your users are way more important than any framework.
Not to use too-harsh language but that's a cop-out in my opinion. Yes, some tools are better for a given job than others. But we're working with general-purpose machinery for the purpose of building UIs and applications. There isn't really a differing set of requirements or problems in that domain. ... and if that's true, then it means that one size should actually fit all. I think, personally, UIKit is excellent. I think people don't understand how to use it properly… they don't understand how to write good imperative code, so they look to a declarative system as a way around that… but I think they're only deferring the inevitable or shifting non-problem-inherent complexity they couldn't initially solve.
Agree. IMHO the fact that React uses the virtual DOM is one of its biggest inconveniences.
> In the long run it leaves an opportunity for a new generation of tools that respect JavaScript and the DOM.
Angular (v. >= 2.x.x) on this is much simpler to understand as it manipulates the DOM directly. With the built-in dev tools of any browser you pretty much can inspect any portion of HTML, CSS and source code.
Dom explorer shows the elements. document.querySelector finds your tags. Css just works. Nothing new to learn.
Custom elements let you be just another html tag and do your magic. Not fully sold on shadow dom but web components api is simple and I love it.
CSS has of course always worked just fine with React (as does LESS and SASS). Styled-components is totally optional.
There's tradeoffs at scale with trying to use an imperative style of coding with document.querySelector or JQuery. Fine for simple websites. Absolutely awful for complex web apps with large teams.
Dom explorer is still a tab in Chrome for react devs. I readily switch between the React devtools and Dom explorer all the time.
The reason in my mind, for React, is that it's a higher level, functional abstraction above the DOM that makes complex web development manageable.
After showing the HTML you can still make elements more interactive with things like jQuery, Stimulus or Freudjs (disclaimer: my own)
If you add redux and something like redux-form you end up with sending each keyup event to the redux store and re-rendering your input fields from that store.
So yes the JSX at the very bottom of your software tree is pretty much like HTML, but it takes a whole lot of engineering to get there and variables get pushed through many layers before they reach the final JSX in which they are rendered.
Some of this has to do with how you implement your application, but in general getting from input to output takes more steps than it does with a server side rendering framework.
This is fine when building something like a mobile application or an off-line-ready application like devdocs.io, but if you use a React application in front of some back-end you are just getting HTML in return for all your engineering efforts. If HTML with a few interactions is all you are after there is too much code and too many layers between the page that has your `<div id='myapp' />` and what you get after React is done rendering.
You can treat React itself as a single-pass server template engine with component support. You don't have to bring all of this single-page app stuff into it. Hope that explains my point. You don't even have to run React on the client at all.
I'm specifically talking about ReactDOMServer.renderToString() on the server and serving that HTML. Not "mounting into a <div>" client use case.
Indeed.
I mean who'd do that when there are plenty of server-side templating solutions that don't have to live by React's constraints (vdom/DOM diffing) only making things difficult? The only use case for React SSR seems quick first-page rendering and SEO.
So you mean something like keeping state of forms in something like redux and sending out an event every time you press a button so that state gets update and the change is pushed down the tree of elements so that the letter you just pressed gets rendered in the form?
Or did you mean client side validations of forms that you also have in your back-end?
Obviously you didn't and I am being a bit of an ass, but this is what is the somewhat recommended way of going around this and it is so convoluted.
> doing a lot of manual labour keeping track of all states, events, etc.
The state of most web applications can be kept inside of DOM elements and the url just fine.
> What div is visible, which one to hide, which buttons to disable
This is where CSS-classes and the aforementioned JS libraries come in and they do this job just fine.
> adding new rows into forms dynamically with pre-populated values... that kind of stuff is way (and I mean waaaay) easier when coded in a declarative reactive way.
I don't believe you are right. It is not easier at all to add some DOM elements with React than it is when you use small bits of JS. Let's say you use jQuery, then it is 1 dependency you add with a small wrapper script for your dynamic form, with React you add thousands of dependencies and you have to build your complete application in React just to dynamically add a row in one of the forms. How is that easier?
I don't think I'd build Slack mostly using HTML rendering from the back-end, but most of the things that we build are CRUD applications that can easily be built using things like Ruby on Rails. Let's say the Trello's, Githubs and Amazons of our world.
Because with sufficiently complicated UI you will simply at some point have to start writing abstractions and libraries to help you handle all that mess, and then you'll basically end up building a good part of those "thousands of dependencies" yourself - reinventing the wheel.
For smaller projects it's an overkill obviously, no one says you have to use it everywhere. But for bigger projects it's a way more optimal to sacrifice some performance in order to be able to build faster and maintain the project easier, and even if you try to make your own solution chances are that with time it will evolve into something very close to how big players solve it. At least that's what happened to all my custom frameworks (front and backend), 10+ years ago when I myself still believed in not needing extra bloat of frameworks... you one day realize that someone already solved your problem, and solved it way better than you ever would...
This is an argument that I often see from people trying to defend front-end frameworks. That mythical complex UI. So far the only thing I can imagine that comes close might be something like a chat application. Apart from off-line ready apps, I grant you. In that case there would be no point in trying to accomplish that with vanilla JS or jQuery.
> But for bigger projects it's a way more optimal to sacrifice some performance in order to be able to build faster and maintain the project easier,
I am arguing that you build slower if you build your front-end separately from your back-end rather than use something like Ruby on Rails.
> you one day realize that someone already solved your problem, and solved it way better than you ever would...
I am saying the problem isn't there 95% of the time. You are just better off rendering HTML and some small pieces of JavaScript.
> 10+ years ago when I myself still believed in not needing extra bloat of frameworks...
I don't believe this at all, I just oppose the current state of affairs in the JavaScript world and don't subscribe to what is generally considered a good stack. I am not saying you should reinvent the wheel either, I am talking about existing tools like jQuery or Stimulus JS.
Sorry, but if you think that chat is a complex UI you obviously don't understand what type of complexity I'm talking about. Multi-page, multi-level forms with a lot of conditional rendering are far bigger problem to handle than chat. Challenge is not in a single particularly advanced action, forms I'm talking about are mostly just a bunch of ifs and event handlers that update the DOM accordingly. Problem is the overall complexity arising from a sheer number of different combinations you need to control, so you end up with thousands and thousand of lines of jQuery functions and events interacting and stepping on each other's toes.
For instance I'm currently working on an IP management app for big, international law firm. In order to invoice a client for even a very basic service like trademark registration you need to handle multiple countries, multiple laws, multiple currencies, and it has to be all in one dynamic form because they need to fill hundreds of those and it has to be simple and quick. These forms are huge, each loads a dozen of subforms, dialogs, etc. conditionally based on different business and legal rules that apply and user has to be able to edit all of that interactively. I've built the first version of that app 10 years ago using jQuery and it worked for a long time, but it took us more than 3 years to fully finish and it was huge and hard to maintain and had a number of limitations, as some legal rules were just too complex to handle. We now did a new version in Vue in less than 6 months. Much easier, much cleaner, our code deals just with our logic, not touching DOM at all, so it's much easier to debug and maintain it. Overall much nicer experience and thanks to that we were able to solve a number of problems that the old version had.
And this experience translates to pretty much any serious business web app that I've ever built.
And oh lord have I seen the result of these home brew “not a framework but actually is a framework” frameworks. They are all a rats nest nightmare for anybody but the original developer to work on.
The first thing that happens when the original developer moves on is the whole thing gets rewritten using the framework du joir.
SSR and "PRPL"-style hydration are totally compatible with React. See Gatsby's intro docs for a great example.
That's an understandable but dangerous attitude for a web developer to take.
That's a bit of a stretch. What debuggers are /you/ using?
A great phrase that puts my feelings about React or any other front-end JS framework into words. Thanks for that.
I remember AngularJS well, that’s a framework I can do without.
100% agreed. May I shamelessly plug my enormously positive experience with Elm here, with DOM being DOM, always-present time-travelling debugger, no runtime exceptions and other nicities? Main point is that you don't have to do the tradeoffs sometimes if you go full way towards a different, pure, statically-typed language.
The analog of styled-components exists, but I never used it, just regular BEM+SCSS.
This is false. I've been developing with React for over a year and a half and have never used the React dev tools. I've only ever used the browser's web inspector and it's fine. We don't write CSS in JS, so this could play in to that, but when we were evaluating those solutions it wasn't impossible to figure out what was going on, even if you had hashes for class names.
Be sure to check out the complete changelog and the tutorial linked in the announcement.
But when it comes to mobile, React-Native seems the way to go.
<script src="vue.js"></script>
most tutorials do "excalate quickly" and introduce the vue cli within the first few minutes, which is probably what most professional teams use to manage today's frontend build step (drama).Just drop it as a script on the page.
Ironically, my understanding is that it’s Vue that requires a compiler for even basic component support. If you don’t use webpack or similar tools with Vue, as far as I know, you can’t declare an idiomatic reusable Vue component.
With React, whether you use Babel/JSX/Webpack or not, components are always available. They’re the whole point.
I think it’s fair to say that Vue is initially more familiar to and easier to get started with for folks who are more comfortable with HTML. React is more JS-centric. Even though in the end they render the same DOM elements.
React takes a different approach. It doesn't "pretend" to be HTML by extending it with custom directives. Instead, it forces you to start the journey in JS land. That can be frustrating at first if you're unfamiliar with JS. But the gap between "simple" and "complex" is smaller: you learn the idea of components once, and can apply it with or without a toolchain.
I know at the end of the day, they both still come out as HTML and JS in the browser, but React just feels cleaner. At least to me.
It was a last minute idea and I'm excited about how it turned out.
I was impressed to see how well hooks worked when attaching Vscode to a chrome instance in debug mode. They just show up in the list of closures at your breakpoint. Maybe I need to try harder but I haven't been needing react dev tools.
Commits with fixes:
* https://github.com/bvaughn/react-devtools-experimental/commi...
* https://github.com/bvaughn/react-devtools-experimental/commi...
Both of these issues should be fixed in 4.0.2.
Brian goes into more detail on why we originally added these permissions during the rewrite, and why we were able to remove them: https://www.reddit.com/r/reactjs/comments/cqx554/introducing.... (TLDR: some were for features we ended up cutting; others had easier workarounds that didn't need these permissions.)
The source code is here (https://github.com/bvaughn/react-devtools-experimental/commi...). We're currently moving it into React repo so it's easier to find (https://github.com/facebook/react/pull/16381) but haven't managed to make the CI green so the source of truth for releases is still in that branch. We plan to cut over to React repo as source of truth next week.
Sounds like you're talking about extensions in general, but for what it's worth- React DevTools doesn't require any super deep permissions¹ and all of the source code is in the open².
¹ https://github.com/bvaughn/react-devtools-experimental/blob/...
² https://github.com/bvaughn/react-devtools-experimental/tree/...
The notion that there's some kind of plan to "weaken the web" there just isn't true. I don't know what you're basing it on. You may not remember this, but when React came out, everybody laughed at it. It was not some kind of asset for Facebook at the time. If we talk about motivation, ours is quite the opposite. We want to empower web developers to create complex UIs, comparable to native apps. We very much want the web to win, or at least to stay relevant.
The only reason React got open sourced and kept being developed in the open was because engineers working on it wanted to share it with the wider web community. They saw something useful in it. Eventually, the industry took note, but it wasn't until a few years later. We believe in open web, and this is why we work on React.
The notion that React is at odds with accessibility is also mistaken. React outputs regular DOM, and common React setups like Create React App include more accessibility checks than you'd get writing HTML by hand. Maybe you're confusing React with something else?
Yes, keeping dynamic JS apps accessible has its own set of challenges (we document some here: https://reactjs.org/docs/accessibility.html), but it's not React that makes it hard. It's the dynamic UI expected by users that makes it hard. If anything, in my experience React makes it easier for teams to adopt better accessibility practices by putting them directly into React components (example: https://ui.reach.tech).
Finally, concerning standards. We've worked and will continue working with standards committees to bring good parts of React into the platform. For example, the "object spread" operator in JavaScript was originally added to JSX, and was championed in TC39 by a React team member. Similarly, we're closely working with standard bodies to improve web app responsiveness. Not just for React, but for all libraries. You can learn more about this work here:
* https://github.com/WICG/is-input-pending
* https://www.youtube.com/watch?v=mDdgfyRB5kg
Happy to address any specific concerns if you have them.
> We very much want the web to win, or at least to stay relevant.
> We believe in open web, and this is why we work on React.
Who is “we” in these sentences, Facebook or the React team? If it’s the React team, then what is Facebook’s motivation? If it’s Facebook, then why on earth would anyone trust it?
The discussion here is motivated by distrust for Facebook, and suspicion about their (your) motives. The specific accusations in the thread above are perhaps a bit out there, but I don’t think it’s addressed well by focusing on the history of React but ignoring the history of Facebook.
Thank goodness, that was killing me.
Maybe the Chrome/Firefox DevTools don't, but the standalone React DevTools most definitely depend on WebSockets. My custom React renderer can't connect to them without shimming in a WebSockets implementation, for example.
https://github.com/facebook/react-native/issues/10027
The issue has been locked and is still open.
Doesn't this particular issue include a workaround?