Skip to content

:container option used by Phoenix.LiveView behaves unexpectly when tag is set to body #3932

@Eiji7

Description

@Eiji7

Environment

  • Elixir version (elixir -v):
    N/A
  • Phoenix version (mix deps):
    Latest (release candidate):
* phoenix 1.8.0-rc.4 (Hex package) (mix)
  locked at 1.8.0-rc.4 (phoenix) 754c8caf
  ok
  • Phoenix LiveView version (mix deps):
    Latest (stable):
* phoenix_live_view 1.1.2 (Hex package) (mix)
  locked at 1.1.2 (phoenix_live_view) 54b2e4a3
  ok
  • Operating system:
    N/A
  • Browsers you attempted to reproduce this bug on (the more the merrier):
    Chromium and Firefox
  • Does the problem persist after removing "assets/node_modules" and trying again? Yes/no:
    No, the directory does not exists

Actual behavior

With below code:

use Phoenix.LiveView, container: {:body, id: "example"}

there are 2 bugs:

  1. The empty head is added as a first child of a body wrapper and the contents are wrapped in then 2nd body element that does not have any attributes.
  2. The id is not set

Note: I have reproduced it also in new example app (mix phx.new example). Nothing "fancy" was added except that simplest live page, removing body from root.html.heex layout and of course adding container option.

Image

The simplest example with mix phx.gen.live Accounts User users --no-context name:string just to quickly get a live page. Made on Firefox (to be precise zen browser that is Firefox fork).

Image The same page on `Chromium` just to be sure that it's not browser/web engine related bug.

In both cases in DevTools you can see a huge body tag (with a lot of attributes) that contain empty head and another body (without attributes) as described above.

Expected behavior

Setting :body as tag and id attribute are documented in Containers section | Phoenix.Component.

use Phoenix.LiveView, container: {:tr, id: "foo-bar"}

and

Beware if you set this to :body, as any content injected inside the body (such as Phoenix.LiveReload features) will be discarded once the LiveView connects

So except Phoenix.LiveReload known issue it's supposed to be fully supported, but none of those works properly. For sure other tags and their attributes (like class for example) works without a problem. I would simply like to have a semantically valid HTML5 document (with header, main, footer and other HTML5 elements) without a weird div wrapper. id is not so important as I simply can use body in CSS.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions