Upgrading This Site From Rails 5.2 - My Initial Rails 6.0 Impressions

Published: March 8,  2019
     I recently abandoned this website for a couple of months. After hearing about the release of the Rails 6 beta, I decided to nuke the server this site lives on, and take 6.0 for a spin. I'm still in the transition process of that upgrade, but so far, it has been a pleasant experience. The only bugs I've encountered while porting over my code, have been my own. Rails 6 seems to be very stable already, and hasn't broken anything one me. Which is good, because the Rails team plans to have an official release ready in less than 2 months. It's also worth noting, that some companies, like Basecamp and Shopify, are already running Rails 6 in production.

     Rails 6.0 has quite a few new things going on under the hood. For one, it now requires Ruby 2.5 or higher, so if you're using an older build of ruby, upgrade ruby, or stay away from Rails 6 for now. What immediately leaped out at me, is the new app/javascripts/ folder. The default javascript directory was rehomed to app/javascript/, from app/assets/javascripts. The other big change was the new app/node_modules/ folder. Rails 6.0 also includes Webpacker now by default, as the new JavaScript processor. You can read about more about webpacker, at webpack.js.org. I'm not an expert on webpacker, but basically, it's sales pitch, is that it should make our lives, importing node modules, and using javascript in our applications, faster and easier. And so far, I have no complaints. About webpack.

     I am a little unhappy with the new node_modules folder. It drags in a lot of dependencies. Like, a lot, a lot of dependencies. I created two separate Rails projects, to compare the size of an empty Rails 5.2 vs 6.0 project, and I was kind of unhappy with the results.  Here are the commands I ran on each project.
    ls -lR rails_project_directory | wc -l #get file count of rails project directory
    du -ch rails_project_directory | grep total #get size of rails project directory

     I found that a brand new Rails 5.2 project, contains 239 files, and weighs in at 528 kilobytes. A brand new Rails 6 project, contains a whopping 24,812 files, and weighs in at a relatively massive 136 megabytes. Now, to be fair to Rails 6, 107 megabytes, of that 136 megabytes, is the node_modules folder. It also makes up 22,139 of the files. Rails, hasn't really gotten that much bigger. It just pulls a much larger set of dependencies. I tried deleting a couple of modules I knew I wasn't using, like one for Amazon' AWS, and it broke the project. I believe you can remove unneeded modules, but I couldn't get this to work in practice. This probably stems from my unfamiliarity with webpack.

     Personally, I hope that the Rails 6 official release, will change it's default behavior, away from pulling down this huge folder of node_modules, to only pulling down the actual modules, that Rails is dependent on. And to be even more fair to the current Rails beta, this isn't a Rails issue. It's a node issue. Node developers have complained about the size of node_modules, for awhile now.

     There are some positives from this new marriage to node. And that's that node has a very large ecosystem, with lots of well documented modules and plugins, and it's now easier than ever to leverage this ecosystem, in Rails. I use CKeditor, to type up the posts on this site. In Rails 5, I was using this gem, https://github.com/galetahub/ckeditor, for integrating CKeditor4. In Rails 6, I used Yarn to install a build of CKeditor5, I went into app/javascript/packs/application.js, and told it compile my CKeditor module, and then I was able to call the editor in a few lines of JavaScript, in one of my views. This could not have been much easier.

     By the way, if you aren't familiar with it, CKeditor, is a great WYSIWYG rich text editor, and you can read about it here, ckeditor.com. However, Ckeditor, was kind of a bad example, because Rails 6, has a new component, called ActionText, that allows you to easily use Trix, another WYSIWYG editor. After spending a little time with ActionText, I totally abandoned Ckeditor, I haven't worked with ActionText yet, but it looks very promising, and I will be adding to this site pretty soon. Semi related note, we are also supposed to be getting legitimate file validations in Active Storage, with Rails 6. I like Active Storage, but the lack of a good file validation system, has kept me working with Carrierwave and Shrine. Rails 6 may finally change that.

     I think the new marriage with Node, and the inclusion of Webpack, are some of the most striking changes to Rails 6, they are definitely what jumped out at me the most. Now, let's talk about the other side of a new release, the deprecations. Well, I actually don't have a lot to say about deprecations. Luckily, I haven't run into issues with anything that was deprecated. I couldn't get that CKeditor gem I was using, to work in Rails 6. But, I was given multiple replacements that were better. If you want the latest scoop on deprecations, I recommend checking out this blog post, https://blog.driftingruby.com/ruby-on-rails-6-0-beta-1-deprecations/, or read through some of the changelogs, linked in the official release notes of the Rails 6 betas, here, https://edgeguides.rubyonrails.org/6_0_release_notes.html.

     This is not a comprehensive review of Rails 6 or anything, just some thoughts I have after playing with it for a couple of evenings. So far I like most of what I see. It's got it's ups and downs, but I would definitely declare Rails 6 a step forward. You should take it for a spin. I'm not saying nuke your production server, and upgrade right now(like I did), but if you've got a good ruby manager(Rbenv > RVM), install Rails --pre, and give 6.0 a shot.