docs(toolkit): unwrap updatePost mutation in Part 8 edit form example - #4918
trinadhkoya wants to merge 1 commit into
Conversation
The EditPostForm example in Part 8 awaited the updatePost mutation without calling .unwrap(), so a failed request would not be caught and the form would navigate away as if the edit had succeeded. Part 7 already teaches calling .unwrap() inside a try/catch to surface request errors; mirror that pattern here so the tutorial handles errors consistently across both forms. Closes reduxjs#4577
✅ Deploy Preview for redux-docs ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
|
Hi @timdorr — small docs-only change (unwraps the |
updatePost mutation in Part 8 edit form example
commit: |
aryaemami59
left a comment
There was a problem hiding this comment.
Seems like this was already attempted at #4578, which was closed unmerged for the reasons highlighted here, as well as a more thorough explanation posted here.
Worth noting they aren't identical though. #4578 only appended .unwrap() by itself, and one of the objections was that unwrapping without handling the rejection ends up logging unhandled promise rejections, which the try/catch here does address. What still seems to apply is that leaving out .unwrap() is a deliberate call site choice, and Part 8 might be demonstrating exactly that. Also the fallback mentioned in the description (.unwrap() without the try/catch) is pretty much the exact shape that already got declined.
|
Thanks for digging up the history, @aryaemami59 — I hadn't seen #4578, Mark's note there, or @EskiMojo14's explanation on #4577. First, let me withdraw the fallback I offered in the description: appending On the objection that still applies: I agree that leaving out So I see two ways to resolve this, and I'm happy with either:
Happy to rework this PR into option 2 if that's the direction you and @markerikson prefer. |
Checklist
semi: false,singleQuote: true) and match the existing Part 7 example. I intentionally did not run Prettier across the whole file —master's copy of this page already has pre-existing formatting deviations, so a full reformat would balloon the diff well beyond this focused fix (per CONTRIBUTING: "try to keep your pull request focused in scope").What docs page needs to be fixed?
docs/tutorials/essentials/part-8-rtk-query-advanced.md)What is the problem?
In the
EditPostFormexample, theupdatePostmutation is awaited without calling.unwrap():This is inconsistent with what the tutorial teaches. Part 7 explicitly explains that the mutation trigger returns "a special Promise with a
.unwrap()method" that youawaitinside atry/catchto handle request errors, and theAddPostFormexample there does exactly that. As written, the Part 8 edit example swallows a failed request and navigates away as if the edit succeeded.What changes does this PR make to fix the problem?
Mirrors the Part 7 pattern in the Part 8
EditPostFormexample — wraps the call intry/catch, adds.unwrap(), navigates only on success, and logs on failure:This keeps error handling consistent across both the add and edit forms in the Essentials tutorial. If maintainers prefer the more minimal change of only appending
.unwrap()(without the surroundingtry/catch), I'm happy to adjust.