Skip to content

fix: guard wubox clicks before scripts load#1596

Merged
superdav42 merged 1 commit into
mainfrom
fix/modal-trigger-ready
Jun 30, 2026
Merged

fix: guard wubox clicks before scripts load#1596
superdav42 merged 1 commit into
mainfrom
fix/modal-trigger-ready

Conversation

@superdav42

@superdav42 superdav42 commented Jun 30, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Print an idempotent .wubox early-click guard in admin_head when wubox is enqueued so modal form links cannot navigate to raw AJAX URLs before footer scripts load.
  • Reuse the same guard for the footer inline script and preserve previously queued clicks.
  • Add Scripts_Test coverage for the new hook and guard contents.

Verification

  • vendor/bin/phpcs inc/class-scripts.php tests/WP_Ultimo/Scripts_Test.php
  • vendor/bin/phpunit --filter Scripts_Test
  • Browser repro with a .wubox Add Domain AJAX href: without guard the click navigated to admin-ajax.php?action=wu_form_display&form=add_new_domain; with guard the URL stayed put and one click was queued.

Notes

  • The fix applies to all modal/form triggers using the shared .wubox class, not only the domains page.

aidevops.sh v3.31.0 plugin for OpenCode v1.17.12 with gpt-5.5 spent 1h 30m and 469,237 tokens on this with the user in an interactive session.

Summary by CodeRabbit

  • Bug Fixes

    • Improved responsiveness when clicking “wubox” elements by capturing clicks earlier, helping prevent missed or delayed interactions on relevant admin pages.
    • Reduced duplicate click handling, making the behavior more reliable and consistent.
  • Refactor

    • Updated how the click-handling logic is assembled internally to keep the behavior centralized and easier to maintain.

@coderabbitai

coderabbitai Bot commented Jun 30, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

📝 Walkthrough

Walkthrough

Introduces an early wubox click guard script in the Scripts class, centralizing its JavaScript generation into a helper method and printing it via an admin_head hook on WP Ultimo pages. Adds corresponding unit tests validating the generated script content and its attachment to the registered wubox script.

Changes

Wubox Early Click Guard

Layer / File(s) Summary
Guard script generation and output
inc/class-scripts.php
Adds print_wubox_early_click_guard() and get_wubox_early_click_guard_script() methods, registers an admin_head hook (priority 1) to print the guard on WP Ultimo pages when wubox is enqueued, and replaces the inline JS literal in register_default_scripts() with the new helper output.
Guard script tests
tests/WP_Ultimo/Scripts_Test.php
Adds tests verifying the generated guard JS contains expected idempotency/queueing logic and confirming the script is attached as the "before" payload for the wubox handle after registration.

Sequence Diagram(s)

sequenceDiagram
  participant WordPress
  participant Scripts
  participant DocumentHead

  WordPress->>Scripts: init()
  Scripts->>Scripts: register_default_scripts()
  Scripts->>Scripts: get_wubox_early_click_guard_script()
  Scripts->>Scripts: wp_add_inline_script(wubox, guard script)
  WordPress->>Scripts: admin_head action (priority 1)
  Scripts->>Scripts: print_wubox_early_click_guard()
  Scripts->>DocumentHead: output <script> tag with guard JS
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Poem

A click too soon? No need to fret,
This bunny built a guard, you bet!
Queue it up, don't lose a trace,
Catch it early, hold its place. 🐇
Hop along, the wubox's safe,
Tested twice to seal the case.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main fix: guarding wubox clicks before scripts load.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/modal-trigger-ready

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

Copy link
Copy Markdown

🔨 Build Complete - Ready for Testing!

📦 Download Build Artifact (Recommended)

Download the zip build, upload to WordPress and test:

🌐 Test in WordPress Playground (Very Experimental)

Click the link below to instantly test this PR in your browser - no installation needed!
Playground support for multisite is very limitied, hopefully it will get better in the future.

🚀 Launch in Playground

