fix(Editor): not throw exception when call reset method#659
fix(Editor): not throw exception when call reset method#659
Conversation
Reviewer's GuideThis 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 componentclassDiagram
class Editor {
- string? ClassString
+ void Update(string value)
- string? CssClass
- string? ValidCss
- string CurrentValue
- string _lastValue
}
Class diagram for dynamic CSS class builder usageclassDiagram
class Editor {
- string? ClassString
}
class CssBuilder {
+ static Default(string)
+ AddClass(string)
+ Build()
}
Editor --> CssBuilder : uses
Flow diagram for reset method exception handlingflowchart 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"]
Flow diagram for validation border style applicationflowchart 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"]
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
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.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
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-invalidand.is-valid) to provide visual feedback for validation states - Refactored the
Updatemethod to useCurrentValueproperty, leveraging theValidateBase<T>base class functionality - Added defensive null checking in the JavaScript
resetfunction 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.
| 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; | ||
| } |
There was a problem hiding this comment.
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:
- The test needs to be updated to remove
OnValueChangedusage, or - The
OnValueChangedparameter 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.
Link issues
fixes #658
Summary By Copilot
Regression?
Risk
Verification
Packaging changes reviewed?
☑️ Self Check before Merge
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:
Enhancements: