Skip to content

Add versioning to scanner bundle URL for frontend scans#1682

Open
pattonwebz wants to merge 3 commits intodevelopfrom
william/no-issue/add-cache-busting-param-to-bundle-output-on-frontend-scanner
Open

Add versioning to scanner bundle URL for frontend scans#1682
pattonwebz wants to merge 3 commits intodevelopfrom
william/no-issue/add-cache-busting-param-to-bundle-output-on-frontend-scanner

Conversation

@pattonwebz
Copy link
Copy Markdown
Member

@pattonwebz pattonwebz commented May 5, 2026

Updated the scannerBundleUrl to include the version parameter for better cache management.

Checklist

  • PR is linked to the main issue in the repo
  • Tests are added that cover changes

Summary by CodeRabbit

  • Chores
    • Frontend scanner script URL now includes a cache‑busting version query parameter so browsers fetch updated scanner assets reliably.
  • Tests
    • Added a unit test to verify the localized frontend data includes the scanner URL with the version query parameter.

Updated the scannerBundleUrl to include the version parameter for better cache management.
Copilot AI review requested due to automatic review settings May 5, 2026 18:00
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 5, 2026

📝 Walkthrough

Walkthrough

The frontend highlighter's localized script payload now sets scannerBundleUrl to a versioned URL using add_query_arg('ver', EDAC_VERSION, ...) wrapped with esc_url_raw(), replacing the previous unversioned bundle URL.

Changes

Cache-Busting Versioning for Frontend Scanner

Layer / File(s) Summary
Localization payload
includes/classes/class-enqueue-frontend.php
scannerBundleUrl value in the wp_localize_script() payload was changed to include a ver query parameter.
URL construction / sanitization
includes/classes/class-enqueue-frontend.php
Replaced plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/pageScanner.bundle.js' with esc_url_raw( add_query_arg( 'ver', EDAC_VERSION, plugin_dir_url( __FILE__ ) . 'build/pageScanner.bundle.js' ) ).
Tests
tests/phpunit/includes/classes/EnqueueFrontendTest.php
Added testScannerBundleUrlIncludesVersionQueryString() to assert scannerBundleUrl exists and contains ver=<EDAC_VERSION>.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related PRs

Suggested labels

codex

Suggested reviewers

  • SteveJonesDev

Poem

🐰 A little hop, a versioned cheer,

The bundle’s tagged, the path is clear,
Caches bow out, fresh bytes unfurl,
A rabbit cheers for a tidier world.

🚥 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 accurately and concisely describes the main change: adding a version query parameter to the scanner bundle URL for cache-busting purposes.
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.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ 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 william/no-issue/add-cache-busting-param-to-bundle-output-on-frontend-scanner

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

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist Bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request updates the scannerBundleUrl in includes/classes/class-enqueue-frontend.php to include a version query parameter for cache busting. The review feedback recommends using add_query_arg() and esc_url_raw() to ensure the URL is properly encoded and sanitized according to WordPress best practices.

Comment thread includes/classes/class-enqueue-frontend.php Outdated
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR improves cache management for frontend scans by appending the plugin version to the dynamically loaded scanner bundle URL used by the frontend highlighter, helping ensure updated scanner code is fetched after plugin updates.

Changes:

  • Add ?ver={EDAC_VERSION} to the scannerBundleUrl value passed to the frontend highlighter app for dynamic script injection.

'widgetPosition' => get_option( 'edac_frontend_highlighter_position', 'right' ),
'editorLink' => get_edit_post_link( $post_id ),
'scannerBundleUrl' => plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/pageScanner.bundle.js',
'scannerBundleUrl' => plugin_dir_url( EDAC_PLUGIN_FILE ) . 'build/pageScanner.bundle.js?ver=' . EDAC_VERSION,
Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

@copilot apply changes based on this feedback

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.

Added testScannerBundleUrlIncludesVersionQueryString to EnqueueFrontendTest in commit 144bd77. It enqueues the frontend highlighter as an admin, then asserts the localized edacFrontendHighlighterApp data contains both scannerBundleUrl and ver=EDAC_VERSION.

Comment thread includes/classes/class-enqueue-frontend.php Outdated
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
tests/phpunit/includes/classes/EnqueueFrontendTest.php (1)

72-73: ⚡ Quick win

Tighten the assertion so ver is validated on scannerBundleUrl specifically.

The current checks are independent, so this can pass even if ver= is present on a different localized field. Use one assertion that binds ver to scannerBundleUrl.

Proposed change
-		$this->assertStringContainsString( 'scannerBundleUrl', $localized_data );
-		$this->assertStringContainsString( 'ver=' . EDAC_VERSION, $localized_data );
+		$pattern = '/scannerBundleUrl[\'"]?\s*:\s*[\'"][^\'"]*[?&]ver=' . preg_quote( EDAC_VERSION, '/' ) . '(?:[\'"&]|$)/';
+		$this->assertMatchesRegularExpression( $pattern, $localized_data );
🤖 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/phpunit/includes/classes/EnqueueFrontendTest.php` around lines 72 - 73,
Replace the two independent assertions with a single assertion that verifies the
"ver=" parameter appears specifically inside the scannerBundleUrl field in
$localized_data; in EnqueueFrontendTest, build a check (e.g. a regex or exact
substring match) that targets the scannerBundleUrl entry and asserts it contains
"ver=" . EDAC_VERSION so the version is validated on scannerBundleUrl rather
than elsewhere in $localized_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/phpunit/includes/classes/EnqueueFrontendTest.php`:
- Around line 72-73: Replace the two independent assertions with a single
assertion that verifies the "ver=" parameter appears specifically inside the
scannerBundleUrl field in $localized_data; in EnqueueFrontendTest, build a check
(e.g. a regex or exact substring match) that targets the scannerBundleUrl entry
and asserts it contains "ver=" . EDAC_VERSION so the version is validated on
scannerBundleUrl rather than elsewhere in $localized_data.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: f4a1f031-da48-4a50-b301-3982cd4db88e

📥 Commits

Reviewing files that changed from the base of the PR and between 00dd795 and 144bd77.

📒 Files selected for processing (1)
  • tests/phpunit/includes/classes/EnqueueFrontendTest.php

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.

4 participants