phoenixframework / phoenix_live_view

Rich, real-time user experiences with server-rendered HTML
https://hex.pm/packages/phoenix_live_view
MIT License
6.18k stars 931 forks source link

phx-no-feedback class not applied when page is live-patched #1282

Closed iwarshak closed 3 years ago

iwarshak commented 3 years ago

Environment

Actual behavior

When navigating to a form (via live_patch) which has an input with phx_feedback_for: input_id(f, :name), the phx-no-feedback is not applied.

But if you refresh this page, or do a normal link to it (or manually navigate to the page), the phx-no-feedback IS applied.

This leads to unpredictable behavior if you are applying styles to these form elements.

I have a repo which you can use to see this quickly. https://github.com/iwarshak/phx-no-feedback-bug

1) visit http://localhost:3999/users 2) click the 'New User' link, and notice that the name field doesn't have the phx-no-feedback class 3) refresh this page and see that now it does have the phx-no-feedback class

mveytsman commented 3 years ago

@iwarshak thanks for the report! I can confirm that this is an issue -- I think it has to do with how the discardError method is called during morphdom patching - when patching it seems to only be called on the modal and not it's children while in a full mount it is called on every child.

I think this has something to do with it's use in onBeforeNodeAdded and onBeforeElUpdated, and the way morphdom traverses the tree...

iwarshak commented 3 years ago

@mveytsman Yes, I tracked it down to it: onBeforeNodeAdded gets called for the outer div containing the input, but it doesn't recurse into the contents of that div - which is I think similar to what you are saying

chrismccord commented 3 years ago

@mcrumm remind me, did we dig into this and fix this already or something related but different?

chrismccord commented 3 years ago

Derp, I see we reference this as closed. All fixed! ❤️❤️❤️🐥🔥