jshprentz

jshprentz

Programming Phoenix LiveView B10.0: Some readers do not use VSCode (page 191)

Page 191 shows two screenshots of helpful warning messages about faulty calls to function components. The book explains:

The Elixir Language Server extension in VSCode provides us with these helpful warnings.

This is the first and only mention of VSCode in the book. Some users might not use VSCode. (I use Vim.)

I suggest showing the consequences of the faulty calls when VSCode is not used.

The first survey_live.html.heex example calls the hero component with a content attribute that has an invalid type.

<Component.hero content={123} >
  Please fill out our survey
</Component.hero>

The Phoenix server logs this warning:

warning: attribute "content" in component PentoWeb.SurveyLive.Component.hero/1 must be a :string, got: 123
  lib/pento_web/live/survey_live.html.heex:1: (file)

The survey web page displays the content 123.

The second example calls the hero component without any inner_block content.

<Component.hero content="Survey" />

The Phoenix server logs this error with a stack trace:

** (exit) an exception was raised:
    ** (KeyError) key :inner_block not found in: %{__changed__: nil, __given__: %{__changed__: nil, content: "Survey"}, content: "Survey"}

The web browser displays an error page with the error message, a listing of the hero component, and a stack trace.

It is interesting that Phoenix reports no warning or error when the inner_block content is omitted with either of these representations:

<Component.hero content="Survey" >
</Component.hero>

or

<Component.hero content="Survey" ></Component.hero>

In both cases, the web browser displays a reasonable page with no inner_block content.

The source HTML shows the two header elements of the hero component with the content attribute value and empty inner_block content interpolated:

<h1 class="font-heavy text-3xl">
  Survey
</h1>
<h3>
  
</h3>

Where Next?

Popular Pragmatic Bookshelf topics Top

belgoros
Following the steps described in Chapter 6 of the book, I’m stuck with running the migration as described on page 84: bundle exec sequel...
New
mikecargal
Title: Hands-On Rust (Chapter 11: prefab) Just played a couple of amulet-less games. With a bit of debugging, I believe that your can_p...
New
alanq
This isn’t directly about the book contents so maybe not the right forum…but in some of the code apps (e.g. turbo/06) it sends a TURBO_ST...
New
gilesdotcodes
In case this helps anyone, I’ve had issues setting up the rails source code. Here were the solutions: In Gemfile, change gem 'rails' t...
New
adamwoolhether
When trying to generate the protobuf .go file, I receive this error: Unknown flag: --go_opt libprotoc 3.12.3 MacOS 11.3.1 Googling ...
New
hazardco
On page 78 the following code appears: &lt;%= link_to ‘Destroy’, product, class: ‘hover:underline’, method: :delete, data: { confirm...
New
jonmac
The allprojects block listed on page 245 produces the following error when syncing gradle: “org.gradle.api.GradleScriptException: A prob...
New
andreheijstek
After running /bin/setup, the first error was: The foreman' command exists in these Ruby versions: That was easy to fix: gem install fore...
New
davetron5000
Hello faithful readers! If you have tried to follow along in the book, you are asked to start up the dev environment via dx/build and ar...
New
SlowburnAZ
Getting an error when installing the dependencies at the start of this chapter: could not compile dependency :exla, "mix compile" failed...
New

Other popular topics Top

dasdom
No chair. I have a standing desk. This post was split into a dedicated thread from our thread about chairs :slight_smile:
New
AstonJ
There’s a whole world of custom keycaps out there that I didn’t know existed! Check out all of our Keycaps threads here: https://forum....
New
PragmaticBookshelf
Rust is an exciting new programming language combining the power of C with memory safety, fearless concurrency, and productivity boosters...
New
New
AstonJ
Just done a fresh install of macOS Big Sur and on installing Erlang I am getting: asdf install erlang 23.1.2 Configure failed. checking ...
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New
PragmaticBookshelf
Build highly interactive applications without ever leaving Elixir, the way the experts do. Let LiveView take care of performance, scalabi...
New
AstonJ
If you get Can't find emacs in your PATH when trying to install Doom Emacs on your Mac you… just… need to install Emacs first! :lol: bre...
New
Help
I am trying to crate a game for the Nintendo switch, I wanted to use Java as I am comfortable with that programming language. Can you use...
New
AnfaengerAlex
Hello, I’m a beginner in Android development and I’m facing an issue with my project setup. In my build.gradle.kts file, I have the foll...
New

Sub Categories: