Skip to content

feat(DynamicElement): add Key parameter#7636

Merged
ArgoZhang merged 32 commits intomainfrom
dev-test
Feb 8, 2026
Merged

feat(DynamicElement): add Key parameter#7636
ArgoZhang merged 32 commits intomainfrom
dev-test

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Feb 7, 2026

Link issues

fixes #7637

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 support for element keys in dynamic components and improve ZIP archive handling for files and directories.

New Features:

  • Allow DynamicElement to accept a unique Key parameter and apply it to the rendered element.

Bug Fixes:

  • Ensure ZIP archive entries close their streams after copying content and correctly create entries for directory sources.

* feat(IpAddress): support paste function

* refactor: 代码格式化
# Conflicts:
#	src/BootstrapBlazor/Components/IpAddress/IpAddress.razor.js
* refactor: 增加 JSInvoke 能力

* refactor: 更改样式

* refactor: 增加客户端更改 IP 回调方法

* test: 更新单元测试

* chore: bump version 10.1.3
# Conflicts:
#	src/BootstrapBlazor/BootstrapBlazor.csproj
#	src/BootstrapBlazor/Components/IpAddress/IpAddress.razor.scss
#	test/UnitTest/Components/IpAddressTest.cs
# Conflicts:
#	src/BootstrapBlazor/Services/DefaultZipArchiveService.cs
#	src/BootstrapBlazor/Services/IZipArchiveService.cs
# Conflicts:
#	test/UnitTest/Services/ZipArchiveServiceTest.cs
# Conflicts:
#	src/BootstrapBlazor/BootstrapBlazor.csproj
#	src/BootstrapBlazor/Components/BaseComponents/BootstrapModuleComponentBase.cs
#	src/BootstrapBlazor/Components/BaseComponents/DynamicElement.cs
#	src/BootstrapBlazor/Components/Drawer/Drawer.razor.js
#	src/BootstrapBlazor/Components/IpAddress/IpAddress.razor.cs
#	src/BootstrapBlazor/Components/IpAddress/IpAddress.razor.scss
#	src/BootstrapBlazor/Components/Table/Table.razor
#	src/BootstrapBlazor/Components/Table/Table.razor.cs
#	src/BootstrapBlazor/Components/TreeView/TreeView.razor.cs
#	src/BootstrapBlazor/Components/Upload/CardUpload.razor
#	src/BootstrapBlazor/Components/Upload/CardUpload.razor.cs
#	src/BootstrapBlazor/Options/PdfOptions.cs
#	src/BootstrapBlazor/Services/DefaultZipArchiveService.cs
#	src/BootstrapBlazor/Services/IZipArchiveService.cs
#	test/UnitTest/Components/IpAddressTest.cs
#	test/UnitTest/Services/ZipArchiveServiceTest.cs
Copilot AI review requested due to automatic review settings February 7, 2026 09:55
@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Feb 7, 2026

Reviewer's Guide

Adds key support to DynamicElement rendering and fixes/improves directory handling when creating ZIP archives, including explicit entry creation for directories and stream cleanup.

Class diagram for DynamicElement and DefaultZipArchiveService changes

classDiagram
    class DynamicElement {
        +bool GenerateElement
        +object Key
        +RenderFragment ChildContent
        +bool IsTriggerClick()
        +bool IsTriggerDoubleClick()
        +void BuildRenderTree(RenderTreeBuilder builder)
    }

    class DefaultZipArchiveService {
        +Task ArchiveFilesAsync(Stream stream, IEnumerable_ArchiveEntryInfo_ files, ZipArchiveOptions options, CancellationToken cancellationToken)
    }

    class ArchiveEntryInfo {
        +string SourceFileName
        +string EntryName
        +CompressionLevel CompressionLevel
    }

    class ZipArchiveOptions {
        +CompressionLevel CompressionLevel
        +Task~Stream~ ReadStreamAsync(string sourceFileName)
    }

    DefaultZipArchiveService --> ArchiveEntryInfo : uses
    DefaultZipArchiveService --> ZipArchiveOptions : uses
    DynamicElement --> RenderTreeBuilder : uses
    DynamicElement --> RenderFragment : uses
Loading

Flow diagram for updated ArchiveFilesAsync directory and file handling

flowchart TD
    A["Start ArchiveFilesAsync"] --> B["For each ArchiveEntryInfo f"]
    B --> C{"File.Exists(f.SourceFileName)?"}
    C -- "Yes" --> D["Create file entry in archive
archive.CreateEntry(f.EntryName, compressionLevel)"]
    D --> E["Read content stream via options.ReadStreamAsync"]
    E --> F["Open entry stream"]
    F --> G["CopyToAsync from content to entry stream"]
    G --> H["entryStream.Close()"]
    H --> I["Next file"]

    C -- "No" --> J{"Directory.Exists(f.SourceFileName)?"}
    J -- "Yes" --> K{"Is f.EntryName null or empty?"}
    K -- "No" --> L{"Does f.EntryName end with directory separator?"}
    L -- "No" --> M["Append Path.DirectorySeparatorChar to f.EntryName"]
    M --> N["Create directory entry in archive
archive.CreateEntry(entryName, compressionLevel)"]
    L -- "Yes" --> N
    N --> I

    K -- "Yes" --> I
    J -- "No" --> I
    I --> O["End loop"]
    O --> P["End ArchiveFilesAsync"]
Loading

File-Level Changes

Change Details Files
Add support for an explicit rendering key on DynamicElement and apply it in the render tree.
  • Introduce a new nullable Key component parameter with bilingual XML documentation describing it as a unique element identifier.
  • Update BuildRenderTree summary to inherit base documentation.
  • Set the render tree key with builder.SetKey(Key) when a non-null Key value is provided, after adding child content and before conditionally closing the element.
src/BootstrapBlazor/Components/BaseComponents/DynamicElement.cs
Adjust ZIP archive creation logic to better handle file streams and directory entries.
  • Explicitly close the entry stream after copying file content into the ZIP entry.
  • Add conditional handling when the source path is a directory to create a directory entry in the archive, ensuring the entry name ends with a directory separator.
  • Leave the existing directory branch (likely to be removed or refactored) for further review of duplicated directory handling logic.
src/BootstrapBlazor/Services/DefaultZipArchiveService.cs

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 1 issue, and left some high level feedback:

  • The new else if (Directory.Exists(f.SourceFileName)) block in ArchiveFilesAsync makes the existing else if (Directory.Exists(f.SourceFileName)) immediately below it unreachable; consolidate these into a single directory-handling branch.
  • In ArchiveFilesAsync, entryStream is already wrapped in await using, so the explicit entryStream.Close() call is redundant and can be removed to avoid confusion about ownership/disposal.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- The new `else if (Directory.Exists(f.SourceFileName))` block in `ArchiveFilesAsync` makes the existing `else if (Directory.Exists(f.SourceFileName))` immediately below it unreachable; consolidate these into a single directory-handling branch.
- In `ArchiveFilesAsync`, `entryStream` is already wrapped in `await using`, so the explicit `entryStream.Close()` call is redundant and can be removed to avoid confusion about ownership/disposal.

## Individual Comments

### Comment 1
<location> `src/BootstrapBlazor/Components/BaseComponents/DynamicElement.cs:141-143` </location>
<code_context>

         builder.AddContent(8, ChildContent);

+        if (Key != null)
+        {
+            builder.SetKey(Key);
+        }
+
</code_context>

<issue_to_address>
**suggestion:** Consider calling `builder.SetKey(Key)` immediately after `OpenElement` instead of after `AddContent`.

This will work, but the usual Blazor pattern is to call `SetKey` immediately after `OpenElement`/`OpenRegion` so the key clearly applies to the element rather than any content frames. Placing it there makes the intent clearer and reduces the risk of subtle issues if the render sequence changes later.

Suggested implementation:

```csharp
        if (Key != null)
        {
            builder.SetKey(Key);
        }

        builder.AddContent(8, ChildContent);


    /// <summary>

```

If `BuildRenderTree` contains a call like `builder.OpenElement(sequence, tagName)` or `builder.OpenRegion(sequence)` above this snippet, the ideal pattern in Blazor is:

```csharp
builder.OpenElement(0, "some-tag");
if (Key != null)
{
    builder.SetKey(Key);
}
builder.AddContent(8, ChildContent);
// ...
builder.CloseElement();
```

So you may want to further adjust the method to ensure the `SetKey` block appears *immediately after* `OpenElement`/`OpenRegion` and before any other content is added, following the usual Blazor pattern.
</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.

@ArgoZhang ArgoZhang changed the title wip: merge branch feat(DynamicElement): add Key parameter Feb 7, 2026
@bb-auto bb-auto bot added the enhancement New feature or request label Feb 7, 2026
@bb-auto bb-auto bot added this to the v10.3.0 milestone Feb 7, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 7, 2026

Codecov Report

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

Additional details and impacted files
@@            Coverage Diff            @@
##              main     #7636   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          749       749           
  Lines        33105     33109    +4     
  Branches      4593      4593           
=========================================
+ Hits         33105     33109    +4     
Flag Coverage Δ
BB 100.00% <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

This PR updates BootstrapBlazor internals around ZIP archive creation and dynamic element rendering, adding support for keyed rendering and adjusting how directory entries are handled when archiving.

Changes:

  • Added directory-entry handling logic during ZIP creation and explicitly closed the ZIP entry stream after copying.
  • Added a new Key parameter to DynamicElement and applied it via RenderTreeBuilder.SetKey.

Reviewed changes

Copilot reviewed 1 out of 1 changed files in this pull request and generated 1 comment.

File Description
src/BootstrapBlazor/Services/DefaultZipArchiveService.cs Adjusts ZIP entry writing/closing and introduces directory-entry creation logic.
src/BootstrapBlazor/Components/BaseComponents/DynamicElement.cs Adds a Key parameter and applies keyed rendering in BuildRenderTree.

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

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(DynamicElement): add Key parameter

2 participants