Skip to content

Conversation

@ysmoradi
Copy link
Member

@ysmoradi ysmoradi commented Sep 16, 2025

closes #11406

Summary by CodeRabbit

  • Bug Fixes

    • Improved reliability of real-time notifications and in-app messages.
    • Standardized notification payloads to prevent display issues in diagnostics and role updates.
    • User profile updates now send only mapped fields, reducing unnecessary data exposure.
  • Refactor

    • Unified error responses with a consistent problem details format for clearer diagnostics.
    • Enhanced SignalR JSON serialization for better compatibility and stability across clients.

@ysmoradi ysmoradi requested a review from Copilot September 16, 2025 13:36
@coderabbitai
Copy link

coderabbitai bot commented Sep 16, 2025

Walkthrough

SignalR message payloads were standardized to Dictionary<string, string?> across client and server handlers. Server configured SignalR to use System.Text.Json source-generated contexts. Exception handling now returns AppProblemDetails instead of ProblemDetails. Minor formatting changes were applied, with no other public API changes besides these.

Changes

Cohort / File(s) Summary
SignalR client handler update
src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/AppClientCoordinator.cs
Updated SHOW_MESSAGE subscription: hubConnection.On<string, Dictionary<string, string?>?, bool>(...) replacing object payload with Dictionary<string, string?>?. Lambda parameter type adjusted; logic unchanged. Public API usage changed accordingly.
Server controllers: SHOW_MESSAGE payloads
.../Server/Boilerplate.Server.Api/Controllers/AttachmentController.cs, .../Server/Boilerplate.Server.Api/Controllers/Diagnostics/DiagnosticsController.cs, .../Server/Boilerplate.Server.Api/Controllers/Identity/RoleManagementController.cs
Replaced anonymous/object payloads with Dictionary<string, string?> when invoking SignalR SHOW_MESSAGE. AttachmentController maps user to user.Map() before sending. No controller public signatures changed.
SignalR JSON serialization config
.../Server/Boilerplate.Server.Api/Program.Services.cs
Configured SignalR AddJsonProtocol to use source-generated contexts: base AppJsonContext.Default, plus IdentityJsonContext.Default and ServerJsonContext.Default via TypeInfoResolverChain. Minor CORS formatting changes only.
Exception handling type update
.../Server/Boilerplate.Server.Api/Services/ServerExceptionHandler.cs
Switched from ProblemDetails to AppProblemDetails in handler signatures and instances. Public method now returns AppProblemDetails?. Serialization still uses ProblemDetails type info. Control flow unchanged.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  actor User
  participant Server Controller
  participant SignalR Hub
  participant Client (AppClientCoordinator)
  participant Notification UI

  User->>Server Controller: Trigger action
  Server Controller->>SignalR Hub: SendAsync("SHOW_MESSAGE", title, data: Dictionary<string,string?>, requireAction)
  Note right of SignalR Hub: Payload uses source-generated JSON contexts

  SignalR Hub-->>Client (AppClientCoordinator): SHOW_MESSAGE(title, Dictionary, bool)
  Client (AppClientCoordinator)->>Notification UI: Show(title, data["pageUrl"], data["action"])
  Notification UI-->>Client (AppClientCoordinator): success: bool

  alt success
    Client (AppClientCoordinator)-->>SignalR Hub: return true
  else failure
    Client (AppClientCoordinator)->>Notification UI: Show(title) // fallback
    Client (AppClientCoordinator)-->>SignalR Hub: return false
  end
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Poem

I thump my paws—new signals fly,
A dictionary’s how we try.
The hub now speaks with typed delight,
Source-gen stars that guide the night.
When errors hop, details bloom,
AppProblem tales dispel the gloom.
Carrots up—deploy goes zoom! 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (2 warnings)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning Most edits target SignalR serialization, but the change in src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Services/ServerExceptionHandler.cs alters a public API return type from ProblemDetails to AppProblemDetails (including the public Handle signature), which is unrelated to enabling System.Text.Json source generators and constitutes a breaking public API change that requires justification or separation. Either revert the ServerExceptionHandler public signature change or move it into a dedicated PR with rationale, compatibility notes/changelog, and updates to callers and tests if the change must be retained.
Docstring Coverage ⚠️ Warning Docstring coverage is 57.14% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The PR title "Use system text json source generators in boilerplate SignalR (#11406)" concisely and accurately describes the primary change—enabling System.Text.Json source generators for SignalR in the boilerplate—and directly matches the changes in Program.Services.cs and related SignalR payload adaptations.
Linked Issues Check ✅ Passed The PR implements source-generated JSON support for SignalR by building JsonSerializerOptions from AppJsonContext.Default, adding IdentityJsonContext.Default and ServerJsonContext.Default to the TypeInfoResolverChain, and assigning that chain to SignalR's PayloadSerializerOptions in Program.Services.cs, and the related controller and client payload adjustments align message shapes to use the generated contexts, which satisfies the objective of issue #11406.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Please see the documentation for more information.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.


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

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
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 implements System.Text.Json source generators in the boilerplate's SignalR configuration to improve serialization performance and enable trimming support. The changes replace anonymous objects with strongly typed alternatives and configure SignalR to use the project's JSON source generators.

Key changes:

  • Configure SignalR to use System.Text.Json source generators through JsonProtocol
  • Replace anonymous objects in SignalR calls with Dictionary<string, string?> for better serialization
  • Update exception handling to use AppProblemDetails instead of ProblemDetails
  • Add explicit mapping for User objects in SignalR messages

