Gnarly Learnings from May 2023
Tags: rails, nextjs, ruby, javascript
Published: 2023-05-31 16:23:20


At The Gnar we are always reading, watching, and listening in order to keep our skills sharp and our perspectives fresh. Here are some of the resources we learned from this month.


## [Automatic Fetch Request Deduping with Next.js](https://nextjs.org/docs/app/building-your-application/data-fetching#automatic-fetch-request-deduping)

NextJS focuses a lot on optimization. So it was no surprise to learn about [fetch request deduping](https://nextjs.org/docs/app/building-your-application/data-fetching#automatic-fetch-request-deduping). When using fetch with Next, any GET requests with the same input will be cached, so that if there are multiple requests for the same resource during a render cycle or between page refreshes, Next will not make the HTTP request again.


## [Variable Fonts in Google Fonts](https://fonts.google.com/variablefonts)

I am always deliberating over which and how many font weights and variants to import from Google Fonts. I want them all, but am I willing to accept the file size overhead? Luckily Google has come up with a significant improvement to web fonts: variable fonts. These fonts allow for a single font to be selected, and that font can be adjusted by weight, slant, and more. Read more about [variable fonts](https://fonts.google.com/knowledge/introducing_type/introducing_variable_fonts).


## [Active Record’s `rewhere`](https://api.rubyonrails.org/classes/ActiveRecord/QueryMethods.html#method-i-rewhere)

It now takes two hands to count the number of years I have been working with Ruby on Rails and I _still_ regularly discover new concepts and methods. This month, it was `rewhere`, an Active Record method that allows you to change a previously set `where` condition for an attribute. If you’re thinking “Hey…that sounds an awful lot like the behavior of `unscope`” you’d be right! That’s because it is a shorthand for `unscope(where: conditions.keys).where(conditions)`. 


## [Cross-Browser Support for Import Maps](https://web.dev/import-maps-in-all-modern-browsers/)

A modern choice for including and reusing JavaScript code in web apps is ES modules. There are a variety of ways to implement ES modules but [import maps](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/script/type/importmap) have been gaining popularity in recent years. Popularity, in this case, equates to industry adoption. For example, Rails 7 (released in 2021) allowed us to break away from the Node.js and webpack bundling strategy and leverage import maps instead. Now, import maps are compatible across the three major browser engines which will make developing with them much easier.


## [Migration Method: `create_join_table`](https://github.com/rails/rails/blob/83217025a171593547d1268651b446d3533e2019/activerecord/lib/active_record/connection_adapters/abstract/schema_statements.rb#L381)

I was late to this party! When creating a join table in Rails, there's no need to pass `id: false` to a typical table creation method. Instead, just reach for [`create_join_table`](https://api.rubyonrails.org/v7.0.4.2/classes/ActiveRecord/ConnectionAdapters/SchemaStatements.html#method-i-create_join_table). 


## Contributors:

* [Ethan Fertsch](https://github.com/efertsch)
* [Taylor Kearns](http://github.com/taylorkearns)


_Learn more about how The Gnar [builds software](https://www.thegnar.com/software-development)._