Skip to content

React migration Phase 5: user profile - #870

Closed
vibhaseshadri-cognition wants to merge 2 commits into
devin/1791295336-react-phase4-item-detailsfrom
devin/1791295373-react-phase5-user
Closed

vibhaseshadri-cognition wants to merge 2 commits into
devin/1791295336-react-phase4-item-detailsfrom
devin/1791295373-react-phase5-user

Conversation

@vibhaseshadri-cognition

Copy link
Copy Markdown

Summary

Ports src/app/user/user.component.* to react/src/user/UserProfile.tsx (+ UserProfile.scss), replacing the Phase 2 placeholder. Stacked on Phase 2 (#867). Only touches react/src/user/**, react/e2e/user.spec.ts, react/e2e/fixtures/user.ts.

  • id from useParams() → fetchUser(id, signal); the effect aborts on id change/unmount and ignores AbortError/aborted rejections. State is tagged with the id it belongs to, so a stale result is never shown while the next id is loading.
  • Renders Loader → ErrorMessage("Could not load user {id}.") → .profile with the same markup/classes as Angular (.item-header.mobile .title-block .back-button, .main-details .name/.right/.age, .other-details via SafeHtml as="p" only when about is set).
  • Root <div className="main-content" data-testid="user-profile" data-user-id> is rendered in every state (keeps App.test.tsx / shell.spec.ts green).
  • SCSS ported under .profile (no view encapsulation): :host >>> pre → .profile pre; the two duplicate mobile .main-details blocks merged.

Parity notes / intentional deviations

  • Back button: still a <span class="back-button"> (keeps the theme CSS working), but now has role="button", tabIndex=0, aria-label="Go back", Enter/Space via the existing onActivateKey helper, and cursor: pointer. Calls navigate(-1) (same as Location.back()).
  • On id change Angular kept showing the previous user until the new one arrived (and kept a stale errorMessage). The React version shows the loader instead and aborts the old request.
  • The User model wasn't changed (it's shared): live node-hnapi returns created_time, while the model keeps Angular's crated_time typo. The component only reads id, created, karma, about.
  • E2E "navigate to a user from the feed": the Phase 3 feed list isn't on this base yet, so the spec clicks a[href="/user/dhouston"] if the feed renders one and otherwise falls back to an in-app history.pushState + popstate navigation 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.
  • The live /user/<id> endpoint returns an HTML 404, so unit and e2e tests mock it (vi.mock / mockHnApi).

Tests

  • Unit (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 (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.
  • Locally all of these pass: format:check, lint, typecheck, test (86 tests, 100% overall), build, e2e (15 passed).
File               | % Stmts | % Branch | % Funcs | % Lines
 src/user          |     100 |      100 |     100 |     100
  UserProfile.tsx  |     100 |      100 |     100 |     100

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

@devin-ai-integration

Copy link
Copy Markdown

I'll fix CI failures and address comments from users with write access. I'll skip comments containing "(aside)".

  • Disable automatic comment, CI, and merge conflict monitoring

@devin-ai-integration
devin-ai-integration Bot force-pushed the devin/1791295373-react-phase5-user branch from 7757633 to 3c494cd Compare October 6, 2026 14:10
@devin-ai-integration
devin-ai-integration Bot changed the base branch from devin/1791294931-react-phase2-shell to devin/1791295336-react-phase4-item-details October 6, 2026 14:10
devin-ai-integration Bot and others added 2 commits October 6, 2026 14:54
Co-Authored-By: Vibha  Seshadri <vibha.seshadri@cognition.ai>
…profile (migration phase 5)

Co-Authored-By: Vibha  Seshadri <vibha.seshadri@cognition.ai>
@devin-ai-integration
devin-ai-integration Bot force-pushed the devin/1791295336-react-phase4-item-details branch from f24934d to 44b2dd9 Compare October 6, 2026 14:54
@devin-ai-integration
devin-ai-integration Bot force-pushed the devin/1791295373-react-phase5-user branch from 3c494cd to 6dbadd5 Compare October 6, 2026 14:54

@devin-ai-integration devin-ai-integration Bot 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.

Devin Review found 1 potential issue.

1 flag not posted on this PR by your GitHub settings — view it in Devin Review. (Configure)

Devin Review

useEffect(() => {
const controller = new AbortController();
fetchUser(id, controller.signal).then(
(user) => setState({ id, user }),

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 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.

Suggested change
(user) => setState({ id, user }),
(user) => {
if (!controller.signal.aborted) {
setState({ id, user });
}
},

Devin Review


Was this helpful? React with 👍 or 👎 to provide feedback.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@devin-ai-integration

Copy link
Copy Markdown

Closing as part of the nightly demo-repo reset — reopen if this demo artifact is still needed.

@devin-ai-integration
devin-ai-integration Bot deleted the devin/1791295373-react-phase5-user branch October 26, 2026 12:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant