fix(ui): refresh Edit page loading state on post-ID changes#310
Conversation
🏗️ PR Added to Squad Triage QueueThis PR has been labeled with Next steps:
|
76d5e60 to
e18b851
Compare
There was a problem hiding this comment.
Pull request overview
This PR updates the Blazor Blog Post Edit page to avoid getting stuck in a “Loading...” state (especially in bUnit) and adds regression tests for not-found and in-place route parameter changes.
Changes:
- Introduced a dedicated
_isLoadingflag and updated the UI to render “Loading...” based on that flag (withrole="status"for accessibility). - Ensured
_isLoadingis cleared viatry/finallyeven whenNavigateTo("/blog")returns early. - Added bUnit coverage for redirect-on-not-found and switching post IDs within the same component instance.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/Web/Features/BlogPosts/Edit/Edit.razor |
Adds _isLoading and refactors parameter-loading logic to prevent indefinite loading on early redirects. |
tests/Web.Tests.Bunit/Features/EditAclTests.cs |
Adds regression tests for not-found redirect and post-ID parameter switching. |
.squad/agents/legolas/history.md |
Documents the issue and the approach used to fix loading-state behavior. |
| _isLoading = true; | ||
| try | ||
| { | ||
| if (result.Value is not null) | ||
| var result = await Sender.Send(new GetBlogPostByIdQuery(Id)); | ||
| if (result.Success) | ||
| { | ||
| var authState = await AuthStateProvider.GetAuthenticationStateAsync(); | ||
| var user = authState.User; | ||
| _callerUserId = user.FindFirst("sub")?.Value ?? string.Empty; | ||
| _callerIsAdmin = user.IsInRole("Admin"); | ||
| var isAuthor = result.Value.AuthorId == _callerUserId; | ||
| if (result.Value is not null) | ||
| { | ||
| var authState = await AuthStateProvider.GetAuthenticationStateAsync(); | ||
| var user = authState.User; | ||
| _callerUserId = user.FindFirst("sub")?.Value ?? string.Empty; | ||
| _callerIsAdmin = user.IsInRole("Admin"); | ||
| var isAuthor = result.Value.AuthorId == _callerUserId; | ||
|
|
||
| if (!_callerIsAdmin && !isAuthor) | ||
| { | ||
| Navigation.NavigateTo("/blog"); | ||
| return; | ||
| } | ||
|
|
||
| if (!_callerIsAdmin && !isAuthor) | ||
| _model = new PostFormModel { Title = result.Value.Title, Content = result.Value.Content }; | ||
| } | ||
| else | ||
| { | ||
| Navigation.NavigateTo("/blog"); | ||
| return; | ||
| } | ||
|
|
||
| _model = new PostFormModel { Title = result.Value.Title, Content = result.Value.Content }; | ||
| } | ||
| else | ||
| { | ||
| _model = null; | ||
| _error = result.Error; | ||
| } |
Aragorn — CHANGES_REQUESTEDPre-Review Gate Failures (2 hard blocks)1. Merge Conflict — 2. Test CI Did Not Run — No build/unit/bUnit/architecture checks in the status rollup. Only Dependabot admin jobs appear. Until the full test suite CI runs green, we cannot verify no regressions. Copilot-Flagged Bug (must fix)Copilot inline comment on
Concrete regression: If post A loads successfully (sets Required fix at the top of _isLoading = true;
_model = null;
_error = null;
_concurrencyError = false;A regression test should also cover: param change → error response → verify no stale form is shown. What is Good
Routed to Legolas (UI domain) to apply the stale-state reset fix after rebasing. |
- reset loading state at parameter changes so route updates fetch and render correctly - add bUnit coverage for post ID parameter switch regression Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…eter changes Before this fix, OnParametersSetAsync only reset _isLoading. If a first load succeeded (populating _model), then a second route-parameter change triggered a fetch that failed or returned null, the old _model data remained visible alongside the new error message. Changes: - Edit.razor: add _model = null, _error = null, _concurrencyError = false at the top of OnParametersSetAsync so all display state is clean before every fetch cycle - EditAclTests: add two regression tests covering the stale-content paths: • EditClearsStaleContentOnErrorAfterSuccessfulLoad • EditClearsStaleContentOnNullAfterSuccessfulLoad All 92 bUnit tests pass (was 90 before). Gate 4 fully green. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
e18b851 to
1c9ebfa
Compare
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #310 +/- ##
==========================================
+ Coverage 83.46% 83.67% +0.21%
==========================================
Files 47 47
Lines 1252 1256 +4
Branches 152 152
==========================================
+ Hits 1045 1051 +6
+ Misses 147 146 -1
+ Partials 60 59 -1
🚀 New features to boost your workflow:
|
Closes #307\n\nWorking as ralph (Meta).\n\n## Summary\n- reset the Edit page loading flag whenever route parameters change\n- prevent stale previous-post content from persisting across post-ID navigation\n- add bUnit regression coverage for switching IDs in the same component instance