Skip to content

Clarifications about nested live views and their appropriate use#3713

Merged
SteffenDE merged 4 commits intophoenixframework:mainfrom
jdmarshall:docs
Mar 13, 2025
Merged

Clarifications about nested live views and their appropriate use#3713
SteffenDE merged 4 commits intophoenixframework:mainfrom
jdmarshall:docs

Conversation

@jdmarshall
Copy link
Copy Markdown
Contributor

@jdmarshall jdmarshall commented Mar 13, 2025

I had a problem with nested live view testing where the test helpers did not understand where to send the click events.

This was discussed in issue #3393 and a subsequent read of the code makes it clear to me that there is no obvious way to have the test infrastructure walk up the DOM or process tree looking for the correct child to send clicks to (if someone knows a way to fix that I would love to encourage you to look into it).

So barring that, and informed by a separate conversation in the forums, here are some bits of advice gleaned from those two conversations. I think if the core Phoenix crew believes that Nested LiveViews are something you should use very sparingly, then the docs should warn new users that they are flying into the proverbial terrain.

There are some old SO threads and ancient forum threads that the participants didn't know about attach_hook. I don't know if that's lack of experience or later additions to the API. I'm hoping some more links in the docs will help with those.

@SteffenDE SteffenDE merged commit 2f3fc95 into phoenixframework:main Mar 13, 2025
@SteffenDE
Copy link
Copy Markdown
Collaborator

Thank you! 🙌🏻

SteffenDE added a commit that referenced this pull request Mar 20, 2025
* Add hint about find_live_child/2 to the live_render docs.

* Add a recommendation to try LiveComponent before resorting to a liveview.

* Apply suggestions from code review

* Update lib/phoenix_component.ex

---------

Co-authored-by: Steffen Deusch <steffen@deusch.me>
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

Successfully merging this pull request may close these issues.

2 participants