Conversation
Reviewer's GuideThis PR introduces a new OfficeViewer component that embeds Office documents via Office Online Viewer, combining a Blazor Razor component with C# lifecycle logic and JS interop to initialize, load, and style the viewer dynamically. Sequence diagram for OfficeViewer initialization and document loadingsequenceDiagram
participant User as actor User
participant Blazor as OfficeViewer (Blazor)
participant JS as OfficeViewer.razor.js
participant OfficeOnline as Office Online Viewer
User->>Blazor: Navigates to OfficeViewer component
Blazor->>JS: Invoke init(id, invoke, options)
JS->>JS: addLink(office-viewer.css)
JS->>JS: Data.set(id, officeViewer)
JS->>JS: load(id, options.url)
JS->>OfficeOnline: iframe src=https://view.officeapps.live.com/op/embed.aspx?src=url
OfficeOnline-->>JS: Document loaded
JS->>Blazor: invokeMethodAsync(LoadedCallaback)
Blazor->>User: OnLoaded callback (if set)
Class diagram for the new OfficeViewer componentclassDiagram
class OfficeViewer {
+string? Url
+string? Height
+Func<Task>? OnLoaded
-NavigationManager? NavigationManager
-string? ClassString
-string? StyleString
-string? _url
+Task OnAfterRenderAsync(bool firstRender)
+Task InvokeInitAsync()
-string GetAbsoluteUri(string? url)
+Task TriggerOnLoaded()
}
OfficeViewer --|> BootstrapModuleComponentBase
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:
- Rather than using Func for the OnLoaded callback, consider switching to an EventCallback (or EventCallback) so it follows standard Blazor event patterns.
- You’re using CssBuilder to generate inline styles in StyleString; it might be clearer to use a dedicated style builder or just interpolate the
--bb-office-viewer-heightCSS variable directly into the style attribute. - The JS side stores viewer instances in a shared Data map but there’s no cleanup on component disposal—consider implementing DisposeAsync (or OnAfterDispose) to remove the entry and avoid potential memory leaks.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Rather than using Func<Task> for the OnLoaded callback, consider switching to an EventCallback (or EventCallback<T>) so it follows standard Blazor event patterns.
- You’re using CssBuilder to generate inline styles in StyleString; it might be clearer to use a dedicated style builder or just interpolate the `--bb-office-viewer-height` CSS variable directly into the style attribute.
- The JS side stores viewer instances in a shared Data map but there’s no cleanup on component disposal—consider implementing DisposeAsync (or OnAfterDispose) to remove the entry and avoid potential memory leaks.
## Individual Comments
### Comment 1
<location> `src/components/BootstrapBlazor.OfficeViewer/OfficeViewer.razor.cs:42` </location>
<code_context>
+ .AddClassFromAttributes(AdditionalAttributes)
+ .Build();
+
+ private string? StyleString => CssBuilder.Default()
+ .AddClass($"--bb-office-viewer-height: {Height};", !string.IsNullOrEmpty(Height))
+ .Build();
+
</code_context>
<issue_to_address>
Use AddStyle instead of AddClass for inline style construction.
Using AddClass for a CSS variable may prevent the height from being applied correctly. Use AddStyle to set the variable as an inline style.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Comment on lines
+42
to
+43
| private string? StyleString => CssBuilder.Default() | ||
| .AddClass($"--bb-office-viewer-height: {Height};", !string.IsNullOrEmpty(Height)) |
There was a problem hiding this comment.
issue (bug_risk): Use AddStyle instead of AddClass for inline style construction.
Using AddClass for a CSS variable may prevent the height from being applied correctly. Use AddStyle to set the variable as an inline style.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Link issues
fixes #477
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
Summary by Sourcery
Add OfficeViewer component to embed and display Office documents, complete with JS interop, styling, and project integration.
New Features:
Enhancements:
Chores: