This April 2023 roundup collects five things our team learned: CSS trigonometry functions, new Action Mailer delivery callbacks in Rails, tips for GitHub Copilot, the CSS text-wrap: balance value and TypeScript's infer. The text-wrap: balance item gets an update below, because the property has changed since this post.
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.
CSS Supports Trigonometry Functions#
Trig functions in CSS make it easier to rotate objects and let us avoid using magic numbers. For example, sin(60 degrees) expresses the developer's intent more clearly than 0.866025.
Action Mailer Now Supports *_deliver Callbacks#
Three callbacks (before_deliver, after_deliver, around_deliver) have been added to Action Mailer. You may have strong feelings about callbacks and I probably tend to agree with you, but sometimes they are the right tool to reach for. The described use cases for this include updating an Active Record model's delivered_atwhich is especially useful when dealing with async deliveries), handling delivery errors, and executing tasks that require a delivery provider's message_id.
Useful Tips for Using GitHub Copilot#
Like any other tool, GitHub Copilot has a learning curve. This article from GitHub developer advocate Rizel Scarlett gives us a few tips to quickly improve the quality of Copilot suggestions. One thing I didn't realize: Copilot uses your open tabs to provide context for the questions you ask! That tip in and of itself really helped me make better use of the tool in my day-to-day work.
CSS text-wrap: balance#
Chrome Canary now includes a new experimental CSS feature, text-wrap: balance, that evaluates line breaks to balance blocks of text. As developers, we often look for solutions that help to keep text consistent regardless of final font size, screen size, and language, which are often unknown. This property aims to mitigate those concerns, though it is not without its challenges. It is currently limited to four wrapped lines (and under) and presents some performance considerations due to the iterative technique used to perform the wrapping.
CSS text-wrap: balance today#
When we wrote this, text-wrap: balance was an experiment in Chrome Canary. MDN now lists the text-wrap property as widely available across browsers. It is a shorthand for two properties, text-wrap-mode and text-wrap-style, and it controls the soft line breaks the browser chooses inside a block of text. It takes these values:
| Value | What it does |
|---|---|
wrap | The default. Text wraps at appropriate points, such as spaces, to minimize overflow. |
nowrap | Text does not wrap and overflows its container instead. |
balance | Text wraps so each line has a similar number of characters. It only works on blocks with a limited number of lines, because balancing is expensive to compute. |
pretty | Wraps like wrap but uses a slower algorithm that favors better layout, meant for body copy, for example to avoid orphans. |
stable | Wraps like wrap, but while a user edits the text, lines before the one being edited stay put. |
The limit we mentioned above still applies in a new form: MDN says balance is only supported for blocks of text spanning a limited number of lines, and that the limit differs between browsers. That makes it a good fit for headings, captions and short pull quotes, and pretty the better choice for long paragraphs.
A simple way to use CSS text wrap balance. To understand where it helps in a design, take the following example. A rule like h1, h2, h3, blockquote { text-wrap: balance; } evens out line lengths in headlines and short quotes, so the lines come out closer in length. In browsers that support it, a separate rule, p { text-wrap: pretty; }, gives paragraphs slower, better-looking wrapping; other browsers ignore it and wrap as usual.
TypeScript's infer#
TypeScript's Conditional types have allowed developers to build internal type logic based on types provided to the conditional-Model<string> might have subtle differences in signature from Model<number>. Now, TypeScript has given us infer, allowing us to identify and refer to dynamic type values from within a Conditional type. It sounds like a lot (and it kind of is: the uses for this are pretty niche!) but once you wrap your head around it, you'll have a powerful new TypeScript tool in your arsenal.
Contributors:#
Learn more about how The Gnar builds software.


