Skip to content

fix(ui): refresh Edit page loading state on post-ID changes#310

Merged
mpaulosky merged 3 commits into
devfrom
squad/307-fix-edit-null-post-redirect
May 12, 2026
Merged

fix(ui): refresh Edit page loading state on post-ID changes#310
mpaulosky merged 3 commits into
devfrom
squad/307-fix-edit-null-post-redirect

Conversation

@mpaulosky

Copy link
Copy Markdown
Owner

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

Copilot AI review requested due to automatic review settings May 12, 2026 00:27
@github-actions github-actions Bot added the squad Squad triage inbox — Lead will assign to a member label May 12, 2026
@github-actions

Copy link
Copy Markdown
Contributor

🏗️ PR Added to Squad Triage Queue

This PR has been labeled with squad and added to the triage queue.

Next steps:

  • The squad Lead will review and assign to an appropriate team member
  • A squad:member label will be added after triage

If you know which squad member should handle this, you can add the appropriate squad:member label yourself.

@mpaulosky
mpaulosky force-pushed the squad/307-fix-edit-null-post-redirect branch from 76d5e60 to e18b851 Compare May 12, 2026 00:30

Copilot AI left a comment

Copy link
Copy Markdown

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 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 _isLoading flag and updated the UI to render “Loading...” based on that flag (with role="status" for accessibility).
  • Ensured _isLoading is cleared via try/finally even when NavigateTo("/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.

Comment on lines +69 to 100
_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;
}
@mpaulosky

Copy link
Copy Markdown
Owner Author

Aragorn — CHANGES_REQUESTED

Pre-Review Gate Failures (2 hard blocks)

1. Merge Conflictmergeable: CONFLICTING / mergeStateStatus: DIRTY
The branch has conflicts with dev. Rebase onto current dev and resolve all conflicts before requesting re-review.

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 Edit.razor line 100 is correct and must be addressed:

OnParametersSetAsync sets _isLoading = true but does NOT reset _model, _error, or _concurrencyError when the route Id changes.

Concrete regression: If post A loads successfully (sets _model), user navigates to post B, and post B load fails (_error set), the old post A form will still render alongside the error banner — because _model is not null and _isLoading is false.

Required fix at the top of OnParametersSetAsync, before the try block:

_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

  • try/finally is the correct Blazor pattern for loading state. ✅
  • role="status" on the loading indicator is a good accessibility addition. ✅
  • New tests (EditRedirectsToBlogWhenPostNotFound, EditShowsNewPostContentAfterParameterChange) cover real gaps. ✅
  • Branch naming, PR template, and issue link (Closes #307) are all correct. ✅

Routed to Legolas (UI domain) to apply the stale-state reset fix after rebasing.
Re-review required once CI is green and conflicts are resolved.

Boromir and others added 3 commits May 11, 2026 17:42
- 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>
@mpaulosky
mpaulosky force-pushed the squad/307-fix-edit-null-post-redirect branch from e18b851 to 1c9ebfa Compare May 12, 2026 00:48
@github-actions

Copy link
Copy Markdown
Contributor

Test Results Summary

365 tests  +3   364 ✅ +3   19s ⏱️ ±0s
  6 suites ±0     1 💤 ±0 
  6 files   ±0     0 ❌ ±0 

Results for commit 1c9ebfa. ± Comparison against base commit 5e176dc.

@codecov

codecov Bot commented May 12, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.67%. Comparing base (5e176dc) to head (1c9ebfa).

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     
Files with missing lines Coverage Δ
src/Web/Features/BlogPosts/Edit/Edit.razor 90.90% <100.00%> (+5.90%) ⬆️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@mpaulosky
mpaulosky merged commit a1ad0c9 into dev May 12, 2026
19 checks passed
@mpaulosky
mpaulosky deleted the squad/307-fix-edit-null-post-redirect branch May 12, 2026 00:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

squad Squad triage inbox — Lead will assign to a member

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix(ui): redirect to /blog when post not found in Edit page (null-value stuck loading)

2 participants