-
Notifications
You must be signed in to change notification settings - Fork 19
Use a rest api url that works on subsites as well as if someone changes the rest api base #1737
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 5 commits
0492b7e
03ecb65
e47899f
87c49d2
08d4a7e
ce8674d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -1863,7 +1863,7 @@ class AccessibilityCheckerHighlight { | |||||
|
|
||||||
| saveScanResults( postId, nonce, violations, densityMetrics ) { | ||||||
| const self = this; | ||||||
| return fetch( '/wp-json/accessibility-checker/v1/post-scan-results/' + postId, { | ||||||
| return fetch( `${ edacFrontendHighlighterApp.restUrl }/post-scan-results/${ postId }`, { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If const restUrl = window.edacFrontendHighlighterApp?.restUrl;
if ( ! restUrl ) {
return Promise.reject( new Error( 'Missing REST API URL.' ) );
}
return fetch( restUrl + '/post-scan-results/' + postId, {
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in ce8674d — added guard clause / switched to |
||||||
| method: 'POST', | ||||||
| headers: { | ||||||
| 'Content-Type': 'application/json', | ||||||
|
|
@@ -1943,7 +1943,7 @@ class AccessibilityCheckerHighlight { | |||||
| } | ||||||
|
|
||||||
| // Validate required parameters | ||||||
| if ( ! edacFrontendHighlighterApp?.edacUrl || ! edacFrontendHighlighterApp?.postID ) { | ||||||
| if ( ! edacFrontendHighlighterApp?.restUrl || ! edacFrontendHighlighterApp?.postID ) { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Accessing
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in ce8674d — added guard clause / switched to |
||||||
| const summary = document.querySelector( '.edac-highlight-panel-controls-summary' ); | ||||||
| if ( summary ) { | ||||||
| summary.textContent = __( 'Error: Missing required parameters.', 'accessibility-checker' ); | ||||||
|
|
@@ -1956,7 +1956,7 @@ class AccessibilityCheckerHighlight { | |||||
| this.clearIssuesButton.textContent = __( 'Clearing...', 'accessibility-checker' ); | ||||||
| const summary = document.querySelector( '.edac-highlight-panel-controls-summary' ); | ||||||
|
|
||||||
| fetch( `${ edacFrontendHighlighterApp.edacUrl }/wp-json/accessibility-checker/v1/clear-issues/${ edacFrontendHighlighterApp.postID }`, { | ||||||
| fetch( `${ edacFrontendHighlighterApp.restUrl }/clear-issues/${ edacFrontendHighlighterApp.postID }`, { | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For safety and consistency, access the localized variables via
Suggested change
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in ce8674d — added guard clause / switched to |
||||||
| method: 'POST', | ||||||
| headers: { | ||||||
| 'Content-Type': 'application/json', | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If
fixesRestUrlis undefined or null (for example, if the script is loaded in a context where the localized variables are missing), thefetchcall will attempt to request a relative URL starting withundefined/fixes/update/. Adding a guard clause to handle this scenario gracefully prevents broken network requests and improves robustness.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed in ce8674d — added guard clause / switched to
window.prefix throughout.