Add versioning to scanner bundle URL for frontend scans#1682
Add versioning to scanner bundle URL for frontend scans#1682pattonwebz wants to merge 3 commits intodevelopfrom
Conversation
Updated the scannerBundleUrl to include the version parameter for better cache management.
📝 WalkthroughWalkthroughThe frontend highlighter's localized script payload now sets ChangesCache-Busting Versioning for Frontend Scanner
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related PRs
Suggested labels
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 thescannerBundleUrlvalue 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, |
There was a problem hiding this comment.
@copilot apply changes based on this feedback
There was a problem hiding this comment.
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.
…ring Agent-Logs-Url: https://github.com/equalizedigital/accessibility-checker/sessions/44a9a616-a57e-4349-b3f3-7d5656203ba8 Co-authored-by: pattonwebz <3902039+pattonwebz@users.noreply.github.com>
There was a problem hiding this comment.
🧹 Nitpick comments (1)
tests/phpunit/includes/classes/EnqueueFrontendTest.php (1)
72-73: ⚡ Quick winTighten the assertion so
veris validated onscannerBundleUrlspecifically.The current checks are independent, so this can pass even if
ver=is present on a different localized field. Use one assertion that bindsvertoscannerBundleUrl.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
📒 Files selected for processing (1)
tests/phpunit/includes/classes/EnqueueFrontendTest.php
Updated the scannerBundleUrl to include the version parameter for better cache management.
Checklist
Summary by CodeRabbit