Conversation
Reviewer's GuideIntroduces a PageIndex parameter to PdfViewer and refactors rendering logic by removing internal state caching, ensuring the PDF reloads correctly with the specified page index. Sequence diagram for PDF reload with PageIndex parametersequenceDiagram
actor User
participant PdfViewer
participant JSInterop
User->>PdfViewer: Set Url or PageIndex
PdfViewer->>PdfViewer: OnAfterRenderAsync(false)
PdfViewer->>JSInterop: InvokeVoidAsync("loadPdf", Id, GetAbsoluteUri(Url))
JSInterop-->>PdfViewer: PDF loaded at specified page
Class diagram for updated PdfViewer componentclassDiagram
class PdfViewer {
+string? Url
+int PageIndex
+string? Height
+bool UseGoogleDocs
+string? UseGoogleDocsString
+Task OnAfterRenderAsync(bool firstRender)
+string GetAbsoluteUri(string? url)
}
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 and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.cs:24` </location>
<code_context>
+ /// Gets or sets the page index of the PDF file.
+ /// </summary>
+ [Parameter]
+ public int PageIndex { get; set; }
+
/// <summary>
</code_context>
<issue_to_address>
Consider defaulting PageIndex to 1 to avoid invalid PDF page references.
Defaulting to 1 aligns with standard PDF viewer behavior and helps prevent errors from invalid page references.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
[Parameter]
public int PageIndex { get; set; }
=======
[Parameter]
public int PageIndex { get; set; } = 1;
>>>>>>> REPLACE
</suggested_fix>
### Comment 2
<location> `src/components/BootstrapBlazor.PdfViewer/PdfViewer.razor.cs:111` </location>
<code_context>
url ??= string.Empty;
if (string.IsNullOrEmpty(url) || !UseGoogleDocs)
{
- return url;
+ return $"{url}#page={PageIndex}";
}
var uri = NavigationManager.ToAbsoluteUri(url);
</code_context>
<issue_to_address>
Appending '#page={PageIndex}' to all URLs may break some PDF viewers or integrations.
Some viewers or contexts may not handle the '#page=' fragment correctly. Consider making this addition optional or context-aware.
Suggested implementation:
```csharp
url ??= string.Empty;
// Add an optional parameter to control appending the page fragment
return GetProcessedUrl(url, appendPageFragment: false);
}
private string GetProcessedUrl(string url, bool appendPageFragment = false)
{
if (string.IsNullOrEmpty(url) || !UseGoogleDocs)
{
if (appendPageFragment)
{
return $"{url}#page={PageIndex}";
}
return url;
}
var uri = NavigationManager.ToAbsoluteUri(url);
if (appendPageFragment)
{
return $"{uri.AbsoluteUri}#page={PageIndex}";
}
return uri.AbsoluteUri;
```
You will need to update all usages of this code to call `GetProcessedUrl(url, appendPageFragment: true)` if you want to append the `#page={PageIndex}` fragment in specific contexts. By default, the fragment will not be appended, making the behavior context-aware and opt-in.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| [Parameter] | ||
| public int PageIndex { get; set; } |
There was a problem hiding this comment.
suggestion: Consider defaulting PageIndex to 1 to avoid invalid PDF page references.
Defaulting to 1 aligns with standard PDF viewer behavior and helps prevent errors from invalid page references.
| [Parameter] | |
| public int PageIndex { get; set; } | |
| [Parameter] | |
| public int PageIndex { get; set; } = 1; |
| await InvokeVoidAsync("loadPdf", Id, GetAbsoluteUri(Url)); | ||
| } | ||
| } | ||
|
|
There was a problem hiding this comment.
suggestion: Appending '#page={PageIndex}' to all URLs may break some PDF viewers or integrations.
Some viewers or contexts may not handle the '#page=' fragment correctly. Consider making this addition optional or context-aware.
Suggested implementation:
url ??= string.Empty;
// Add an optional parameter to control appending the page fragment
return GetProcessedUrl(url, appendPageFragment: false);
}
private string GetProcessedUrl(string url, bool appendPageFragment = false)
{
if (string.IsNullOrEmpty(url) || !UseGoogleDocs)
{
if (appendPageFragment)
{
return $"{url}#page={PageIndex}";
}
return url;
}
var uri = NavigationManager.ToAbsoluteUri(url);
if (appendPageFragment)
{
return $"{uri.AbsoluteUri}#page={PageIndex}";
}
return uri.AbsoluteUri;You will need to update all usages of this code to call GetProcessedUrl(url, appendPageFragment: true) if you want to append the #page={PageIndex} fragment in specific contexts. By default, the fragment will not be appended, making the behavior context-aware and opt-in.
Link issues
fixes #505
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Introduce a new PageIndex parameter, update URL generation to include the page anchor, and simplify reload logic by removing redundant state fields in PdfViewer.
New Features:
Enhancements: