We recently added a new component to Broadcasts. Here's a behind-the-scenes look at the technical process.
Both development and design share a common task: solving problems. As a Design Engineer, I often combine tools from both worlds to solve problems for our customers. Let's explore the process of adding a new component to Broadcasts, our no-code editor, from challenge to solution.
I'll expose my research, the thought process for developing the component, and the challenges and lessons I learned along the way.
As with everything we create, we want the Broadcast editor to be second to none. The editing experience should be easy, intuitive, and as simple as writing a document.
Emails may benefit from embedded media like videos, social posts, and third-party integrations, but this media is often dynamic, while email is static.
As one example, for nearly two decades, ๐ (formerly Twitter) has played a key role in online communication. As a result, it has become a common practice to embed ๐ posts.
Since email is static, we faced the challenge of embedding something dynamic (an ๐ post). Given that email-safe HTML cannot embed an ๐ post, so we needed to find a way to convert any post to an email-friendly form.
๐ post
โ Email
Dynamic
โ Static
We began exploring possible options and dismissed the following:
Luckily, we found the solution using three excellent tools made by Vercel. In short, we use ๐ post data and dynamically create an image via a Next.js function for use in the Broadcast editor.
The three tools we used were:
ImageResponse
constructor.ImageResponse
to create images using JSX syntax. It renders our custom post UI to an SVG. The Next.js response will then capture the rendering and return a JPG.Finally, we save the rendered JPG into the static host (S3 bucket) and embed it into the email HTML body, wrapping it with an anchor tag directed to the ๐ post.
What does it look like?
The journey to a solution included several challenges and edge cases. These issues allowed the output to be more polished and visually closer to an ๐ post layout. There were a few key challenges:
The ImageResponse
constructor receives a ReactElement
and an options
object, which allows you to set the width and height of the image.
Since the constructor requires passing both the element and the dimensions simultaneously, it produces a sequencing challenge, as we need to know the dimensions of the rendered image before it is rendered.
Thankfully, we found a way to predict the dimension of the image by:
We calculate the final dimensions of the image by adding the dimensions of these elements beforehand. We then pass these calculated dimensions to the ImageResponse
and the JSX to render the image.
Due to its special use case, the Satori library used by Next.js ImageResponse
supports a limited subset of HTML and CSS. For one, it does not support css variables for switching themes. Additionally, Satori requires styling all elements with the style attribute.
We felt it was important to provide light and dark themes for maximum flexibility in the editor to match the users' content theme. We created a custom theme object to switch between themes from the Broadcast quickly.
We faced various other challenges, like supporting different screen densities, styling mentions, hashtags, links, and more, but we couldn't be happier with the final result.
Sending professional, modern emails is crucial for our customers. A modern email editor should make it easy to stand out from the crowd and communicate in various formats.
We want the editor to get out of the way so you can focus on what matters most to you: connecting with your readers. We're striving to make it easy to create engaging emails, communicate your brand, and bring value to your readers.
In the future, we want to support all possible post variations, including reposts, responses, and more.
We are confident the lessons we learned while creating this component will continue to benefit you as we develop additional media types, including posts, videos, and more on other social media platforms.