Reviewed Changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
Program.Services.cs Configures SignalR with JSON source generators using TypeInfoResolverChain
ServerExceptionHandler.cs Updates return types from ProblemDetails to AppProblemDetails
RoleManagementController.cs Replaces anonymous object with Dictionary in SignalR call
DiagnosticsController.cs Replaces anonymous object with Dictionary in SignalR call
AttachmentController.cs Adds explicit mapping for User object in SignalR message
AppClientCoordinator.cs Updates SignalR event handler to expect Dictionary instead of object

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: 1

🧹 Nitpick comments (2)
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Services/ServerExceptionHandler.cs (1)

146-157: Consistent concrete type for problem details.

Constructing new AppProblemDetails { ... } is consistent with the type change. Note: the earlier if (instance is null || traceIdentifier is null) problemDetails = null; becomes a no‑op as this assignment overwrites it; if the intent was “no body when missing context,” consider guarding this block.

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Program.Services.cs (1)

231-241: Simplify SignalR JSON resolver wiring; avoid temp options.

No functional issue, but you can add resolvers directly without the temporary jsonOptions and foreach.

Apply this diff:

-        }).AddJsonProtocol(options =>
-        {
-            JsonSerializerOptions jsonOptions = new JsonSerializerOptions(AppJsonContext.Default.Options);
-            jsonOptions.TypeInfoResolverChain.Add(IdentityJsonContext.Default);
-            jsonOptions.TypeInfoResolverChain.Add(ServerJsonContext.Default);
-
-            foreach (var chain in jsonOptions.TypeInfoResolverChain)
-            {
-                options.PayloadSerializerOptions.TypeInfoResolverChain.Add(chain);
-            }
-        });
+        }).AddJsonProtocol(options =>
+        {
+            options.PayloadSerializerOptions.TypeInfoResolverChain.AddRange([
+                AppJsonContext.Default,
+                IdentityJsonContext.Default,
+                ServerJsonContext.Default
+            ]);
+        });

Optionally, also align naming policies for SignalR payloads with controllers:

options.PayloadSerializerOptions.PropertyNamingPolicy = JsonNamingPolicy.CamelCase;
options.PayloadSerializerOptions.DictionaryKeyPolicy = JsonNamingPolicy.CamelCase;
📜 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 dbb789a and 0e47429.

📒 Files selected for processing (6)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/AppClientCoordinator.cs (1 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Controllers/AttachmentController.cs (1 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Controllers/Diagnostics/DiagnosticsController.cs (1 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Controllers/Identity/RoleManagementController.cs (1 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Program.Services.cs (2 hunks)
  • src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Services/ServerExceptionHandler.cs (3 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
🔇 Additional comments (7)
src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Controllers/Diagnostics/DiagnosticsController.cs (1)

62-66: SHOW_MESSAGE payload standardized to dictionary — looks good.

The move to Dictionary<string,string?> matches the client On<string, Dictionary<string,string?>?, bool> signature and stays friendly to STJ source gen. No issues spotted.

src/Templates/Boilerplate/Bit.Boilerplate/src/Client/Boilerplate.Client.Core/Components/AppClientCoordinator.cs (1)

180-211: Client handler generic types aligned with server — nice.

On<string, Dictionary<string,string?>?, bool> matches server InvokeAsync<bool> and enables typed payloads. The fallback returning false when data != null is a sensible signal.

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Controllers/Identity/RoleManagementController.cs (2)

229-231: SignalR payload refactor to dictionary — aligned.

Using { "pageUrl": dto.PageUrl } keeps parity with the client’s typed handler for SHOW_MESSAGE. Looks good.


234-239: Push filter parameters clarified — LGTM.

Named args improve readability. The role‑based customSubscriptionFilter is clear; keep an eye on null‑forgiving operators if model shapes change.

Consider adding a null‑safe predicate to avoid relying on ! if feasible in the push layer.

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Program.Services.cs (1)

181-183: CORS exposed headers: formatting only.

No behavioral change detected.

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Controllers/AttachmentController.cs (1)

106-106: Good switch to DTO for SignalR payload — UserDto is source‑generated; confirm SignalR registration

IdentityJsonContext declares [JsonSerializable(typeof(UserDto))] (src/Templates/Boilerplate/Bit.Boilerplate/src/Shared/Dtos/IdentityJsonContext.cs). Ensure that this JsonSerializerContext is configured for SignalR's JSON protocol (i.e., the JsonContext/TypeInfoResolver used by AddSignalR().AddJsonProtocol or equivalent).

src/Templates/Boilerplate/Bit.Boilerplate/src/Server/Boilerplate.Server.Api/Services/ServerExceptionHandler.cs (1)

173-178: Public API now returns AppProblemDetails — OK.

Signature change is coherent. Repo search shows the class-level call sites; only SignalR/AppHub.Chatbot.cs captures the returned value (var problemDetails = serverExceptionHandler.Handle(exp)); other callers invoke via IExceptionHandler or ignore the return. Compile-time will catch any remaining mismatches.

@ysmoradi ysmoradi merged commit 05884a9 into bitfoundation:develop Sep 16, 2025
3 checks passed
@ysmoradi ysmoradi deleted the 11406 branch September 16, 2025 15:05
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.

bit Boilerplate SignalR server is not using System.Text.Json.SourceGenerators

1 participant