Repository navigation
Conversation
Co-authored-by: Copilot App <[email protected]> Copilot-Session: 0fb5ea3b-44bb-495b-99c5-93e753ca9ce1
Keep the mark-only EditContext operation internal and bridge it from InputBase without raising OnFieldChanged or expanding public API surface. Strengthen repeated-invalid, recovery, model-preservation, and browser coverage. Co-authored-by: Copilot App <[email protected]> Copilot-Session: f88407e7-efcf-44b1-9387-cde2a2557973
There was a problem hiding this comment.
Pull request overview
This pull request adjusts Blazor Forms’ handling of InputBase parse failures so that invalid user input still marks the field as modified (preserving “dirty”/CSS behavior) but does not raise EditContext.OnFieldChanged, avoiding validators running against an unchanged model value (fixing #58407).
Changes:
- Refactors
EditContext.NotifyFieldChangedto delegate modified-state mutation to a new internalMarkAsModifiedhelper. - Updates
InputBase’s parse-failure path to mark the field modified without triggeringOnFieldChanged, while continuing to notify validation-state changes for parsing messages. - Adds unit and E2E coverage for the notification boundary (invalid → valid, valid → invalid, and empty input for nullable required scenarios).
Show a summary per file
| File | Description |
|---|---|
| src/Components/Forms/src/EditContext.cs | Introduces internal MarkAsModified and refactors NotifyFieldChanged to use it before raising OnFieldChanged. |
| src/Components/Web/src/Forms/EditContextAccessor.cs | Adds a narrow UnsafeAccessor bridge so Web can invoke EditContext.MarkAsModified without making it public. |
| src/Components/Web/src/Forms/InputBase.cs | Uses MarkAsModified (via accessor) on parse failure to avoid revalidating unchanged model values. |
| src/Components/Forms/test/EditContextTest.cs | Adds a unit test verifying MarkAsModified updates modified state without raising OnFieldChanged. |
| src/Components/Forms/test/EditContextDataAnnotationsExtensionsTest.cs | Adds a unit test verifying MarkAsModified does not trigger per-property validation. |
| src/Components/Web/test/Forms/InputBaseTest.cs | Expands/introduces unit tests asserting parse failures don’t raise OnFieldChanged and that subsequent valid input resumes normal behavior. |
| src/Components/test/testassets/BasicTestApp/FormsTest/TypicalValidationComponent.razor | Adds a required nullable number field to support the regression E2E scenario. |
| src/Components/test/E2ETest/Tests/FormsTest.cs | Adds E2E regression test ensuring parse failures don’t trigger model validation while preserving modified/invalid UI state. |
Review details
Tip
Add a code-review agent skill for context-aware, tailored reviews. Learn more in the docs.
- Files reviewed: 8/8 changed files
- Comments generated: 0
- Review effort level: Lite
Co-authored-by: Copilot App <[email protected]> Copilot-Session: f88407e7-efcf-44b1-9387-cde2a2557973
|
Looks like this PR hasn't been active for some time and the codebase could have been changed in the meantime. |
PureWeen
left a comment
There was a problem hiding this comment.
Written with GitHub Copilot (AI), with human direction. Posted by PureWeen.
| EditContext.NotifyFieldChanged(FieldIdentifier); | ||
| // The raw input changed, but the model value did not. Track the user interaction | ||
| // without revalidating the unchanged model value. | ||
| EditContext.MarkAsModified(FieldIdentifier); |
There was a problem hiding this comment.
Can we also notify the field when parsing successfully recovers to the same model value? For a [Required] int? that starts null, the sequence null -> "1e+10" -> empty clears the parsing message, but assigning null hits CurrentValue's equality gate and never raises NotifyFieldChanged. The model remains null with no Required message, and the browser renders the field as modified valid.
The current E2E path enters 5 before the final empty value, so it only covers a value-changing recovery. Please add direct null -> invalid -> empty coverage and notify exactly once on successful recovery, while continuing to avoid model validation on the parse failure itself.
|
/review |
Restore field validation after successful parsing even when the model value is unchanged, without invoking ValueChanged or duplicating changed-value notifications. Cover nullable Required and same-value Range recovery through real input binders and Server/WebAssembly browser tests. Co-authored-by: Copilot App <[email protected]>
|
/review This review was created by GitHub Copilot with help from a human. |
kubaflo
left a comment
There was a problem hiding this comment.
Current-head review — e36af28fd03dfa96284aee0739ab1b9bd7c65432
No new high-confidence actionable finding identified in the changed parsing/notification state machine. I traced parse failure, repeated failure, value-changing recovery, same-value recovery, and nullable-empty recovery against CurrentValue's equality gate and the new managed/browser assertions. Failure retains modified state without OnFieldChanged; successful same-value recovery has an explicit notification, while changed values use the existing notification path. The previous failure flag is captured before recovery callbacks.
Prior feedback: The cross-assembly UnsafeAccessor/IvT objection is addressed by the public API/baseline entry; no accessor bridge remains in this diff. The null → invalid → empty recovery finding is addressed in source by the same-value notification and explicit nullable theory row, plus browser coverage. I am not claiming independent green execution or resolving that thread. The alternative #65574 is already disclosed in the description and makes a different modified-state tradeoff, so it is not reported as a new duplicate defect.
Validation and limits: Frozen git diff --check passes. Inspected full changed files, InputBase's surrounding setter, shared form fixture/model constraints, and relevant existing form-test callers. No local Forms/Web build, browser run, or mutation replay was performed; the author's reported passes/AOT results are not independently certified here. The exact head has failed main CI, Helix monitor, CoreCLR/Mono-server E2E, and Build Analysis/Insights checks, alongside successful platform/template/Mono-client-WebAssembly checks. Check summaries alone do not establish cause; raw Azure logs were not analyzed, so failures remain unresolved validation evidence rather than attributed findings.
Scope: GPT-6.1 Sol; no model campaign or visual/browser validation. Public API approval/release readiness was not established; COMMENT only.
| /// Marks the specified field as modified. | ||
| /// </summary> | ||
| /// <param name="fieldIdentifier">Identifies the field whose modification flag should be set.</param> | ||
| public void MarkAsModified(in FieldIdentifier fieldIdentifier) |
There was a problem hiding this comment.
Why this helper method is needed?
kubaflo
left a comment
There was a problem hiding this comment.
Feedback follow-up: the helper has a concrete caller; public API design remains a human decision. No new code revision or new actionable correctness finding.
Revisited the question about why MarkAsModified is needed against the full EditContext/InputBase source at the unchanged head, the PR diff, and all three feedback surfaces.
The method separates two effects currently combined by NotifyFieldChanged: setting the field's modification flag and invoking OnFieldChanged. InputBase.CurrentValueAsString calls only MarkAsModified when parsing fails, so invalid user input keeps dirty/CSS state without notifying validators that the unchanged model value changed. Normal successful changes still call NotifyFieldChanged; successful recovery to the same value has its own explicit notification path. Calling NotifyFieldChanged instead would reintroduce the behavior this PR removes, while removing the parse-failure call altogether would also remove modified-state tracking.
That explains the operation, not automatic acceptance of the proposed public API. The earlier no cross-assembly IvT/UnsafeAccessor feedback explains why this version exposes an operation rather than using a private bridge. Whether EditContext.MarkAsModified(in FieldIdentifier) is the desired public shape, or whether the behavior should instead change, still needs maintainer/API judgment. The existing description already calls out that tradeoff and the alternative implementation.
The previous same-value-recovery finding remains addressed in the inspected source; this comment does not resolve anyone's thread. No tests were rerun for the new question, no browser/visual validation was performed, and author-reported runtime results remain unverified here. Required Build Analysis still reports failure; this feedback-only pass does not classify the CI cause or certify merge readiness.
Direct GPT-6.1 Sol source/feedback reconciliation. Overall safety confidence remains low, matching the prior review's execution/CI limitations. COMMENT only.
Fix
InputBaseparse failures without reporting a model value changeDescription
When
TryParseValueFromStringfails, the raw value in the input changed but the bound model value did not. The existing parse-failure path callsEditContext.NotifyFieldChanged, which does two things:OnFieldChanged, causing validators to run against the unchanged model value.That can produce both the parsing error and an unrelated model-validation error, such as
[Required], even thoughCurrentValue,ValueChanged, and the model were not updated.This change separates those two effects. A parse failure still marks the field modified, preserving the existing dirty-state and CSS behavior, but it no longer raises
OnFieldChanged. Parsing messages continue through the existingNotifyValidationStateChangedflow.Fixes #58407
Design
EditContext.NotifyFieldChangednow delegates its state mutation to a new publicMarkAsModifiedmethod before raisingOnFieldChanged.InputBasecalls onlyMarkAsModifiedwhen parsing fails.The API is symmetric with
MarkAsUnmodified(in FieldIdentifier)and gives custom input implementations a supported way to record user interaction without claiming that the bound model value changed. Forms and Web are separate assemblies, and framework code should not bridge that boundary withInternalsVisibleToorUnsafeAccessor, so the public API is the explicit contract between them.Areas I would especially like reviewed
modified invalidbehavior while suppressing only the value-change notification.EditContext.MarkAsModified(in FieldIdentifier)the right symmetric counterpart toMarkAsUnmodifiedfor this scenario?ValueChangedandOnFieldChangedpath exactly once.[Required]validation.Alternative PR
#65574 addresses the same issue by removing
NotifyFieldChangedfrom the parse-failure branch. That is much smaller, but it also changesEditContext.IsModified(field)fromtruetofalseafter invalid user input.This PR keeps the useful part of the existing behavior, namely modified-state tracking, while removing only the model-value-change notification. The main product decision between these PRs is whether failed input should remain modified, not whether the extra model validation should be suppressed.
Tests
InputBaseTest: 24/24 passed.EditContextTestandEditContextDataAnnotationsExtensionsTest: 43/43 passed.OnFieldChangedevent and passes with this change.