feat(PdfViewer): add UseGoogleDocs parameter#454
Conversation
Reviewer's GuideIntroduces a new UseGoogleDocs toggle to the PdfViewer component, with component-level state tracking and updates to both Razor and JS interop to optionally render PDFs via the Google Docs viewer and to reinitialize the viewer when this flag or the URL changes. File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @ArgoZhang - I've reviewed your changes - here's some feedback:
- Use HTTPS and encode the PDF URL when constructing the Google Docs viewer link to avoid mixed-content issues and ensure valid URLs.
- The manual state-tracking in OnAfterRenderAsync for _url and _useGoogleDocs could be simplified by overriding ShouldRender or leveraging Blazor’s built-in change detection.
- Re-add clearing logic for when Url is null or empty, as removing the else branch in loadPdf may leave old frames in place when no URL is provided.
Here's what I looked at during the review
- 🟡 General issues: 1 issue found
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟡 Complexity: 1 issue found
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| if (useGoogleDocs) { | ||
| url = `http://docs.google.com/viewer?url=${url}` | ||
| } |
There was a problem hiding this comment.
suggestion (bug_risk): Use HTTPS and encode URL when loading Google Docs viewer
Update the protocol to https:// and use encodeURIComponent(url) to prevent mixed-content errors and handle special characters in the URL.
| if (useGoogleDocs) { | |
| url = `http://docs.google.com/viewer?url=${url}` | |
| } | |
| if (useGoogleDocs) { | |
| url = `https://docs.google.com/viewer?url=${encodeURIComponent(url)}` | |
| } |
| private string? _url; | ||
| private bool _useGoogleDocs; | ||
|
|
||
| private string? UseGoogleDocsString => UseGoogleDocs ? "true" : null; |
There was a problem hiding this comment.
issue (complexity): Consider removing the unused property and simplifying the rerender logic in OnAfterRenderAsync with a single if/else block.
// 1) Remove the unused property
// private string? UseGoogleDocsString => UseGoogleDocs ? "true" : null;
// 2) Collapse OnAfterRenderAsync into a single if/else
protected override async Task OnAfterRenderAsync(bool firstRender)
{
await base.OnAfterRenderAsync(firstRender);
if (firstRender)
{
_url = Url;
_useGoogleDocs = UseGoogleDocs;
}
else if (_url != Url || _useGoogleDocs != UseGoogleDocs)
{
_url = Url;
_useGoogleDocs = UseGoogleDocs;
await InvokeVoidAsync("loadPdf", Id, _url);
}
}These two changes preserve all behavior while removing dead code and flattening the rerender logic.
|
|
||
| const useGoogleDocs = el.getAttribute('data-bb-google-docs') === 'true'; | ||
| if (useGoogleDocs) { | ||
| url = `http://docs.google.com/viewer?url=${url}` |
There was a problem hiding this comment.
issue (code-quality): Don't reassign parameter - url (dont-reassign-parameters)
Explanation
Reassigning parameters can lead to unexpected behavior, especially when accessing the arguments object. It can also cause optimization issues, especially in V8.From the Airbnb JavaScript Style Guide
Link issues
fixes #453
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Introduce a new UseGoogleDocs parameter and update the interop logic to load PDFs via Google Docs when enabled, while ensuring the viewer is properly reinitialized on configuration changes.
New Features:
Enhancements: