Skip to content

Components returning empty string or new line are triggering malformed html error in liveview #264

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
mhanberg opened this issue Feb 20, 2025 · 1 comment

Comments

@mhanberg
Copy link
Owner

Describe the bug

Reported by @evnp

#2

The second issue seems to relate to temple do blocks which may return nothing. I have this simple component, which worked fine on my previous version of Temple (0.14.0):

    defp unread_message_counter(assigns) do
      temple do
        if @count > 0 do
          span class: "flex items-center justify-center
                       bg-blue-500 rounded-full font-medium h-5 px-2ml-auto
                       text-xs text-white"
          do
            @count
          end
        end
      end
    end

Rendering this component with this branch installed leads to this error:

Screen Shot 2025-02-19 at 4 11 55 PM

If I update to this, it works fine, so maybe this one is WAI and I should avoid returning nothing from temple blocks.

    defp unread_message_counter(assigns) do
      temple do
        if @count > 0 do
          span class: "flex items-center justify-center
                       bg-blue-500 rounded-full font-medium h-5 px-2ml-auto
                       text-xs text-white"
          do
            @count
          end
+++     else
+++       span
        end
      end
    end
@evnp
Copy link

evnp commented Feb 21, 2025

Thanks for opening – just to add a bit more context (which I should have thought to try in the first place), it looks like returning any string directly from a temple block triggers the issue:

          end
+++     else
+++       "TEST"
        end
Image

Wrapping the string in any Temple/HTML tag resolves the issue.

Verified the above works ok (without wrapping tag) on Temple v0.14.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants