Repository navigation
React migration Phase 5: user profile - #870
vibhaseshadri-cognition wants to merge 2 commits into
Conversation
|
I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".
|
7757633 to
3c494cd
Compare
Co-Authored-By: Vibha Seshadri <vibha.seshadri@cognition.ai>
…profile (migration phase 5) Co-Authored-By: Vibha Seshadri <vibha.seshadri@cognition.ai>
f24934d to
44b2dd9
Compare
3c494cd to
6dbadd5
Compare
There was a problem hiding this comment.
Devin Review found 1 potential issue.
1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)
| useEffect(() => { | ||
| const controller = new AbortController(); | ||
| fetchUser(id, controller.signal).then( | ||
| (user) => setState({ id, user }), |
There was a problem hiding this comment.
🟡 Canceled profile response overwrites a later visit
After navigating A → B → A, a late success from fetchUser for the first A can replace the newer profile. state.id matches A again, so the stale response passes the render guard.
Learn more
The component tags fetched state with a user id and displays it only when the route has that id. The effect aborts requests when the id changes, but its success callback does not check the abort signal. A request that resolves after cancellation can therefore update state. If the route has returned to the same id, the render guard accepts that old result, including when a newer request has already completed.
Example: Visit A, then B, then A before the first A response settles. The second A request returns updated karma 200; the canceled first A request then returns karma 100. The profile switches back to 100.
Recommended fix: Check controller.signal.aborted before setting state in the success callback, as the rejection callback already does. Add an A → B → A test that resolves the first A request after the second.
| (user) => setState({ id, user }), | |
| (user) => { | |
| if (!controller.signal.aborted) { | |
| setState({ id, user }); | |
| } | |
| }, |
Was this helpful? React with 👍 or 👎 to provide feedback.
There was a problem hiding this comment.
You're right. The success callback doesn't check controller.signal.aborted, so if you go A → B → A, a late response from the first A request passes the state.id === id guard and overwrites the newer profile. I added a test for exactly that sequence: it fails on the current head and passes once the success callback checks the abort signal, the same way the error callback already does.
The branch owner asked me not to push here again, so the fix (component change plus the new test) is sitting locally and hasn't been pushed. I'm waiting on the owner to either let me push it or apply it themselves.
|
Closing as part of the nightly demo-repo reset — reopen if this demo artifact is still needed. |
Summary
Ports
src/app/user/user.component.*toreact/src/user/UserProfile.tsx(+UserProfile.scss), replacing the Phase 2 placeholder. Stacked on Phase 2 (#867). Only touchesreact/src/user/**,react/e2e/user.spec.ts,react/e2e/fixtures/user.ts.idfromuseParams()→fetchUser(id, signal); the effect aborts on id change/unmount and ignoresAbortError/aborted rejections. State is tagged with the id it belongs to, so a stale result is never shown while the next id is loading.Loader→ErrorMessage("Could not load user {id}.")→.profilewith the same markup/classes as Angular (.item-header.mobile .title-block .back-button,.main-details .name/.right/.age,.other-detailsviaSafeHtml as="p"only whenaboutis set).<div className="main-content" data-testid="user-profile" data-user-id>is rendered in every state (keepsApp.test.tsx/shell.spec.tsgreen)..profile(no view encapsulation)::host >>> pre→.profile pre; the two duplicate mobile.main-detailsblocks merged.Parity notes / intentional deviations
<span class="back-button">(keeps the theme CSS working), but now hasrole="button",tabIndex=0,aria-label="Go back", Enter/Space via the existingonActivateKeyhelper, andcursor: pointer. Callsnavigate(-1)(same asLocation.back()).errorMessage). The React version shows the loader instead and aborts the old request.Usermodel wasn't changed (it's shared): live node-hnapi returnscreated_time, while the model keeps Angular'scrated_timetypo. The component only readsid,created,karma,about.a[href="/user/dhouston"]if the feed renders one and otherwise falls back to an in-apphistory.pushState+popstatenavigation from/news/1. Then it presses the back button with the keyboard and checks it returns to the feed. Once Phase 3 lands, the click path runs automatically./user/<id>endpoint returns an HTML 404, so unit and e2e tests mock it (vi.mock/mockHnApi).Tests
UserProfile.test.tsx, 10 tests): loading, loaded with/without about, sanitization, error text, AbortError ignored, back via click/Enter/Space, id-change abort + refetch + stale response ignored, late rejection after id change ignored, abort on unmount.e2e/user.spec.ts, 5 tests): profile fields + sanitized about (no script execution), no-about, error state, feed → user → back, in-app id change refetch.format:check,lint,typecheck,test(86 tests, 100% overall),build,e2e(15 passed).Devin-Org: engineering
Link to Devin session: https://app.devin.ai/sessions/a2357a06c7274bb18fda4d9401310698
Open in Devin Desktop: https://app.devin.ai/desktop/session/a2357a06c7274bb18fda4d9401310698?variant=devin
Requested by: @vibhaseshadri-cognition