Skip to content

Conversation

@msynk
Copy link
Member

@msynk msynk commented Sep 2, 2025

closes #11318

Summary by CodeRabbit

  • Bug Fixes
    • Improved reliability of Markdown rendering across server and client, preventing failures due to missing assets and enhancing error messages.
  • Refactor
    • Streamlined internal loading and caching of the Markdown parser for faster, more stable initialization.
  • Chores
    • Updated framework and dependency references to enhance compatibility and overall stability.

@coderabbitai
Copy link

coderabbitai bot commented Sep 2, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

Adds a FrameworkReference to Microsoft.AspNetCore.App and reorganizes PrivateAssets for dependencies. Refactors BitMarkdownService to use IServiceProvider and IWebHostEnvironment’s WebRootFileProvider for marked.js resolution, updates script path to _content, renames fields/methods, and adjusts client/server parsing flow.

Changes

Cohort / File(s) Summary
Project references & packaging
src/BlazorUI/Bit.BlazorUI.Extras/Bit.BlazorUI.Extras.csproj
Added FrameworkReference Microsoft.AspNetCore.App (PrivateAssets="all"). Moved Newtonsoft.Json and Jint PackageReferences to a new ItemGroup and switched PrivateAssets from nested element to attribute. Existing Microsoft.AspNetCore.Components.Web references unchanged.
Markdown service refactor & asset resolution
src/BlazorUI/Bit.BlazorUI.Extras/Services/BitMarkdownService.cs
Constructor now BitMarkdownService(IJSRuntime js, IServiceProvider serviceProvider). Uses DI to get IWebHostEnvironment and resolve marked.js via WebRootFileProvider. Updated MARKED_FILE path to _content/Bit.BlazorUI.Extras/marked/marked-15.0.7.js. Renamed fields/semaphore. Renamed RuntJint→RunJint. Adjusted client/server parsing logic and error messages.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor UI as Component
  participant Svc as BitMarkdownService
  participant Env as IWebHostEnvironment
  participant FS as WebRootFileProvider (IFileProvider)
  participant JS as IJSRuntime
  participant Jint as Jint Engine

  UI->>Svc: Parse(markdown)
  alt Server-side parsing
    Svc->>Env: Resolve via IServiceProvider
    Env->>FS: GetFileInfo("_content/.../marked-15.0.7.js")
    FS-->>Svc: FileInfo(PhysicalPath)
    Svc->>Svc: ReadMarkedScriptContent (semaphore)
    Svc->>Jint: RunJint(markdown, scriptContent)
    Jint-->>Svc: html
    Svc-->>UI: html
  else Client-side parsing
    Svc->>JS: Ensure marked loaded from "_content/.../marked-15.0.7.js"
    JS-->>Svc: ready
    Svc->>JS: marked.parse(markdown)
    JS-->>Svc: html
    Svc-->>UI: html
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Assessment against linked issues

Objective Addressed Explanation
Improve physical file path discovery using IFileProvider in BitMarkdownService (#11318)

Assessment against linked issues: Out-of-scope changes

Code Change Explanation
Add FrameworkReference Microsoft.AspNetCore.App (PrivateAssets="all") in csproj (src/BlazorUI/Bit.BlazorUI.Extras/Bit.BlazorUI.Extras.csproj, lines: unknown) Not required by #11318; unrelated to file path discovery for marked.js.
Reformat PackageReference PrivateAssets as attributes and regroup ItemGroup (src/BlazorUI/Bit.BlazorUI.Extras/Bit.BlazorUI.Extras.csproj, lines: unknown) Packaging style change not specified in #11318.

Poem

I nibble docs with whiskered cheer,
A marked path found, now crystal clear.
Through roots and files I swiftly hop,
Provider trails lead to the top.
With Jint or JS, I parse and play—
Hooray for tidy code today! 🥕✨

✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

CodeRabbit Commands (Invoked using PR/Issue comments)

Type @coderabbitai help to get the list of available commands.

Other keywords and placeholders

  • Add @coderabbitai ignore or @coderabbit ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Status, Documentation and Community

  • Visit our Status Page to check the current availability of CodeRabbit.
  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🧹 Nitpick comments (5)
src/BlazorUI/Bit.BlazorUI.Extras/Bit.BlazorUI.Extras.csproj (1)

24-28: Use of FrameworkReference looks fine; consider a couple of refinements.

  • PrivateAssets on FrameworkReference is harmless but redundant; FrameworkReferences aren’t transitive. Consider dropping it to reduce noise.
  • If the sole motivation is IWebHostEnvironment (server-only), this reference is appropriate. Otherwise, evaluate whether a narrower package reference (e.g., Hosting.Abstractions) would suffice.
src/BlazorUI/Bit.BlazorUI.Extras/Services/BitMarkdownService.cs (4)

12-12: Avoid hardcoding the marked.js version in code.

Consider centralizing the version (e.g., MSBuild property or generated constants) so bumps don’t require code edits. Alternatively, expose a single stable path (e.g., marked/marked.js) and map/version it at build time.


86-86: Prefer GetService with null-check to avoid hard failures in atypical hosts.

Using GetRequiredService will throw if IWebHostEnvironment isn’t registered (e.g., tests, non-HTTP hosts). Since you resolve it only on server path, a soft failure is nicer.

Apply this diff:

-            var env = serviceProvider.GetRequiredService<Microsoft.AspNetCore.Hosting.IWebHostEnvironment>();
+            var env = serviceProvider.GetService<Microsoft.AspNetCore.Hosting.IWebHostEnvironment>();
+            if (env is null)
+            {
+                Console.Error.WriteLine("IWebHostEnvironment is not available in this host.");
+                return _markedScriptContent = string.Empty;
+            }

31-31: Minor: remove redundant async/await wrapper in Task.Run.

No need for an async lambda here.

Apply this diff:

-                html = await Task.Run(async () => await RunJint(markdown, cancellationToken), cancellationToken);
+                html = await Task.Run(() => RunJint(markdown, cancellationToken), cancellationToken);

35-36: Use ILogger instead of Console.Error for diagnostics.

Library consumers can route logs appropriately; Console writes are easy to miss.

If you want, I can wire ILogger and update these call sites.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Knowledge Base: Disabled due to Reviews > Disable Knowledge Base setting

📥 Commits

Reviewing files that changed from the base of the PR and between b7c7f9b and e30a88b.

📒 Files selected for processing (2)
  • src/BlazorUI/Bit.BlazorUI.Extras/Bit.BlazorUI.Extras.csproj (1 hunks)
  • src/BlazorUI/Bit.BlazorUI.Extras/Services/BitMarkdownService.cs (4 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (1)
  • GitHub Check: build and test

@msynk msynk merged commit 98b5604 into bitfoundation:develop Sep 2, 2025
3 checks passed
@msynk msynk deleted the 11318-blazorui-markdownservice-maked-file-discovery-improvements branch September 2, 2025 11:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

The physical file path discovery of the marked JS library in the BitMarkdownService class needs improvement

1 participant