Improve thumbnail rendering reliability and error handling
Added delays in `EnvelopeViewer.razor` to ensure the DOM is ready and to render thumbnails sequentially, preventing browser overload and keeping the UI responsive. Enhanced error handling in `RenderThumbnailsAsync` with detailed debug logs. In `pdf-viewer.js`, introduced a retry mechanism to wait for canvas elements to appear in the DOM and added detailed error logging for missing canvases or PDF document issues. Replaced generic comments with specific error messages to improve debugging. These changes enhance the robustness, reliability, and user experience of the PDF viewer.
This commit is contained in:
@@ -223,7 +223,8 @@
|
||||
_currentPage = await JSRuntime.InvokeAsync<int>("pdfViewer.getCurrentPage");
|
||||
await InvokeAsync(StateHasChanged);
|
||||
|
||||
// Render thumbnails
|
||||
// Wait for DOM to be ready, then render thumbnails
|
||||
await Task.Delay(100);
|
||||
await RenderThumbnailsAsync();
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
@@ -304,11 +305,18 @@
|
||||
|
||||
async Task RenderThumbnailsAsync() {
|
||||
try {
|
||||
// Sequential rendering to avoid overwhelming the browser
|
||||
for (int i = 1; i <= _totalPages; i++) {
|
||||
await JSRuntime.InvokeVoidAsync("pdfViewer.renderThumbnail", i, $"thumb-canvas-{i}");
|
||||
|
||||
// Small delay between renders to keep UI responsive
|
||||
if (i < _totalPages) {
|
||||
await Task.Delay(50);
|
||||
}
|
||||
}
|
||||
} catch (Exception) {
|
||||
} catch (Exception ex) {
|
||||
// Thumbnail rendering is not critical
|
||||
System.Diagnostics.Debug.WriteLine($"Thumbnail rendering error: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user