Skip to content

This Dot Blog

This Dot provides teams with technical leaders who bring deep knowledge of the web platform. We help teams set new standards, and deliver results predictably.

Newest First
Tags:NextJS
Integrating Next.js with New Relic cover image

Integrating Next.js with New Relic

Check out our detailed guide on integrating New Relic’s application monitoring with Next.js....

These JavaScript Tools Make Collaboration and Deployment Easier with Jack Herrington cover image

These JavaScript Tools Make Collaboration and Deployment Easier with Jack Herrington

Join Jack Herrington and Tracy Lee at CascadiaJS 2024 as they talk about content creation, experimenting with new tools, and continuous learning. They cover some of the latest in what’s going on in the Vercel, Next.js, and Deno Deploy ecosystems, and what these teams are doing to enable easy deployment and better community collaboration. Tracy and Jack's discussion highlights the lack of educational resources on advanced web development topics. This scarcity poses an opportunity for developers who want to showcase their expertise in areas like app router and React server components. By actively engaging in knowledge sharing, developers can demonstrate their deep understanding of these complex concepts and set themselves apart from the competition. Jack emphasized Vercel's role in simplifying deployment with its easy commands and Next.js integration for seamless collaboration and performance. Next.js was highlighted for its advanced features and simplified development process, including efficient routing and SEO benefits. Deno Deploy, built on Deno, offers serverless deployment without traditional infrastructure management, focusing on code writing and scalability. Throughout, the importance of community and knowledge sharing in platforms like Vercel, Next.js, and Deno Deploy was underscored, enabling developers to share, receive feedback, and stay updated with advancements. Download this episode here....

Communication Between Client Components in Next.js cover image

Communication Between Client Components in Next.js

Describing different strategies for communication between client components in Next.js....

Effortless App Building with V0.dev and Next.js Training featuring Mark Shenouda cover image

Effortless App Building with V0.dev and Next.js Training featuring Mark Shenouda

In this JS Drop training, Mark Shenouda covers the capabilities of v0.dev by building a custom Next.js application. He explores the features and benefits of v0.dev, highlighting its efficiency in generating interfaces, customizing UI elements, and simplifying deployment processes. v0.dev allows users to build interfaces. The integration with Next.js is a game-changer, enabling the addition of new pages to projects with a single command. It efficiently generates different interface options, making it a valuable tool for both developers and non-developers. With v0.dev, interactive layouts can be achieved without extensive coding knowledge, opening up new possibilities for app development. One of the standout features of v0.dev is its ability to customize UI elements. The tool provides a range of options to tailor the user interface to specific requirements. Whether it's tweaking colors, fonts, or layouts, v0.dev empowers developers to create visually appealing and user-friendly interfaces. This flexibility ensures that the final product aligns with the desired aesthetic and enhances the overall user experience. v0.dev seamlessly integrates with Next.js, a server rendering framework for React. This integration brings numerous benefits, including simplified deployment processes and enhanced performance. Next.js allows for server-side rendering, resulting in faster page loads and improved SEO. With v0.dev, app development becomes more accessible and efficient, allowing for faster iterations and improved user experiences. Whether you're a seasoned developer or a non-technical individual looking to bring your app idea to life, v0.dev is definitely worth exploring....

Maximizing Server Rendering for Interactive Next.js Applications cover image

Maximizing Server Rendering for Interactive Next.js Applications

Maximize server rendering while maintaining interactivity by strategically combining React Server Components (RSCs) and client components in a Next.js application....

Improving INP in React and Next.js cover image

Improving INP in React and Next.js

A follow-up article on the new Core Web Vital INP outlining some techniques to improve your INP score in Next.js and React....

Maximizing Routing Flexibility with Next.js Parallel and Intercepting Routes cover image

Maximizing Routing Flexibility with Next.js Parallel and Intercepting Routes

Dive deep into Next.js Parallel Routes and Intercepting Routes! Unleash the potential of these features for optimized performance and seamless user experiences....

NextJS 14 Server Actions and Why Building CRUD Apps is Good For You with Dave Gray cover image

NextJS 14 Server Actions and Why Building CRUD Apps is Good For You with Dave Gray

Dave Gray talks about the shift from dynamic to static content generation, exploring how it can enhance website performance and user experience. Additionally, they explore the new server actions feature in NextJS 14, facilitating more efficient handling of server-side logic. They talk about the front-end development landscape evolving, and frameworks such as Vue, Angular, and Astro gaining traction. Dave advocates for developers to construct simple CRUD applications as a means to effectively comprehend and apply these frameworks. Dave, Tracy, and Rob debate whether developers need to develop a firm understanding of HTML, CSS, and vanilla JavaScript prior to jumping into a more complex framework. This conversation opens the door to an examination of the ongoing struggle of universities to keep pace with the swiftly evolving landscape of web technologies. With the emergence of new frameworks and tools, educational institutions find it challenging to maintain relevance in their curricula. Nevertheless, by focusing on teaching fundamental concepts, universities can empower students with the adaptability needed to learn and integrate new technologies as they arise. Beyond web development, the episode provides valuable insights into content creation and growing a YouTube channel. Dave draws from his experiences, underscoring the importance of consistency and engagement with the algorithm. Whether in web development or content creation, the overarching lesson from this episode is one of persistence. Success in any domain necessitates ongoing learning, adaptability, and a readiness to embrace new challenges and technologies. Download this episode here....

Are Performance Issues Really Next.js’s Fault? What Vercel Should Actually Be Building cover image

Are Performance Issues Really Next.js’s Fault? What Vercel Should Actually Be Building

Jay Phelps is a Senior Software Engineer at Netflix and shares his experiences and perspectives on the challenges and opportunities facing web developers. Along with Ben Lesh, Tracy Lee, and Adam Rackis, they talk about the impact of third-party services on performance optimization, what’s in store for React, and whether Next.js is really the best solution for software engineers. Jay shares his thoughts on how the web platform (aka Chrome team) can improve performance, and why some of the issues facing Next.js developers are really not Next.js’ fault. He also shares his thoughts on what Vercel could focus on (or should focus on) and why Partytown is worth looking into for those building storefronts. Download this episode here....

Deploying Next.js Applications to Fly.io cover image

Deploying Next.js Applications to Fly.io

