bugfix/5155-roots-panel-openmenu-undefined#5291
Conversation
Signed-off-by: NAYANA.R <nayana.r7813@gmail.com>
|
@Nayana-R-Gowda Please add tests |
Signed-off-by: NAYANA.R <nayana.r7813@gmail.com>
Signed-off-by: NAYANA.R <nayana.r7813@gmail.com>
marekdano
left a comment
There was a problem hiding this comment.
The user-facing bug is correctly fixed!
LGTM 🚀
vishu-bh
left a comment
There was a problem hiding this comment.
Thanks @Nayana-R-Gowda!
changes are clean.
LGTM ☘️
msureshkumar88
left a comment
There was a problem hiding this comment.
Verified this fixes #5155 end-to-end in a real browser (Chromium via Playwright, against a live admin server).
Repro (pre-fix code, x-data="window.Admin?.overflowMenu?.('roots-table-wrapper')"): created a root, clicked the row's overflow-menu button → reproduced the exact reported error:
Error: Undefined variable: openMenu
With this PR's fix (x-data="overflowMenu('roots-table-wrapper')"): same click → no console errors, dropdown opens correctly (menuOpen toggles as expected).
Root cause write-up is accurate — overflowMenu is registered via Alpine.data('overflowMenu', overflowMenu), not attached to window.Admin, so the old optional-chaining expression always evaluated to undefined and Alpine initialized the component with an empty scope.
Diff is minimal and well-scoped: template one-liner, a doc-comment clarifying the correct usage pattern, and solid regression coverage in overflow-menu.test.js (including a test that reproduces the broken expression directly). Nothing to flag on correctness or cleanup.
Signed-off-by: NAYANA.R nayana.r7813@gmail.com
closes #5155
What Changed
Root cause: Alpine evaluates the x-data expression as JavaScript. With optional chaining (?.), when window.Admin or window.Admin.overflowMenu resolves to undefined at init time, Alpine initializes the component with an empty scope — menuOpen and openMenu are never defined. Clicking the button then tries to call openMenu() which doesn't exist → "Undefined variable: openMenu".