phx-viewport-bottom doesn't get triggered if there's a hidden element
Maintainers usually reply within 1 day
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 48/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Stale
- Tech stack
- elixir, javascript
Research direction
The reported behavior is in assets/js/phoenix_live_view/hooks.js, specifically the InfiniteScroll hook and its use of this.el.lastElement. Reproduce it with the linked liveview-infinitescroll project at /, then verify that phx-viewport-bottom fires with the hidden empty-state element present and when content is shorter than the container.
Written by the indexing model from the issue text.
Description
Environment
- Elixir version (elixir -v): 1.17.2
- Phoenix version (mix deps): 1.7.18
- Phoenix LiveView version (mix deps): 1.0.2
- Operating system: macOS Sequoia 15.2
- Browsers you attempted to reproduce this bug on (the more the merrier): Arc
- Does the problem persist after removing "assets/node_modules" and trying again? Yes/no: Yes
Actual behavior
phx-viewport-bottom does not work if there's a hidden element (for example to show no results)
If you create an infinite scroll list with streams, set phx-bottom-viewport and add a hidden div (for example, to show no results as shown in the examples: Handling the empty case), the event doesn't get triggered when the last element reaches the bottom.
Reaching the end of the list won't trigger "next":
def render(assigns) do
~H"""
<div class="flex flex-col h-full w-full justify-center items-center">
<div
id="test"
phx-update="stream"
phx-viewport-bottom="next"
phx-viewport-top="prev"
class="w-[300px] h-[300px] max-h-[300px] overflow-y-auto bg-white border border-outline"
>
<div class="hidden empty:block" id="emtpy-container">
<p>No results</p>
</div>
<div :for={{id, option} <- @streams.options} id={id}>
<p>{option.name}</p>
</div>
</div>
</div>
"""
end
Project with reproducible bug -> Navigate to "/" to see the example. The bug disappears when commenting the hidden div.
Expected behavior
When the user reaches the end of the list, phx-viewport-bottom get's triggered
Notes
I looked at LiveView's InfiniteScroll Hook and this.el.lastElement is being set to the hidden div, but it's boundingRect is
{
"x": 0,
"y": 0,
"width": 0,
"height": 0,
"top": 0,
"right": 0,
"bottom": 0,
"left": 0
}
and so isAtViewportBottom never returns true.
A possible fix would be to find the last element whose computed style for display is not none.
As a side note, I also think that phx-viewport-bottom should be triggered if the height of the items is less than the height of the container because some times in infinite lists, the container is bigger than the initially loaded items.
For example, let's say the container holds 50 items and you only load 30 out of 60. Since the last element will never reach the end of the container, the last 30 items are never loaded and the user has no way of loading them. I think it would make sense, in this case, to call viewport-bottom to immediately load the next 30, and keep doing it until either there are no more elements or the elements overflow the container.
- Dominant language
- Elixir
- Stars
- 6.8k
- Forks
- 1.1k
- Avg merge
- 1d 3h
- Merged PRs (30d)
- 19
Getting set up
This project ships no dev container, Dockerfile or contributing guide, so setting up is up to you: start from its README, and see our first-contribution guide for the general steps.
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from phoenixframework/phoenix_live_view
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
phoenixframework/phoenix_live_view#4509 ·
Maintainers usually reply within 1 day
-
awaiting feedback needs more info
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
phoenixframework/phoenix_live_view#4407 · 2 comments ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
phoenixframework/phoenix_live_view#4507 ·
Maintainers usually reply within 1 day
-
Difficulty 4/5 3-5 days Newbie friendliness 48/100
phoenixframework/phoenix_live_view#4506 ·
Maintainers usually reply within 1 day
-
Focused input with `phx-patch-focused` loses typed chars when a `phx-change` reply lands mid-typingOpen
Difficulty 4/5 3-5 days Newbie friendliness 65/100
phoenixframework/phoenix_live_view#4504 ·
Maintainers usually reply within 1 day
All issues in phoenixframework/phoenix_live_view
Similar issues
-
Bug: Table layout and date column are cut off on mobile screens on the Tournaments -> History pageOpenbug
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
hexlet-codebattle/codebattle#2375 ·
-
Bug
Difficulty 2/5 1-3 hours Newbie friendliness 68/100
wintermeyer/vutuv#2388 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
-
Broadcast API docs say to prepend realtime: to the topic, which breaks deliveryPossibly taken @mandar1045 claimed this 1 day ago. Open
Difficulty 1/5 Under an hour Newbie friendliness 80/100
Maintainers usually reply within 1 day
-
camelToSnake and snakeCamelMapper() drop the underscore when a digit precedes a camelCase boundaryOpen
Difficulty 2/5 1-3 hours Newbie friendliness 85/100
electric-sql/electric#4855 ·