JavaScript and WordPress: Thoughts on the React Debate

JavaScript developer coding in React

The web is moving steadily toward being an API-driven medium, and JavaScript is playing a huge role in that. However you feel about it, it’s a fact. Over the past year or so, I’ve found some general consensus among other developers. Front-end developers are thrilled, because this opens up a brand new realm of possibilities. Back-end developers often have mixed feelings, because this adds an additional layer of complexity to every build, not just specific use cases. And full-stack developers such as myself…well, I think we sort of groan and move forward knowing that our tech stack just became fundamentally more fragmented.

JavaScript and the Decoupled Content Management System

In case you’re wondering, “what is this drama that I’ve apparently heard nothing about,” let me give you a really high-level view. The web is marching steadily toward decoupled, or “headless” content management systems being the standard. The first iteration of Angular showed us what was really possible for single page applications, and since it took the development world by storm, we’ve begun to see more hybrid applications (in which external web APIs are consumed within a portion of a more traditional site), as well as fully headless CMS instances in the wild. A headless CMS is essentially one that uses the CMS…WordPress or Drupal, for example…as the portal through which the content is generated, and then serves that content up as JSON endpoints. Those endpoints can then be consumed in a method of the front-end developer’s choosing, completely agnostic as to platform. That’s where JavaScript comes in, because, in the headless model, we’re no longer bound by the CMS’ templating system. We now have a front-end templating layer (or, in some cases, a complete MVC structure) that lives independently of the system which is managing the content. JavaScript, at the least, handles the business logic of this front end.

The advantage to this is flexibility. Every content management system has it’s limitations, many of which can be overcome by a front-end infrastructure that only exists as a detached presentation layer for content that is served from elsewhere.

Core JavaScript Frameworks

As a result, most content management systems, as well as PHP frameworks, are moving to adopt an “official” JavaScript framework to be used in their core infrastructure. There are older JavaScript frameworks in use that still very popular, such as Backbone, but the two popular contenders right now are React and Vue.js.

React is a lightweight presentation layer of web components that was built by Facebook and released under an open-source-but-not-really license. Vue.js was built in response to Angular as a more lightweight solution, and has gained a lot of popularity recently as the JavaScript community has largely cooled toward Angular after all of the drama surrounding it’s lack of upgrade path and other issues. These two are the frameworks currently under consideration by the WordPress core team to be adopted as the official JavaScript framework in core.

The word on the street is that React is the leading contender, due largely to the fact that Automattic uses it in their projects. I’m concerned that this will be the case, and that the WordPress project is about to make a very poor decision.

Issues with React

I have many issues with React, but I’ll limit them to my top three here. The first is licensing, but let me go into this with the caveat that I hate Facebook. Their callous disregard for their users’ privacy and the fact that user data is treated as an academic experiment is unconscionable to me. This is the reason that I stopped using Facebook, even though I have positive memories associated with it’s origins (I met my wife on Facebook). When Facebook created React and released it to the world, they did so under a license that permits them to revoke a user’s permissions to use the framework in their project. Should this happen, the application using it would have to come down, and significant re-factoring would have to occur (essentially a re-build) in order to be free from Facebook’s power-hungry control. You can do the math. If WordPress core uses React as it’s JavaScript framework, and Facebook decided to revoke this license, then a huge percentage of the web would legally have to come down overnight. This flies in the face of WordPress’ open source philosophy of democratizing the web, which is why I’m earnestly mystified as to the choice of React as a contender. Drupal, in fact, immediately ruled out React as their core JavaScript framework last year for exactly such a reason.

React also has a steep learning curve. This is also a confusing point for me, as another central tenant of the WordPress philosophy has been to make the process of learning easier for developers new to the platform. React introduces an extremely opinionated methodology, to say nothing of an opinionated set of tooling, that seems to fly in the face of what WordPress has done previously.

In addition, I’ll admit that I have philosophical issues with React. Introducing another programmatic layer to the front-end stack to render the DOM not only negatively impacts performance, but also is, in my opinion, a very poor separation of concern. Let the DOM be the DOM.

Vue.js, the other potential alternative for the new WordPress core JavaScript framework, is also very lightweight, but shows a good separation of concern and a much shorter learning curve (especially for anyone who has experimented at all with Angular). I’m quite fond of Vue, and I’m concerned that it is not receiving due attention simply because the developers at Automattic hold too much sway in the direction that the WordPress project takes.

Moving Forward

Based on what I’ve seen, theme developers will continue to maintain their freedom in regards to tooling and frameworks. I’m hoping that’s the case for plugin developers, as well. WordPress has always chosen to remain fiercely loyal to backward compatibility, making sacrifices in order to do so, so I think that that this is a reasonable conclusion. Still, if the decision is made to adopt React as “the” front-end framework for WordPress core, then the WordPress project will not only place itself into a concerning legal situation that can compromise its status as a truly open-source framework, but also diminish its value to the community at large. This says nothing of the fact that JavaScript frameworks tend to have a very short shelf-life, and I suspect that React’s popularity will go the way of Angular’s within a year or so. Time will tell.

The final decision about the core framework is set to be made at WordCamp Europe, so we should have an answer soon. For the sake of the project, I truly hope that the answer is Vue.js and not React.

Photo Attribution: Marcus Bernales under Creative Commons

Leave a Reply

Your email address will not be published. Required fields are marked *

Some html is allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

*
*

This site uses Akismet to reduce spam. Learn how your comment data is processed.