Skip to content

Add Query Monitor 4.0 support#357

Open
JanJakes wants to merge 7 commits intotrunkfrom
query-monitor-4-support
Open

Add Query Monitor 4.0 support#357
JanJakes wants to merge 7 commits intotrunkfrom
query-monitor-4-support

Conversation

@JanJakes
Copy link
Copy Markdown
Member

@JanJakes JanJakes commented Apr 8, 2026

Summary

Query Monitor 4.0 switched from server-side PHP rendering to client-side Preact rendering inside a shadow DOM. This broke the existing SQLite query display integration, which overrides output_query_row() — a method that QM 4.0 no longer calls.

This PR adds QM 4.0 support while maintaining backward compatibility with QM 3.x:

  • Version detection in boot.php using QM_VERSION to choose between QM 3.x and 4.0+ integration paths.
  • Custom QM collector (collector.php) that extracts SQLite queries from $wpdb->queries and outputs them as JSON via a server-side outputter.
  • Shadow DOM injection JS (query-monitor-sqlite.js) that polls for QM's shadow root and injects toggle buttons into the DB queries panel using a debounced MutationObserver.
  • E2E tests for both QM 3.x and 4.0+, each auto-skipping when the other version is detected.

Fixes the CI failure introduced by QM 4.0 release.

Test Plan

  • E2E test passes with QM 4.0+ (latest): toggle buttons appear in shadow DOM, SQLite queries display correctly
  • E2E test passes with QM 3.x (3.16.4): existing server-side integration works unchanged
  • PHPCS passes clean
  • CI end-to-end tests pass

JanJakes added 7 commits April 8, 2026 11:26
Detect QM 4.0+ via QM_Output_Html_DB_Queries::$client_side_rendered
and load the collector-based integration. Fall back to the existing
HTML override for QM 3.x.
Register a custom QM collector that extracts SQLite queries from
$wpdb->queries and a server-side outputter that will render JSON
data and JS for the QM 4.0 shadow DOM integration.
Inject toggle buttons into QM 4.0's Preact-rendered DB queries panel
inside the shadow DOM. Uses MutationObserver to handle panel switches
and re-renders.
Add separate test cases for QM 3.x (server-side HTML) and QM 4.0+
(Preact shadow DOM). Each test auto-skips when the other QM version
is detected.
Use QM_VERSION constant for version detection instead of checking
QM_Output_Html_DB_Queries::$client_side_rendered which isn't loaded
at plugins_loaded time.

Poll for shadow root instead of using MutationObserver, since
attachShadow() doesn't trigger childList mutations. QM's module
script is deferred, so its DOMContentLoaded handler fires after
our inline script's handler.

Fix e2e test to use button[role=tab] for QM 4.0 nav items.
- Escape JSON output with JSON_HEX_TAG to prevent XSS via </script>
  in query text.
- Add timeout to shadow root polling (max 10 seconds).
- Debounce MutationObserver to reduce overhead during re-renders.
- Add missing await on toBeVisible() in QM 3.x test.
- Add toPass() retry for SQLite toggle check in QM 4.0 test.
- Document QM source reference for admin bar query filtering.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant