Skip to content

feat(JitViewer): add JitViewer component#8024

Merged
ArgoZhang merged 8 commits into
mainfrom
doc-jit-viewer
May 20, 2026
Merged

feat(JitViewer): add JitViewer component#8024
ArgoZhang merged 8 commits into
mainfrom
doc-jit-viewer

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented May 20, 2026

Link issues

fixes #7880

Summary By Copilot

Regression?

  • Yes
  • No

Risk

  • High
  • Medium
  • Low

Verification

  • Manual (required)
  • Automated

Packaging changes reviewed?

  • Yes
  • No
  • N/A

☑️ Self Check before Merge

⚠️ Please check all items below before review. ⚠️

  • Doc is updated/provided or not needed
  • Demo is updated/provided or not needed
  • Merge the latest code from the main branch

Summary by Sourcery

Add a new JitViewer sample page and integrate it into the demo navigation.

New Features:

  • Introduce a JitViewer demo component that displays various document and media samples.
  • Provide client-side initialization logic for the JitViewer, including theme and locale handling.
  • Add sample assets (code, markdown, styles, and files) to demonstrate JitViewer capabilities.

Enhancements:

  • Expose the JitViewer demo through the existing menus and documentation/localization configuration.

Copilot AI review requested due to automatic review settings May 20, 2026 04:59
@bb-auto bb-auto Bot added the enhancement New feature or request label May 20, 2026
@bb-auto bb-auto Bot added this to the v10.6.0 milestone May 20, 2026
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai Bot commented May 20, 2026

Reviewer's Guide

Adds a new JitViewer demo page, JS interop bootstrap, and associated sample assets, and wires it into the server demo navigation and localization resources.

Sequence diagram for JitViewer initialization and theme handling

sequenceDiagram
    actor User
    participant JitViewers
    participant JitViewer
    participant SampleJsModule
    participant UtilityModule
    participant WindowJitViewer
    participant Viewer
    participant EventHandler

    User->>JitViewers: navigate /jit-viewer
    JitViewers->>JitViewer: render File parameter

    JitViewer->>SampleJsModule: init(id, invoke, options)
    SampleJsModule->>SampleJsModule: addLink(jit-viewer.css)
    SampleJsModule->>SampleJsModule: addScript(jit-viewer.min.js)

    SampleJsModule->>UtilityModule: getTheme()
    UtilityModule-->>SampleJsModule: theme

    SampleJsModule->>WindowJitViewer: createViewer(target, options)
    WindowJitViewer-->>SampleJsModule: viewer
    SampleJsModule->>Viewer: mount()

    SampleJsModule->>EventHandler: on(document, changed.bb.theme, updateTheme)
    EventHandler-->>Viewer: setTheme(e.theme) on theme change
Loading

File-Level Changes

Change Details Files
Wire JitViewer sample page into the demo navigation and localization/docs metadata.
  • Add a new menu item entry pointing to the /jit-viewer route in the menu extension configuration.
  • Extend localization resources to include JitViewer-related strings for at least en-US and zh-CN locales.
  • Register the new JitViewer documentation/demo entry in docs.json so it appears in the docs/demo index.
src/BootstrapBlazor.Server/Extensions/MenusLocalizerExtensions.cs
src/BootstrapBlazor.Server/Locales/en-US.json
src/BootstrapBlazor.Server/Locales/zh-CN.json
src/BootstrapBlazor.Server/docs.json
Introduce a JitViewers demo component that exposes the JitViewer UI with selectable sample documents.
  • Create a partial JitViewers component code-behind that injects a localizer and defines a list of sample document/media items plus the currently selected document path.
  • Add the Razor page for /jit-viewer which renders localized titles, package tips, a DemoBlock with a Select bound to the current document, and the JitViewer component bound to the selected file, plus an attribute table for JitViewer props.
src/BootstrapBlazor.Server/Components/Samples/JitViewers.razor.cs
src/BootstrapBlazor.Server/Components/Samples/JitViewers.razor
Add JS bootstrap/interop and static sample assets required for JitViewer to function in the demo site.
  • Add a JS module that loads JitViewer CSS/JS, normalizes locale/theme, instantiates the JitViewer instance, stores it in a shared Data registry, and exposes setFile and dispose helpers.
  • Provide CSS that imports the JitViewer library stylesheet and ensures the viewer fills the available area.
  • Add various sample files (markdown, C#, CSV, DXF, TXT, etc.) used by the JitViewers demo to showcase different file types; note that sample.cs mirrors the JitViewers component code as static content for viewing.
src/BootstrapBlazor.Server/wwwroot/samples/sample.js
src/BootstrapBlazor.Server/wwwroot/samples/sample.css
src/BootstrapBlazor.Server/wwwroot/samples/sample.md
src/BootstrapBlazor.Server/wwwroot/samples/sample.cs
src/BootstrapBlazor.Server/wwwroot/samples/sample.csv
src/BootstrapBlazor.Server/wwwroot/samples/sample.dxf
src/BootstrapBlazor.Server/wwwroot/samples/sample.txt

Assessment against linked issues

Issue Objective Addressed Explanation
#7880 Add a JitViewer demo page/component usage in the server app, including a route and menu entry to access it.
#7880 Integrate the JitViewer SDK assets and JS interop needed for the JitViewer component to function in the demo (loading scripts/styles and handling file/theme operations).

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai Bot left a comment

Choose a reason for hiding this comment

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

Hey - I've found 3 issues, and left some high level feedback:

  • The JitViewers class is duplicated in wwwroot/samples/sample.cs with what appears to be real component code under a static wwwroot path; consider replacing this with a minimal, non-compilable sample (e.g., stripped-down snippet or plain text) to avoid namespace/type duplication and accidental compilation issues.
  • In wwwroot/samples/sample.js, the changed.bb.theme event handler is registered in init but never removed in dispose; consider unsubscribing in dispose to prevent leaks when the viewer is destroyed.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The `JitViewers` class is duplicated in `wwwroot/samples/sample.cs` with what appears to be real component code under a static `wwwroot` path; consider replacing this with a minimal, non-compilable sample (e.g., stripped-down snippet or plain text) to avoid namespace/type duplication and accidental compilation issues.
- In `wwwroot/samples/sample.js`, the `changed.bb.theme` event handler is registered in `init` but never removed in `dispose`; consider unsubscribing in `dispose` to prevent leaks when the viewer is destroyed.

## Individual Comments

### Comment 1
<location path="src/BootstrapBlazor.Server/wwwroot/samples/sample.js" line_range="51-61" />
<code_context>
+    }
+}
+
+export function dispose(id) {
+    const data = Data.get(id);
+    if (data === null) {
+        return;
+    }
+
+    const { viewer } = data;
+    if (viewer) {
+        viewer.destroy();
+    }
</code_context>
<issue_to_address>
**suggestion (bug_risk):** Data store entries are not cleared on dispose, which can lead to stale references.

`dispose` destroys the viewer but leaves its entry in `Data`, which can keep DOM and delegate references alive unnecessarily. After destroying the viewer, also remove the entry (e.g. `Data.remove(id)`) so the store doesn’t retain stale objects.

```suggestion
export function dispose(id) {
    const data = Data.get(id);
    if (data === null) {
        return;
    }

    const { viewer } = data;
    if (viewer) {
        viewer.destroy();
    }

    Data.remove(id);
}
```
</issue_to_address>

### Comment 2
<location path="src/BootstrapBlazor.Server/wwwroot/samples/sample.md" line_range="5" />
<code_context>
+
+### Bugs
+* fix(Table): update resetTableWidth method by @ArgoZhang in https://github.com/dotnetcore/BootstrapBlazor/pull/7836
+* fix(DockView): TitleTemplate set ShowClose to false not work by @ArgoZhang in https://github.com/dotnetcore/BootstrapBlazor/pull/7875
+* fix(DataTableDynamicContext): not unload BootstrapBlazor_DynamicAssembly under IsExcel mode by @ArgoZhang in https://github.com/dotnetcore/BootstrapBlazor/pull/7900
+* fix(Localizer): makes JsonStringLocalizerFactory thread-safe by @ArgoZhang in https://github.com/dotnetcore/BootstrapBlazor/pull/7919
</code_context>
<issue_to_address>
**suggestion (typo):** Consider rephrasing this bullet to fix the grammar around "not work".

For example: "TitleTemplate with ShowClose set to false does not work" or "When ShowClose is set to false, TitleTemplate does not work."

```suggestion
* fix(DockView): When ShowClose is set to false, TitleTemplate does not work by @ArgoZhang in https://github.com/dotnetcore/BootstrapBlazor/pull/7875
```
</issue_to_address>

### Comment 3
<location path="src/BootstrapBlazor.Server/wwwroot/samples/sample.md" line_range="6" />
<code_context>
+### Bugs
+* fix(Table): update resetTableWidth method by @ArgoZhang in https://github.com/dotnetcore/BootstrapBlazor/pull/7836
+* fix(DockView): TitleTemplate set ShowClose to false not work by @ArgoZhang in https://github.com/dotnetcore/BootstrapBlazor/pull/7875
+* fix(DataTableDynamicContext): not unload BootstrapBlazor_DynamicAssembly under IsExcel mode by @ArgoZhang in https://github.com/dotnetcore/BootstrapBlazor/pull/7900
+* fix(Localizer): makes JsonStringLocalizerFactory thread-safe by @ArgoZhang in https://github.com/dotnetcore/BootstrapBlazor/pull/7919
+
</code_context>
<issue_to_address>
**suggestion (typo):** The phrase "not unload" is missing an auxiliary verb.

Consider changing this to “does not unload BootstrapBlazor_DynamicAssembly under IsExcel mode” (or similar) so the sentence has the auxiliary verb and reads more naturally.

```suggestion
* fix(DataTableDynamicContext): does not unload BootstrapBlazor_DynamicAssembly under IsExcel mode by @ArgoZhang in https://github.com/dotnetcore/BootstrapBlazor/pull/7900
```
</issue_to_address>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

Comment on lines +51 to +61
export function dispose(id) {
const data = Data.get(id);
if (data === null) {
return;
}

const { viewer } = data;
if (viewer) {
viewer.destroy();
}
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion (bug_risk): Data store entries are not cleared on dispose, which can lead to stale references.

dispose destroys the viewer but leaves its entry in Data, which can keep DOM and delegate references alive unnecessarily. After destroying the viewer, also remove the entry (e.g. Data.remove(id)) so the store doesn’t retain stale objects.

Suggested change
export function dispose(id) {
const data = Data.get(id);
if (data === null) {
return;
}
const { viewer } = data;
if (viewer) {
viewer.destroy();
}
}
export function dispose(id) {
const data = Data.get(id);
if (data === null) {
return;
}
const { viewer } = data;
if (viewer) {
viewer.destroy();
}
Data.remove(id);
}


### Bugs
* fix(Table): update resetTableWidth method by @ArgoZhang in https://github.com/dotnetcore/BootstrapBlazor/pull/7836
* fix(DockView): TitleTemplate set ShowClose to false not work by @ArgoZhang in https://github.com/dotnetcore/BootstrapBlazor/pull/7875
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

suggestion (typo): Consider rephrasing this bullet to fix the grammar around "not work".

For example: "TitleTemplate with ShowClose set to false does not work" or "When ShowClose is set to false, TitleTemplate does not work."

Suggested change
* fix(DockView): TitleTemplate set ShowClose to false not work by @ArgoZhang in https://github.com/dotnetcore/BootstrapBlazor/pull/7875
* fix(DockView): When ShowClose is set to false, TitleTemplate does not work by @ArgoZhang in https://github.com/dotnetcore/BootstrapBlazor/pull/7875

Comment thread src/BootstrapBlazor.Server/wwwroot/samples/sample.md
@codecov
Copy link
Copy Markdown

codecov Bot commented May 20, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (61cb823) to head (df37066).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #8024   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          766       766           
  Lines        34123     34123           
  Branches      4692      4692           
=========================================
  Hits         34123     34123           
Flag Coverage Δ
BB 100.00% <ø> (?)

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Adds a new JitViewer demo entry to the BootstrapBlazor.Server samples site (menu + docs routing) and includes additional sample files under wwwroot/samples for previewing different formats.

Changes:

  • Added a new /jit-viewer sample page (JitViewers) and wired it into docs routing and the demo menu.
  • Added localized menu text for JitViewer in en-US/zh-CN.
  • Added several new static sample files (txt/md/js/css/csv/dxf/cs) for the viewer demo to open.

Reviewed changes

Copilot reviewed 14 out of 16 changed files in this pull request and generated 4 comments.

Show a summary per file
File Description
src/BootstrapBlazor.Server/wwwroot/samples/sample.txt Adds a plain-text sample file for preview.
src/BootstrapBlazor.Server/wwwroot/samples/sample.md Adds a markdown sample file for preview.
src/BootstrapBlazor.Server/wwwroot/samples/sample.js Adds a JavaScript sample file for preview.
src/BootstrapBlazor.Server/wwwroot/samples/sample.dxf Adds a DXF sample file for preview.
src/BootstrapBlazor.Server/wwwroot/samples/sample.csv Adds a CSV sample file for preview.
src/BootstrapBlazor.Server/wwwroot/samples/sample.css Adds a CSS sample file for preview.
src/BootstrapBlazor.Server/wwwroot/samples/sample.cs Adds a C# sample file for preview.
src/BootstrapBlazor.Server/Locales/zh-CN.json Adds the JitViewer menu localization entry (zh-CN).
src/BootstrapBlazor.Server/Locales/en-US.json Adds the JitViewer menu localization entry (en-US).
src/BootstrapBlazor.Server/Extensions/MenusLocalizerExtensions.cs Adds the JitViewer menu item pointing to jit-viewer.
src/BootstrapBlazor.Server/docs.json Registers jit-viewerJitViewers for docs routing.
src/BootstrapBlazor.Server/Components/Samples/JitViewers.razor.cs Adds the backing code and selectable sample document list.
src/BootstrapBlazor.Server/Components/Samples/JitViewers.razor Adds the new sample page UI that hosts <JitViewer>.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

"Introduction": "Introduction",
"Ip": "IpAddress",
"JitViewer": "JitViewer",
"JSExtension": "JSRuntime Extensions",
"Introduction": "简介",
"Ip": "IP 地址 IpAddress",
"JitViewer": "文件预览器 JitViewer",
"JSExtension": "JSRuntime 扩展",
Comment on lines +17 to +20
<JitViewer File="@_doc"></JitViewer>
</DemoBlock>

<AttributeTable Type="typeof(JitViewer)"></AttributeTable>
Comment thread src/BootstrapBlazor.Server/Components/Samples/JitViewers.razor.cs Outdated
@ArgoZhang ArgoZhang merged commit 18056d5 into main May 20, 2026
4 checks passed
@ArgoZhang ArgoZhang deleted the doc-jit-viewer branch May 20, 2026 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

feat(JitViewer): add JitViewer component

2 participants