Login credentials: admin / password

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🧹 Nitpick comments (1)
tests/WP_Ultimo/Scripts_Test.php (1)

279-291: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Add coverage for the actual head output path.

This checks the footer before payload, but not print_wubox_early_click_guard()’s page/enqueue gate or emitted <script id="wu-wubox-early-click-guard">.

Suggested test coverage
+	public function test_print_wubox_early_click_guard_outputs_script_when_wubox_enqueued(): void {
+
+		$force_wu_page = static fn() => true;
+		add_filter('wu_is_wu_page', $force_wu_page);
+
+		$this->scripts->register_default_scripts();
+		wp_enqueue_script('wubox');
+
+		ob_start();
+		$this->scripts->print_wubox_early_click_guard();
+		$output = ob_get_clean();
+
+		remove_filter('wu_is_wu_page', $force_wu_page);
+		wp_dequeue_script('wubox');
+
+		$this->assertStringContainsString('id="wu-wubox-early-click-guard"', $output);
+		$this->assertStringContainsString('window.__wuboxEarlyClicks=window.__wuboxEarlyClicks||[];', $output);
+	}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@tests/WP_Ultimo/Scripts_Test.php` around lines 279 - 291, The current test
only inspects the stored wp_scripts data for wubox and misses the real head
output path from print_wubox_early_click_guard(). Add coverage that exercises
the page/enqueue gate in Scripts_Test by triggering the conditions that cause
the guard to render, then assert the emitted <script
id="wu-wubox-early-click-guard"> appears in the actual output. Keep the existing
register_default_scripts check for the footer payload, but add a separate test
that verifies the early click guard is printed through
print_wubox_early_click_guard() rather than only reading
wp_scripts()->get_data().
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@tests/WP_Ultimo/Scripts_Test.php`:
- Around line 279-291: The current test only inspects the stored wp_scripts data
for wubox and misses the real head output path from
print_wubox_early_click_guard(). Add coverage that exercises the page/enqueue
gate in Scripts_Test by triggering the conditions that cause the guard to
render, then assert the emitted <script id="wu-wubox-early-click-guard"> appears
in the actual output. Keep the existing register_default_scripts check for the
footer payload, but add a separate test that verifies the early click guard is
printed through print_wubox_early_click_guard() rather than only reading
wp_scripts()->get_data().

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e68f6652-57f5-4275-89ca-556177bf62b8

📥 Commits

Reviewing files that changed from the base of the PR and between 3e79498 and f4cf2b3.

📒 Files selected for processing (2)
  • inc/class-scripts.php
  • tests/WP_Ultimo/Scripts_Test.php

@superdav42 superdav42 merged commit e213830 into main Jun 30, 2026
11 checks passed
@superdav42

Copy link
Copy Markdown
Collaborator Author

Summary

  • Print an idempotent .wubox early-click guard in admin_head when wubox is enqueued so modal form links cannot navigate to raw AJAX URLs before footer scripts load.
  • Reuse the same guard for the footer inline script and preserve previously queued clicks.
  • Add Scripts_Test coverage for the new hook and guard contents.

Verification

  • vendor/bin/phpcs inc/class-scripts.php tests/WP_Ultimo/Scripts_Test.php
  • vendor/bin/phpunit --filter Scripts_Test
  • Browser repro with a .wubox Add Domain AJAX href: without guard the click navigated to admin-ajax.php?action=wu_form_display&form=add_new_domain; with guard the URL stayed put and one click was queued.

Notes

  • The fix applies to all modal/form triggers using the shared .wubox class, not only the domains page.

aidevops.sh v3.31.0 plugin for OpenCode v1.17.12 with gpt-5.5 spent 1h 30m and 469,237 tokens on this with the user in an interactive session.


Merged via PR #1596 to main.
Merged by deterministic merge pass (pulse-wrapper.sh).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

review-feedback-scanned Merged PR already scanned for quality feedback

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant