scaffold-frontend-feature
Guide for adding a new feature to the Web Frontend (Blazor), focusing on Reactive State, Optimistic Updates, and Cache Invalidation.
Installation
Suivez les instructions du dépôt pour votre agent. Consultez les fichiers et dépendances avant l’installation.
Voir la source ↗GuidesInstructions
Follow this guide to implement a responsive frontend feature in src/Web/BookStore.Web.
-
Prerequisites
- Ensure the API Client exists:
src/Client/BookStore.Client/I{Resource}Client.cs. - Ensure the Shared/Response DTOs exist in
BookStore.Shared. - if NOT, run
/scaffold-reador/scaffold-writefirst.
- Ensure the API Client exists:
-
Create the Component
- Create/Update
src/Web/BookStore.Web/Components/Pages/{Feature}.razor. -
Template:
templates/Page.razor -
Lifecycle: Use
OnInitializedAsyncto start listening:EventsService.StartListening();.
- Create/Update
-
Implement Data Fetching
-
Pattern: Use
ReactiveQuery<T>. -
Setup (Template):
templates/ReactiveQueryInit.cs
-
Pattern: Use
-
Implement Optimistic Updates (Properties)
- Use Case: Toggling a boolean, changing a number (e.g., Favorites).
-
Pattern:
Mutate -> Call -> Rollback.query.MutateData(s => s with { IsFavorite = true }); // 1. Instant UI update try { await Client.UpdateAsync(); // 2. API Call } catch { query.MutateData(s => s with { IsFavorite = false }); // 3. Revert on error }
-
Implement Optimistic Updates (Lists)
- Use Case: Adding a new item to a list instantly.
-
Pattern:
OptimisticService.AddOptimisticBook(id, title); // 1. Add to separate list await Client.CreateAsync(); // 2. API Call (Event will confirm/remove it) -
UI: Merge
query.DatawithOptimisticService.GetOptimisticBooks()when rendering lists.
-
Configure Invalidation
- Open
src/Web/BookStore.Web/Services/QueryInvalidationService.cs. - Add cases to
GetInvalidationKeys(IDomainEventNotification notification). -
Rule: Map the Domain Event (e.g.,
BookCreated) to the Query Keys you defined in Step 2 (e.g.,"Books").
- Open
-
Verify
- Run the app and verify:
- Data loads.
- Mutations update UI instantly.
- SSE events (from other tabs/users) trigger auto-refetch.
- Run
/verify-featurefor complete verification.
- Run the app and verify:
Related Skills
Prerequisites:
- Backend endpoints must exist first:
-
/scaffold-write- For mutation endpoints -
/scaffold-read- For query endpoints
-
- Client SDK must be configured (usually done by scaffold-write/read)
Next Steps:
-
/scaffold-test- Create integration tests for the feature -
/verify-feature- Complete verification
Debugging:
-
/debug-sse- If real-time updates don't work -
/debug-cache- If query data is stale
See Also:
- real-time-notifications - SSE architecture
- scaffold-write - Backend mutations
- scaffold-read - Backend queries
- Web AGENTS.md - ReactiveQuery patterns and SSE integration
Exemples
Consultez les exemples du dépôt source.
Voir la source ↗Historique source
- Date d’indexation
- 2026-01-20
- Mise à jour de l’index
- 2026-01-26
- Branch
- main
Les dates concernent ce répertoire. Consultez le dépôt pour l’historique du code.
GitHub ↗chat Comments (0)
Sign in to join the discussion and leave a comment.
No comments yet. Be the first to share your thoughts!