Recently, I encountered an issue where a bug appeared in Chrome but worked fine in Firefox. The problem was with an upload component that looked like this:
<input type="file" v-on:change="upload($event)"/>
upload(e) {
this.name = e.target.files[0].name;
this.resultUrl = e.target.files[0];
}
After selecting a file, then choosing to reselect and cancel, the page seemed to hang. Strangely, there were no error messages in the console, leaving me to speculate on the cause of the bug.
After spending some time investigating, I suspected the issue might lie within the component itself. To confirm, I added a console.log(e.target.files)
statement in the upload method. As expected, the output from Chrome differed from that of Firefox. Here is what Chrome showed:
https://i.sstatic.net/mvicz.jpg
Further research led me to discover a related Stack Overflow post titled "Input type=file clearing file after clicking cancel in Chrome". Armed with this knowledge, I identified the root cause of the bug and implemented a fix by incorporating a conditional check.
This wasn't the first time I had encountered a situation where the page froze without any error messages in the console. So, how can errors occurring within Vue components be gracefully handled and addressed?