Repository navigation
Bind the popup's presets without waiting a tick - #14
Merged
Merged
Conversation
Fivell
force-pushed
the
fix/bind-popup-synchronously
branch
2 times, most recently
from
October 1, 2026 09:27
172fb59 to
11c124e
Compare
Fivell
force-pushed
the
fix/bind-popup-synchronously
branch
2 times, most recently
from
October 1, 2026 10:01
122fe83 to
837abea
Compare
There was a problem hiding this comment.
Copilot review overview
🟢 Approval recommended
The focused implementation correctly removes deferred binding and includes regression coverage for both affected interactions.
Review effort: Balanced
Findings: None
What changed in this PR
Binds popup handlers synchronously, preventing inert or duplicate-bound preset popups across jQuery versions.
Changes:
- Appends the popup and immediately registers its handlers.
- Adds regression tests for same-tick preset selection and dismissal.
| File | Description |
|---|---|
vendor/assets/javascripts/active_admin_date_range_preset.js |
Replaces deferred .ready() binding with immediate binding. |
spec/popup_binding_spec.rb |
Tests synchronous popup interactions. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
Fivell
force-pushed
the
fix/bind-popup-synchronously
branch
from
October 1, 2026 10:26
837abea to
53765de
Compare
The preset handlers and the dismissal listener are attached inside
`$('body').append(...).ready(fn)`. jQuery 3 rebuilt .ready() on a Deferred,
whose .then schedules through setTimeout, so on a non-document collection
the callback lands a macrotask late and the popup is on screen but unbound
until then.
Both examples drive their clicks from a single execute_script, so they land
in the same tick: one clicks a preset, the other clicks outside to dismiss.
The preset click hits an unbound popup and the input stays empty; the
dismissal click does nothing and the popup stays up.
This commit is expected to fail CI.
Nothing here waits for anything, so bind straight away instead of deferring through .ready(). Keep the node returned by appendTo rather than re-querying `.block_timerange` by class, which only ever found the right popup because unbindClickEventBlockTimerange removes every other one first. jQuery 4 keeps the same .ready() implementation, so it is not a version cliff -- just a macrotask nobody needs. (An earlier draft of this commit claimed jQuery 4 removed the method; jQuery.fn.ready is present in 4.0.0 with a byte-identical body.)
Fivell
force-pushed
the
fix/bind-popup-synchronously
branch
from
October 1, 2026 10:34
837abea to
671850c
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Found while writing the first test suite (#9). Branched off that PR, because the specs need its harness.
This is the twin of the bug #9 fixes, eight lines into the hot path.
The bug
On jQuery 1 and 2
.ready()on an already-ready document ran synchronously via.done(). jQuery 3 rebuilt it on a Deferred (jQuery.fn.ready = function (fn) { readyList.then(fn) }), andDeferred.thenschedules throughwindow.setTimeout. So:.ready()on a non-document collection is deprecated in jQuery 3 and removed in jQuery 4 — there the popup would never bind at all, which is exactly the failure mode Add a dummy app, specs and CI; fix form auto-init on jQuery 3 #9 exists to fix.The fix
Nothing here waits for anything:
appendis synchronous and the nodes exist on the next line. Bind straight away.The spec
Clicks "Set range" and a preset inside a single
execute_script, so both land in the same tick. On the parent commit the preset click hits an unbound popup and the input stays empty.