Skip to content

fix(Editor): not throw exception when call reset method#659

Merged
ArgoZhang merged 5 commits intomasterfrom
feat-summoernote
Nov 8, 2025
Merged

fix(Editor): not throw exception when call reset method#659
ArgoZhang merged 5 commits intomasterfrom
feat-summoernote

Conversation

@ArgoZhang
Copy link
Copy Markdown
Member

@ArgoZhang ArgoZhang commented Nov 8, 2025

Link issues

fixes #658

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

Improve Editor component by guarding against uninitialized reset operations, streamlining value update logic, and enhancing CSS class handling and validation styling.

Bug Fixes:

  • Prevent reset method from throwing when the editor instance is not initialized.

Enhancements:

  • Introduce ClassString property for dynamic CSS classes and apply it to the root editor element.
  • Refactor Update method to assign CurrentValue synchronously and remove redundant async delegate invocations.
  • Add CSS rules for valid and invalid editor states to display appropriate border colors.

Copilot AI review requested due to automatic review settings November 8, 2025 01:41
@bb-auto bb-auto Bot added the bug Something isn't working label Nov 8, 2025
@bb-auto bb-auto Bot added this to the v9.2.0 milestone Nov 8, 2025
@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Nov 8, 2025

Reviewer's Guide

This PR fixes the reset exception by guarding against uninitialized editor, refactors the Update method to be synchronous and simpler, introduces a dynamic CSS class builder for the root element, and adds validation border styles to the editor component.

Class diagram for updated Editor component

classDiagram
class Editor {
  - string? ClassString
  + void Update(string value)
  - string? CssClass
  - string? ValidCss
  - string CurrentValue
  - string _lastValue
}
Loading

Class diagram for dynamic CSS class builder usage

classDiagram
class Editor {
  - string? ClassString
}
class CssBuilder {
  + static Default(string)
  + AddClass(string)
  + Build()
}
Editor --> CssBuilder : uses
Loading

Flow diagram for reset method exception handling

flowchart TD
    A["reset(id) called"] --> B["Get editor from Data"]
    B --> C{"editor.$editor exists?"}
    C -- No --> D["Return (do nothing)"]
    C -- Yes --> E["Continue with reset logic"]
Loading

Flow diagram for validation border style application

flowchart TD
    A["Editor state changes"] --> B{"Is editor valid?"}
    B -- Yes --> C["Apply .editor.is-valid border style"]
    B -- No --> D["Apply .editor.is-invalid border style"]
    B -- Neither --> E["No border style applied"]
Loading

File-Level Changes

Change Details Files
Make Update method synchronous and simplify state updates
  • Changed Update signature from async Task to void
  • Replaced Value assignments and event invocations with CurrentValue assignment
  • Updated _lastValue assignment to use the new value
src/components/BootstrapBlazor.SummerNote/Components/Editor/Editor.razor.cs
Prevent exceptions in reset by adding guard for uninitialized editor
  • Added semicolon after Data.get(id) call
  • Added if (!editor.$editor) return check before accessing context
src/components/BootstrapBlazor.SummerNote/Components/Editor/Editor.razor.js
Introduce dynamic CSS class builder and apply to root element
  • Added private ClassString property using CssBuilder
  • Updated root div class attribute to use ClassString instead of static class
src/components/BootstrapBlazor.SummerNote/Components/Editor/Editor.razor.cs
src/components/BootstrapBlazor.SummerNote/Components/Editor/Editor.razor
Add validation border styles for editor
  • Added CSS rules for .editor.is-invalid to apply danger border
  • Added CSS rules for .editor.is-valid to apply success border
src/components/BootstrapBlazor.SummerNote/wwwroot/css/editor.css

Assessment against linked issues

Issue Objective Addressed Explanation
#658 Prevent the Editor component from throwing an exception when the reset method is called.

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

@ArgoZhang ArgoZhang merged commit 036dbd7 into master Nov 8, 2025
3 of 4 checks passed
@ArgoZhang ArgoZhang deleted the feat-summoernote branch November 8, 2025 01:41
Copy link
Copy Markdown

@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 there - I've reviewed your changes - here's some feedback:

  • Changing the JSInvokable Update method from Task to void may break JSInterop conventions—consider returning a Task even if the implementation is synchronous.
  • Removing the ValueChanged and OnValueChanged invocations suppresses all external change notifications—reintroduce the callbacks or hook into CurrentValueChanged to propagate updates.
  • In the reset JS function, also guard against Data.get(id) returning null or undefined before checking editor.$editor to fully prevent runtime errors.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Changing the JSInvokable Update method from Task to void may break JSInterop conventions—consider returning a Task even if the implementation is synchronous.
- Removing the ValueChanged and OnValueChanged invocations suppresses all external change notifications—reintroduce the callbacks or hook into CurrentValueChanged to propagate updates.
- In the reset JS function, also guard against Data.get(id) returning null or undefined before checking editor.$editor to fully prevent runtime errors.

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.

Copy link
Copy Markdown

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 pull request enhances the Editor component by adding form validation styling support and improving the value change handling mechanism.

  • Integrated Bootstrap validation classes (.is-invalid and .is-valid) to provide visual feedback for validation states
  • Refactored the Update method to use CurrentValue property, leveraging the ValidateBase<T> base class functionality
  • Added defensive null checking in the JavaScript reset function to prevent potential runtime errors

Reviewed Changes

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

Show a summary per file
File Description
wwwroot/css/editor.css Added CSS rules for validation states (.is-invalid and .is-valid) and removed BOM character
Components/Editor/Editor.razor.js Added null check in reset function for editor.$editor and removed BOM character
Components/Editor/Editor.razor.cs Added ClassString property for dynamic CSS classes and simplified Update method to use CurrentValue
Components/Editor/Editor.razor Changed hardcoded class to use dynamic ClassString property
BootstrapBlazor.SummerNote.csproj Bumped version from 9.0.8 to 9.0.9

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

Comment on lines +189 to 193
public void Update(string value)
{
Value = value;
_lastValue = Value;

if (ValueChanged.HasDelegate)
{
await ValueChanged.InvokeAsync(Value);
}

if (OnValueChanged != null)
{
await OnValueChanged.Invoke(value);
}
CurrentValue = value;
_lastValue = value;
}
Copy link

Copilot AI Nov 8, 2025

Choose a reason for hiding this comment

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

The refactoring to use CurrentValue instead of manually invoking ValueChanged is correct for a component inheriting from ValidateBase<T>. However, the previous implementation also supported an OnValueChanged callback (visible in the removed code), which is referenced in the test file at test/UnitTestEditor/EditorTest.cs:28. If OnValueChanged was a public parameter that has been removed, this is a breaking API change. Either:

  1. The test needs to be updated to remove OnValueChanged usage, or
  2. The OnValueChanged parameter needs to be retained for backwards compatibility.

Additionally, consider keeping the method signature as async Task and returning Task.CompletedTask for better semantic clarity with the JavaScript invokeMethodAsync call, though void methods are technically supported.

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(Editor): throw exception call reset

2 participants