Skip to content

Commit 61549ce

Browse files
committed
defer
1 parent 0ac9471 commit 61549ce

3 files changed

Lines changed: 9 additions & 12 deletions

File tree

app/controllers/primer/view_components/action_menu_controller.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ class ActionMenuController < ApplicationController
1010
def landing; end
1111

1212
def deferred
13+
sleep params[:delay].to_f if params[:delay].present?
1314
render "primer/view_components/action_menu/deferred"
1415
end
1516

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1-
<%# The invoker is pinned to the bottom of the viewport so the overlay has no room to grow %>
2-
<%# downward once its deferred content loads, reproducing the scenario from DREAM-729. %>
1+
<%# The invoker is pinned near the bottom of the viewport, leaving enough room for the loading %>
2+
<%# spinner placeholder to fit below it but not enough for the full deferred content, reproducing %>
3+
<%# the scenario from DREAM-729. The `delay` param forces the fragment response to arrive after the %>
4+
<%# overlay has already been positioned using the placeholder's size, instead of racing the fetch %>
5+
<%# against the initial position calculation. %>
36
<div style="position: fixed; bottom: 100px; right: 0;">
4-
<%= render(Primer::Alpha::ActionMenu.new(menu_id: "deferred-bottom", src: primer_view_components.action_menu_deferred_path)) do |menu| %>
7+
<%= render(Primer::Alpha::ActionMenu.new(menu_id: "deferred-bottom", src: primer_view_components.action_menu_deferred_path(delay: 0.3))) do |menu| %>
58
<% menu.with_show_button { "Menu with deferred content" } %>
69
<% end %>
710
</div>

test/system/alpha/action_menu_test.rb

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -897,15 +897,8 @@ def test_deferred_loading_overlay_positioned_within_viewport
897897
# Wait for lazy content to load
898898
assert_selector "action-menu ul li", text: "Copy link"
899899

900-
overlay_in_viewport = page.evaluate_script(<<~JS)
901-
(function() {
902-
var el = document.querySelector('anchored-position')
903-
var rect = el.getBoundingClientRect()
904-
return rect.bottom <= (window.innerHeight || document.documentElement.clientHeight)
905-
})()
906-
JS
907-
908-
assert overlay_in_viewport, "Overlay should be positioned within the viewport after deferred content loads"
900+
overlay = find("anchored-position").native.node
901+
assert overlay.in_viewport?, "Overlay should be positioned within the viewport after deferred content loads"
909902
end
910903

911904
def test_deferred_dialog_opens

0 commit comments

Comments
 (0)