fileuploader fixed - #119
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to harden the widget’s file uploader and automatic screenshot flow by adding defensive guards and correcting element-detection logic, with the compiled bundle updated accordingly.
Changes:
- Adds guarded
FileUploaderinitialization and safer screenshot invocation in the widget open flow. - Fixes
FileUploader.initializeElements()to warn when the uploader wrapper is missing (correcting the prior inverted condition). - Updates the built
dist/doboard-widget-bundle.jsoutput to reflect the source changes.
Reviewed changes
Copilot reviewed 2 out of 5 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| js/src/widget.js | Adds defensive initialization and optional-chained guards around FileUploader and makeScreenshot() usage. |
| js/src/fileuploader.js | Corrects missing-element detection and adds additional safety checks around screenshot creation/DOM integration. |
| dist/doboard-widget-bundle.js | Rebuild output reflecting the source changes (including the updated file uploader logic). |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 2 out of 5 changed files in this pull request and generated no new comments.
Suppressed comments (4)
js/src/fileuploader.js:517
validateFile,clearError, andaddFileare class methods, so the addedtypeof ... === 'function'checks add noise and can mask real defects. AlsoaddFileError.messagemay be undefined; logging the full error preserves stack/context.
if (typeof this.validateFile === 'function' && this.validateFile(file)) {
if (this.uploaderWrapper && this.uploaderWrapper.style && this.uploaderWrapper.style.display !== 'block') {
this.uploaderWrapper.style.display = 'block';
}
js/src/widget.js:949
- This condition can be simplified:
thisis not optional here, and checkingthis?.fileUploader?.makeScreenshotbeforetypeof ... === 'function'is redundant.
if (!this?.nonRequesting && this?.fileUploader?.makeScreenshot && typeof this?.fileUploader?.makeScreenshot === 'function') {
js/src/widget.js:947
thisis already used unguarded just above, so optional-chaining onthishere and theif (this?.fileUploader)check are redundant. Also logging onlyerror.messagedrops stack/context; log the error object instead.
This issue also appears on line 949 of the same file.
this.fileUploader = new FileUploader(this?.escapeHtml);
if (this?.fileUploader) {
try {
this.fileUploader.init();
} catch (error) {
js/src/fileuploader.js:427
- The screenshot guard condition has redundant checks (
this.filesis always initialized as an array in the constructor), and the log message mentions "not fully initialized" even though no init state is checked. This makes the code harder to reason about.
This issue also appears on line 513 of the same file.
if (!this.files || !Array.isArray(this.files) || this.files.length >= this.maxFiles) {
console.log('SpotFix: File count limit reached or file uploader is not fully initialized.');
return;
}
No description provided.