Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fixed validator not loading
  • Loading branch information
mszylkowski committed Oct 18, 2021
commit ec34422de1575a2d8c6f2c9ac805ac5423a23375
36 changes: 24 additions & 12 deletions extensions/amp-story-dev-tools/0.1/amp-story-dev-tools-tab-debug.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ export class AmpStoryDevToolsTabDebug extends AMP.BaseElement {
/** @private {string} */
this.storyUrl_ = '';

/** @private {!Array} */
this.errorList_ = [];
/** @private {?Array} */
this.errorList_ = null;
}

/** @override */
Expand All @@ -96,19 +96,34 @@ export class AmpStoryDevToolsTabDebug extends AMP.BaseElement {
buildCallback() {
this.storyUrl_ = this.element.getAttribute('data-story-url');
this.element.classList.add('i-amphtml-story-dev-tools-tab');
return this.tryValidatingDocument_();
}

/** @override */
layoutCallback() {
return this.tryValidatingDocument_().finally(() =>
this.buildDebugContent_()
);
}

/**
* Attempts to load the validator, fetch the document and run the validator.
* Can reject due to network conditions or validator initialization.
* @return {!Promise}
*/
tryValidatingDocument_() {
if (this.errorList_ != null) {
return Promise.resolve();
}
return loadScript(this.element.ownerDocument, `${urls.cdn}/v0/validator.js`)
.then(() =>
this.validateUrl_(/* global amp: false */ amp.validator, this.storyUrl_)
)
.then((errorList) => {
this.errorList_ = errorList;
this.updateDebugTabIcon(errorList);
});
}

/** @override */
layoutCallback() {
return this.buildDebugContent_();
})
.catch(() => {});
}

/**
Expand All @@ -134,9 +149,6 @@ export class AmpStoryDevToolsTabDebug extends AMP.BaseElement {
error.message = validator.renderErrorMessage(error);
return error;
});
})
.catch((error) => {
user().error(TAG, error);
});
}

Expand All @@ -145,7 +157,7 @@ export class AmpStoryDevToolsTabDebug extends AMP.BaseElement {
* @return {!Promise}
*/
buildDebugContent_() {
const debugContainer = this.errorList_.length
const debugContainer = this.errorList_?.length
? this.createErrorsList_()
: buildSuccessMessageTemplate(this.element);
debugContainer.prepend(this.buildDebugTitle_(this.errorList_.length));
Expand Down