-
-
Notifications
You must be signed in to change notification settings - Fork 236
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add & use BitMarkdownService class to BlazorUI (#10221) #10223
Add & use BitMarkdownService class to BlazorUI (#10221) #10223
Conversation
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the You can disable this status message by setting the WalkthroughThe changes refactor the markdown processing logic in the BitMarkdownViewer component. The previous implementation using the Changes
Sequence Diagram(s)sequenceDiagram
participant Viewer as BitMarkdownViewer
participant Parser as BitMarked
participant FS as File System (Script Loader)
Viewer->>Parser: OnInitializedAsync calls Parse(markdown)
Parser->>FS: Acquire semaphore & read script (ReadMarkedScriptText)
FS-->>Parser: Return script text (or error)
Parser->>Parser: Configure Jint Engine & evaluate script
Parser-->>Viewer: Return parsed HTML
Poem
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
🧹 Nitpick comments (1)
src/BlazorUI/Bit.BlazorUI.Extras/Services/BitMarked.cs (1)
34-63
: Consider adding disposal of resources.The semaphore is created but never disposed, which could potentially lead to resource leaks if the application is reloaded multiple times in the same process.
Consider making the BitMarked class implement IDisposable to properly clean up resources:
-public class BitMarked +public class BitMarked : IDisposable { private static string? _markedScriptText; private static readonly SemaphoreSlim _markedScriptReadTextSemaphore = new(1, 1); // Existing code... + public void Dispose() + { + _markedScriptReadTextSemaphore.Dispose(); + } }Alternatively, if you prefer to keep it as a static class, consider adding a static Dispose method that can be called during application shutdown.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
src/BlazorUI/Bit.BlazorUI.Extras/Components/MarkdownViewer/BitMarkdownViewer.razor.cs
(2 hunks)src/BlazorUI/Bit.BlazorUI.Extras/Services/BitMarked.cs
(1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
- GitHub Check: build and test
🔇 Additional comments (3)
src/BlazorUI/Bit.BlazorUI.Extras/Components/MarkdownViewer/BitMarkdownViewer.razor.cs (1)
34-38
: Good refactoring to use BitMarked service.The code has been simplified by delegating the markdown parsing logic to the new BitMarked service. The Task.Run ensures the potentially heavy parsing operation doesn't block the UI thread, and invoking StateHasChanged afterward ensures the UI is properly updated once parsing completes.
src/BlazorUI/Bit.BlazorUI.Extras/Services/BitMarked.cs (2)
6-10
: Good structure for the new BitMarked service class.The static fields and semaphore implementation provide an efficient way to load and cache the script text, ensuring it's only loaded once and thread-safety is maintained when accessing it.
13-30
: Effective implementation of the Parse method.The Parse method correctly handles null/empty input, uses the Jint engine with appropriate options, and properly executes the marked.parse function. The use of cancellation tokens is a good practice for long-running operations.
closes #10221
Summary by CodeRabbit
New Features
Refactor