Fly.io has gained significant popularity in the developer community recently, particularly after being endorsed by Kent C. Dodds for hosting his Epic Web project. It's a go-to choice for hobby projects, thanks to its starting plans that are effectively free, making it highly accessible for individual developers. While Next.js applications are often deployed to Vercel, Fly.io has emerged as a perfectly viable alternative, offering robust hosting solutions and global deployment capabilities. In this blog post, we'll give an overview of how to install a Next.js app to Fly.io, mentioning any gotchas you should be aware of along the way. The Project Our project is a simple Next.js project using the latest version of Next.js at the time of the writing (14). It uses the app directory and integrates with Spotify to get a list of episodes for our podcast, Modern Web. The bulk of the logic is in the page.tsx file, shown below, which represents the front page that is server-rendered after retrieving a list of episodes from Spotify. ` The getEpisodes is a custom function that is a wrapper around the Spotify API. It uses the Spotify client ID and secret (provided through the SPOTIFY_CLIENT_ID and SPOTIFY_CLIENT_SECRET environment variables, respectively) to get an access token from Spotify and invoke a REST endpoint to get a list of episodes for the given show ID. As can be seen from the above code, the Home is an async, server-rendered component. Scaffolding of Fly.io Configuration To get started with Fly.io and deploy a new project using flyctl, you need to go through a few simple steps: installing the flyctl CLI, logging into Fly.io, and using the flyctl launch command. Installing the CLI Installing flyctl is different depending on the operating system you use: - If you're on Windows, the easiest way to install flyctl is by using scoop, a command-line installer. First, install scoop if you haven’t already, then run scoop install flyctl in your command prompt or PowerShell. - For macOS users, you can use Homebrew, a popular package manager. Simply open your terminal and run brew install superfly/tap/flyctl. - Linux users can install flyctl by running the following script in the terminal: curl -L https://fly.io/install.sh | sh. This will download and install the latest version. Logging In After installing flyctl, the next step is to log in to your Fly.io account. Open your terminal or command prompt and enter flyctl auth login. This command will open a web browser prompting you to log in to Fly.io. If you don’t have an account, you can create one at this step. Once you're logged in through the browser, the CLI will automatically be authenticated. Scaffolding the Fly.io Configuration The next step is to use fly launch to add all the necessary files for deployment, such as a Dockerfile and a fly.toml file, which is the main Fly.io configuration file. This command initiates a few actions: - It detects your application type and proposes a configuration. - It sets up your application on Fly.io, including provisioning a new app name if you don’t specify one. - It allows you to select a region to deploy to. There are really many to choose from, so you can get really picky here. Once the process completes, flyctl will be ready for deploying the application. In our case, the process went like this: ` Deploying Now, if this was a simpler Next.js app without any environment variables, running flyctl deploy would build the Docker image in a specialized "builder" app container on Fly.io and deploy that image to the app container running the app. However, in our case, executing flyctl deploy will fail: ` This is because our page is statically rendered, and the Next.js build process attempts to run Home, our server-rendered component to cache its output. Before we can do this, we need to add our environment variables so that Fly.io is aware of them, but this is somewhat a tricky subject, so let's explain why in the following chapter. Handling of Secrets Most complex web apps will need some secrets injected into the app via environment variables. Environment variables are a good way to inject sensitive information, such as API secret keys, to your web app without storing them in the repository, the file system, or any other unprotected place. Unlike other providers such as the previously mentioned Vercel, Fly.io distinguishes built-time and run-time secrets, which are then injected as environment variables. Build-time secrets are those secrets that your app requires to build itself, while run-time secrets are needed while the app is running. In our case, due to the fact that Next.js will attempt to cache our static pages upfront, the Spotify client ID and client secret are needed during both build-time and run-time (after the cache expires). Build-Time Secrets Our Next.js app is built while building the Docker image, therefore build-time secrets should be passed to the Docker context. The recommended, Docker-way of doing this, is through Docker's build-time secrets, which are added through a special --mount=type=secret flag to the RUN command that builds the site. This is a relatively newer feature that allows you to securely pass secrets needed during the build process without including them in the final image or even as an intermediate layer. This means that, instead of having the following build command in our Dockerfile: ` we will have: ` Now, you can either modify the Dockerfile manually and add this, or you can use a helpful little utility called dockerfile: ` If we were using docker build to build our image, we would pass the secret values like so: ` However, in our case we use fly deploy, which is just a wrapper around docker build. To pass the secrets, we would use the following command: ` And now, the app builds and deploys successfully in a few minutes. To summarize, if you have any secrets which are necessary at build-time, they will need to be provided to the fly deploy command. This means that if you have a CI/CD pipeline, you will need to make sure that these secrets are available to your CI/CD platform. In the case of GitHub actions, they would need to be stored in your repository's secrets. Run-Time Secrets Run-time secrets are handled in a different way - you need to provide them to Fly.io via the fly secrets set command: ` Now, you might be wondering why fly deploy cannot use these secrets if they are already stored in Fly.io. The architecture of Fly.io is set up in such a way that reading these secrets through the API, once they are set, is not possible. Secrets are stored in an encrypted vault. When you set a secret using fly secrets set, it sends the secret value through the Fly.io API, which writes it to the vault for your specific Fly.io app. The API servers can only encrypt; they cannot decrypt secret values. Therefore, the fly deploy process, which is, if you remember, just a wrapper around docker build, cannot access the decrypted secret values. Other Things to Consider Beware of .env Files In Next.js, you can use .env as well as .env.local for storing environment variable values for local development. However, keep in mind that only .env.local files are ignored by the Docker build process via the .dockerignore file generated by Fly.io. This means that if you happen to be using an .env file, this file could be bundled into your Docker image, which is potentially a security risk if it contains sensitive information. To prevent this from happening, be sure to add .env to your .dockerignore file as well. Not Enough Memory? For larger Next.js sites, you might run into situations where the memory of your instance is simply not enough to run the app, especially if you are on the hobby plan. If that happens, you have two options. The first one does not incur any additional costs, and it involves increasing the swap size. This is not ideal, as more disk operation is involved, making the entire process slower, but it is good enough if you don't have any other options. To set swap size to something like 512 MB, you need to add the following line to the fly.toml file near the top: ` The second one is increasing memory size of your instance. This does incur additional cost, however. If you decide to use this option, the command to use is: ` For example, to increase RAM memory to 1024 MB, you would use the command: ` After making the changes, you can try redeploying and seeing if the process is still crashing due to lack of memory. Conclusion In conclusion, deploying Next.js applications to Fly.io offers a flexible and robust solution for developers looking for alternatives to more commonly used platforms like Vercel. We hope this blog post has provided you with some useful insights on the things to consider when doing so. Be sure to also check out our Next starter templates on starter.dev if you'd like to integrate a few other frameworks into your Next.js project. The entire source code for this project is available on Stackblitz....

Exploring the Hidden Gems of the Next Image Component: What You Might Be Overlooking cover image

Exploring the Hidden Gems of the Next Image Component: What You Might Be Overlooking

A blog post that explores hidden features that are easy to overlook...

Next.js Route Groups cover image

Next.js Route Groups

Learn how to organize and optimize your application routing with ease. Say goodbye to messy routes and hello to a more intuitive and maintainable structure with the new Next.js Group Routes!...