Phoenix 1.6 released!

We have a new version of the most popular Elixir framework - Phoenix framework. Version 1.6.0 has been released.

Generator update

To use the new version when running the command mix, it is necessary to update the generator. You can achieve this through the command:

  mix archive.install hex phx_new 1.6.0

New generators

With the new version of the framework, new generators have appeared. They concern the most frequently implemented functionalities, i.e., authentication and mail handling.

phx.gen.auth will allow you to complete an authentication solution bootstrapped into your application. Details of the solution can be found in the entry here. However, the most important are:

  • Griffin Byatt, the creator of Sobelow, a security-focused static analysis for the Phoenix, was responsible for the security of the solution;
  • hash functions prepared earlier by David Whitlock under comeonin libraries were used - nothing new was needed, used solutions proven in production conditions;
  • HTTP cryptography available through Phoenix and Plug was too low-level - it was necessary to prepare a new Plug version, providing a high-level API for signing, encryption, and built-in support for signed and encrypted cookies;
  • the authentication system has 100% code coverage;
  • the business domain code (the Phoenix context and Ecto schemas) is only 340 LOC (lines of code) - a powerhouse in a very small and verifiable code.

The second generator is phx.gen.notifier. It allows you to prepare a simple notifier for sending an email and a dev mailbox for local development. Of the two, I strongly recommend you familiarize yourself with authentication as this solution may be sufficient for your projects.

LiveView HEEx engine

The new version of LiveView is also available with a new engine for creating HTML files. The new engine not only enforces proper HTML but provides syntax conveniences for rendering components. The code is based on Surface UI - Phoenix’s server-side rendering component library.

The new engine will be used in all future HTML files generated by Phoenix (using generator commands).

The new HEEx engine enforces stricter expressions (in the case of interpolating HTML tags and attributes). The standard start and end of code block <%= %> in EEx expressions has been replaced with {}. To make this process easier, you can use eextoheex posted on GitHub. There are possible errors in the code prepared by this tool. However, it is still a huge help, especially in larger projects. Instead of manually changing hundreds of files, just check the result and make corrections (if necessary).

Thanks to the engine and functional components changes, an ecosystem of shared and reusable components was laid.

Migration between versions

The way to migrate from version 1.5 to version 1.6 has been presented on GitHub. The requirement is to update the dependencies to support the new version.

  def deps do
      {:phoenix, "~> 1.6.0"},
      {:phoenix_html, "~> 3.0"},
      {:phoenix_live_view, "~> 0.16.4"},
      {:phoenix_live_dashboard, "~> 0.5"},
      {:telemetry_metrics, "~> 0.6"},
      {:telemetry_poller, "~> 0.5"},

The gist includes two optional steps. One is to migrate from .html.eex and .html.leex to .html.heex (HEEx engine). The second is a way to use the last of the new features of this version of the framework - esbuild support in building a project.

Node and webpack free asset building with esbuild

A huge change has been made to the way resources are handled. They removed webpack and node. You no longer have to worry about the need to have a node to build JS and CSS resources.

By using esbuild, projects can use portable binaries for a cross-platform, dependency-free build for resources. For more advanced needs, webpack will still be very useful. However, for smaller projects, it may be possible to abandon them altogether.

It is also a success to extract the Phoenix.View module as a separate phoenix_view library. From now on, you won’t need to use the entire phoenix project if you are only interested in rendering views.

Good luck with your migration to the latest version!

Get new posts and extra comments

You'll receive every new post with extra unpublished comments available only to the subscribers!

I won't send you spam. Unsubscribe at any time.