kartheek
Heex engine validates html. Some level of html validation is needed to avoid tag soup and clean code.
Consider the following snippet:
def div_wrapper_bug(assigns) do
assigns = assign_if_nil(assigns, :wrapper_class, nil)
~H"""
<%= if @wrapper_class do %>
<div class={@wrapper_class}> <!-- opening tag -->
<% end %>
<%= render_slot(@inner_block) %>
<%= if @wrapper_class do %>
</div> <!-- closing tag -->
<% end %>
"""
end
As you can see the above snippet will always produce valid html. But compilation will fail with below message:
** (Phoenix.LiveView.HTMLTokenizer.ParseError) lib/<YourProject>/form.ex:177:5: missing opening tag for </div>
(phoenix_live_view 0.17.5) lib/phoenix_live_view/html_engine.ex:227: Phoenix.LiveView.HTMLEngine.pop_tag!/2
(phoenix_live_view 0.17.5) lib/phoenix_live_view/html_engine.ex:432: Phoenix.LiveView.HTMLEngine.handle_token/2
(elixir 1.13.0) lib/enum.ex:2396: Enum."-reduce/3-lists^foldl/2-0-"/3
(phoenix_live_view 0.17.5) lib/phoenix_live_view/html_engine.ex:86: Phoenix.LiveView.HTMLEngine.handle_end/1
(eex 1.13.0) lib/eex/compiler.ex:191: EEx.Compiler.wrap_expr/5
(eex 1.13.0) lib/eex/compiler.ex:140: EEx.Compiler.generate_buffer/4
(eex 1.13.0) lib/eex/compiler.ex:82: EEx.Compiler.generate_buffer/4
(phoenix_live_view 0.17.5) expanding macro: Phoenix.LiveView.Helpers.sigil_H/2
(<YourProject> 0.1.0) lib/<YourProject>/form.ex:171: Form.div_wrapper_bug/1
The below snippet will compile:
<%= if @wrapper_class do %>
<div class={@wrapper_class}>
<%= render_slot(@inner_block) %>
</div>
<% else %>
<%= render_slot(@inner_block) %>
<% end %>
The problem with workaround snippet is we will have to duplicate code. render_slot is simplified example - it may be a html block.
I logged a bug on phoenix_live_view - it is closed as not a bug. Missing opening tag error when using `if` and closing tag is not present in same `if` block · Issue #1856 · phoenixframework/phoenix_live_view · GitHub
Discussion is about the heex engine’s html validation:
- what level of validation is needed - strict or loose, etc?
- what should be done in scenarios where a valid html is generated and but compiler is not sure 100% ?
- should it have configurations to treat certain kinds of errors as warnings
- should there be escape hatch (annotation) to disable validations on a block which produces valid html which is not understood by heex engine.
Please share your thoughts on it.
EDIT:
Jose updates on github issue.
- The escape hatch exists, you can render the tags dynamically:
<%= raw "<div ...>" %>
<%= raw "</div>" %>
- what cannot be done is to render the tags statically and conditionally.
Trending in Discussions
As the title says, please share what you’ve been up to with Elixir. Whether that’s been learning it, looking into it, making stuff with i...
New
I want to open this thread for you all to discuss and help those who really like Ash but are still hesitant to use it in a real project. ...
New
I am happy to introduce the very α version of the new programming language compiled to BEAM.
Welcome Cure.
It has literally three kille...
New
I’m posting this in response to Jose’s recent tweet (Cr. link) :
People are sleeping on Elixir for a coding harness:
Hot-code swappi...
New
Hello,
I wrote Stop My Hand, a Scattergories-like web application using Phoenix/LiveView as my learning project for Elixir (after readin...
New
It would be helpful to have a list of companies worldwide that hire engineers without prior experience in Elixir. Often, it can be quite ...
New
Anyone running long-lived stateful processes on BEAM? We’re building an AI agent runtime and would love to compare notes.
We’re a small ...
New
Other Trending Topics
Hobbes is a low-level distributed database for the Elixir programming language.
Hobbes provides a simple, safe, and scalable storage lay...
New
Hi there! We created Gust: A task orchestrator inspired by Airflow.
For those who have never heard about Aiflow, it’s a Python-based wor...
New
Beam Bots (or just BB for short) is a framework for building fault-tolerant robotics applications in Elixir using familiar OTP patterns. ...
New
Xamal is a deployment tool for Elixir apps that deploys native releases to bare metal servers over SSH. It’s a port of GitHub - basecamp/...
New
Hello everyone. After busy few months I am happy to announce v0.1.0 of Emerge & Solve.
They are GUI (Emerge) and State management (S...
New
There are three potential reasons for members of this forum to have a look at https://vutuv.de
You are tired or annoyed of LinkedIn.
Yo...
New
Categories:
Sub Categories:
Forums
Popular Tags
- #ecto
- #liveview
- #troubleshooting
- #learning-elixir
- #library
- #deployment
- #erlang
- #testing
- #genserver
- #mix
- #absinthe
- #remote-other
- #otp
- #plug
- #how-to-question
- #macros
- #postgres
- #elixirconf
- #channels
- #exunit
- #discussion
- #code-sync
- #podcasts
- #javascript
- #onsite
- #dialyzer
- #docker
- #authentication
- #umbrella
- #full-time-contract
- #podcasts-by-brainlid
- #ecto-query
- #blog-post
- #elixirconf-us
- #elixir-ls
- #ai
- #phoenix_html
- #iex
- #graphql
- #genstage
- #websockets
- #supervisor
- #advent-of-code
- #distillery
- #processes
- #api
- #forms
- #hex
- #security
- #metaprogramming











Showing Posts 1 to 2- Show Best Posts
- Show All (oldest first)
- Show All (newest first)
LostKobrakai
I think this is a good thing as is, because as soon as you introduce backdoors of things the compiler cannot be aware of it’s whole usefulness goes down the drain. If you’re worried about duplicating markup you can just make this optional wrapper thing a function component:
This way the small amout of duplication is nicely contained and reusable.
benwilson512
This 100%. The whole point of the feature is to provide guarantees, which means that the compiler needs to be able to know 100% of the time.
The level of analysis required to infer that the given example always works is on a whole other level from simply looking for matching tags, and also immediately fails the moment more complex functions get involved.