fix(examples): surface errors from useAsyncCallback in examples/base#261
fix(examples): surface errors from useAsyncCallback in examples/base#261
Conversation
Agent-Logs-Url: https://github.com/forwardsoftware/react-auth/sessions/848c6a14-640a-4fb5-8f04-f3f09fbbedf8 Co-authored-by: panz3r <1754457+panz3r@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
This PR improves the examples/base demo UX by surfacing async action failures (login/refresh/logout) instead of leaving errors silent, and by exposing that error state from the local useAsyncCallback hook.
Changes:
- Extend the local
useAsyncCallbackhook to track/reset anerrorstate and return it as a third tuple element. - Update the
Contentcomponent to destructure and conditionally renderloginError,refreshError, andlogoutError.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot please have a look at the review comments and apply fixes that looks most appropriate/correct |
…yncCallback Agent-Logs-Url: https://github.com/forwardsoftware/react-auth/sessions/7c5e293b-c00b-42f6-bdca-56b3c09b79bf Co-authored-by: panz3r <1754457+panz3r@users.noreply.github.com>
…ping, fix unreachable setState Agent-Logs-Url: https://github.com/forwardsoftware/react-auth/sessions/7e291b86-a295-4acd-967f-d5249adc4d40 Co-authored-by: panz3r <1754457+panz3r@users.noreply.github.com>
Done in f2d184d. Applied all three remaining review fixes:
|
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 1 out of 1 changed files in this pull request and generated 3 comments.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Affected Package(s)
Related Issue(s)
Motivation
useAsyncCallbackinexamples/basehad no error handling: a rejected callback left the UI permanently stuck in a loading state with no feedback and the error silently swallowed.Description of Changes
useAsyncCallbackhook: Addedcatch (err)block to capture errors from async callbacks. Replaced two separateuseStatecalls (isLoadinganderror) with a singleAsyncCallbackStateobject ({ isLoading: boolean; error: unknown }), so that starting a new invocation atomically setsisLoading: trueand resetserror: nullin a single render pass. Return type changed from[T, boolean]to[(...args: Parameters<T>) => Promise<unknown>, boolean, unknown], removing the unsafeas Tcast and usingParameters<T>to preserve argument types without a type assertion. Control flow restructured so the success path explicitly callssetStatebefore returning the result, and the catch path callssetStateand falls off naturally — eliminating previously unreachable code.Contentcomponent: Destructures the third element (loginError,refreshError,logoutError) and renders them conditionally with safe message extraction androle="alert"for screen reader accessibility:Breaking Changes
None
How to Test
Vitest) and build steps pass successfully on this PR.cd examples/base && npm install && npm run devAuthClientwhoseonLoginrejects — confirm the error message renders and the button is re-enabled immediately.Checklist
Notes for Reviewers
No tests added —
examples/has no test infrastructure and is documentation/demo only. The fix is a self-contained change to a single file with no impact on published packages.