4 ms·
Another big issue is the ability to seamless transition parts of your software between different programming models. We just don't have good solutions to this t
by tshaddox 5y ago
Another big issue is the ability to seamless transition parts of your software between different programming models. We just don't have good solutions to this that I know of. The thing with SPAs is that you are probably worse off starting with a traditional server-rendered HTML web site and slowly introducing more and more interactivity, unless you know you won't eventually be better off with an SPA at the foundation (or unless you've planned and budgeted for that eventual rewrite).
React is actually great at embedding individual interactive components on a static HTML page (like an interactive chart or table component, or even a fancy button). You can go a long way just having your Rails app render a navigation menu and application shell, and each page just loads a big React component in the main content section. Great!
But then you need to update a little bit of that application shell in response to a visitor interaction or some newly-fetched data. Maybe one of your menu links needs a little red number next to it to indicate the number of unread messages. Still easy, with JQuery or whatever DOM manipulation library you're using. But then when the visitor clicks on one MessageRow component in your big MessageList React component and reads the message. The unread count didn't change! That's still easy to fix though. But pretty soon you're writing a lot of manual DOM manipulation code to sync every bit of data bidirectionally between every source of mutation and every UI element that depends on that bit of data. You'd be better off with an SPA, or at least with having React grow to own a little bit more of your application shell!
Where this line gets drawn is tricky, and I don't think the conclusion is "always use an SPA framework from the beginning of every web site project." But I do think the options to conveniently and maintainably use SPA frameworks to render traditional HTML pages on the server are improving a lot more than the options to gradually introduce whole-page-level interactivity to traditional server-rendered HTML frameworks.
- wrnr 5y agoThe web components and the pending state protocol is one of the things I which more people would know about. Listen for change events bubbling up and push down changed values. This does not only apply to single data fields but the entire DOM tree.
- madelyn 5y agoReact can work really nicely with different parts of the DOM via Portals however!! Portals are awesome for use cases where you're sprinkling dynamic bits into an SSR'd shell. And for all parts of your app that don't need that level of interactivity, you've got plain old templates in your server side language of choice. There's some limits to this but it's a neat trick.
- z3t4 5y agoThe problem you describe is a data modeling problem, its because the same data comes from different places and is stored on multiple places, where each change triggers many changes. Its like like programming using only global variables. The solution is to have one directional data flow rather then bidirectional. UI should only listed to changes- not mutate data directly. Instead UI input should be sent to a client/server data store that in turns trigger the listeners.
- chrisweekly 5y agoYes, this. Unidirectional data flow is a fundamentally good idea. IMHO it's why React (the paradigm) has become dominant.
- chrisweekly 5y agoThis is why NextJS is so compelling; if you want to create an SPA (just like with create-react-app), it can do that. But with built-in 0-config support for SSR and SSG, you can pick and choose where and how data-fetching and rendering happen (client or server, at build-time or request time, or any hybrid combination), using one language, one paradigm, one framework. IMHO it's the obvious foundation for any greenfield (or brownfield) React project. I've been building web-related things since 1998, and IME NextJS has the best DX and most flexibility of any framework I've encountered.
- marstall 5y agoagreed. it's so in tune with the developer/web ecosystem of 2021. the fact that my React SEO landing pages are pre-cached and served by a CDN with so little config required is slightly magical.