-
Notifications
You must be signed in to change notification settings - Fork 90
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
Warn if no <body> present #140
Comments
Proposal: |
Please do submit a PR! |
Ok, I got bitten by this, so I tried implementing a PR, but it is more subtle that I anticipated. In The problem, is, I think, that when live view kicks in, it re-renders everything, including the app layout, this re-render removes the injected live reload tags. That is why the body tag needs to be in the root layout which is untouched by the live view. So to warn the user, we have to get the root layout in It is not hard to implement, but it adds a file read on each request. Something like: layout = Phoenix.Controller.root_layout(conn)
if not layout_contains_body_tag?(layout) do
IO.warn(
"Your root template does not contain a <body> tag. " <>
"The <body> tag is required for the live reload plug to work"
)
end and The other approach would be to inject some JS in the Last but not least, add a comment in the Let me know what you think. |
Thanks for looking into this, @kuon ! Are you saying that
That's a good stopgap IMHO. |
Yes I also think the comment is enough. |
We can't guarantee that the user has a root layout, or a root layout file, so that unfortunately is not going to work. |
We could just add a comment in the generated # Note: The browser reloading code will not work if the
# <body> tag is rendered with live view. In typical situation
# it means to keep the <body> inside your root layout.
config :book, BookWeb.Endpoint,
live_reload: [
patterns: [
~r"priv/static/.*(js|css|png|jpeg|jpg|gif|svg)$",
~r"priv/gettext/.*(po)$",
~r"lib/book_web/.*/.*(ex)$"
]
] Another idea would be to add an attribute that live view would understand, similar to `phx-update="ignore"`` but stronger, it would tell live view to keep the tag even if the parent is removed, then the generated tag from this library would include it and be protected. But I don't know how feasible and desired this would be. |
A LV wrapping the entire body is a pretty large edgecase that I'm not overly worried about. A better way to handle this would be to open a public function on the LV side (like making the current private |
As noted by @ellismarkf in #134 (comment) , this library requires
<body>
to be present inroot.html.heex
for the browser to refresh following a detected code change and subsequent reload.It would be useful to warn if
<body>
is not present due to e.g. developer shenangians with the template structure.The text was updated successfully, but these errors were encountered: