Skip to content

feat: Migrate CommentComponent from Angular to React#175

Open
devin-ai-integration[bot] wants to merge 1 commit intomasterfrom
devin/1771204517-migrate-comment-component
Open

feat: Migrate CommentComponent from Angular to React#175
devin-ai-integration[bot] wants to merge 1 commit intomasterfrom
devin/1771204517-migrate-comment-component

Conversation

@devin-ai-integration
Copy link

@devin-ai-integration devin-ai-integration bot commented Feb 16, 2026

feat: Migrate CommentComponent from Angular to React

Summary

Adds a new React version of the Angular CommentComponent under src/components/Comment/. Three files are introduced:

  • Comment.types.tsComment interface and CommentProps type (mirrors the Angular Comment model)
  • Comment.tsx — Functional component using useState for collapse/expand, react-router-dom <Link> for user routing, dangerouslySetInnerHTML for comment content, and recursive self-rendering for nested comments
  • Comment.module.scss — Styles ported from the Angular SCSS, with :host >>> removed and SCSS media variables inlined

The original Angular component files are left untouched.

Review & Testing Checklist for Human

  • Global style leak in SCSS module: The bare a { ... } selector at the top of Comment.module.scss (lines 4–9) is not scoped by CSS Modules (only class selectors get hashed). This will bleed into global styles and should likely be removed or nested inside a scoped class.
  • Null safety on comment.comments: comment.comments.map(...) in Comment.tsx will throw if comments is undefined or null. Angular's *ngFor silently handles this. Consider adding a guard (comment.comments?.map(...) or a fallback).
  • dangerouslySetInnerHTML usage: Direct port of Angular's [innerHTML] binding. Verify upstream API data is sanitized, or consider adding a sanitization step.
  • SCSS variables duplicated: $mobile-only and $tablet-only are redefined inline rather than imported from the shared _media.scss partial. If those shared values ever change, this file will diverge. Consider updating the import path instead.
  • React dependencies not verified: react, react-router-dom, and CSS Module support are assumed available but may not be in the project's package.json or build config. This component has not been rendered or tested — confirm it compiles and renders correctly when integrated.

Suggested test plan: Install React dependencies if missing, import this component into a test harness or existing page, and render it with sample nested comment data (including a deleted comment and deeply nested replies). Verify collapse/expand, user links, and style scoping.

Notes


Open with Devin

- Create Comment.types.ts with Comment interface and CommentProps
- Create Comment.tsx with useState hook, React Router Link, recursive rendering
- Create Comment.module.scss with migrated styles (removed :host >>> selector, inlined SCSS variables)

Co-Authored-By: Jenna Mansueto <jenna.mansueto@cognition.ai>
@devin-ai-integration
Copy link
Author

🤖 Devin AI Engineer

I'll be helping with this pull request! Here's what you should know:

✅ I will automatically:

  • Address comments on this PR. Add '(aside)' to your comment to have me ignore it.
  • Look at CI failures and help fix them

Note: I can only respond to comments from users who have write access to this repository.

⚙️ Control Options:

  • Disable automatic comment and CI monitoring

Copy link
Author

@devin-ai-integration devin-ai-integration bot left a comment

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.

View 3 additional findings in Devin Review.

Open in Devin Review

dangerouslySetInnerHTML={{ __html: comment.content }}
/>
<ul className={styles.subtree}>
{comment.comments.map((subComment) => (
Copy link
Author

Choose a reason for hiding this comment

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

🔴 comment.comments.map() crashes if comments is undefined/null from API

Calling .map() directly on comment.comments at line 36 will throw a TypeError at runtime if the API returns a comment object where comments is undefined or null.

Root Cause

The data comes from an external API (node-hnapi.herokuapp.com), and the TypeScript interface at src/components/Comment/Comment.types.ts:9 declares comments: Comment[] as always present, but this provides no runtime guarantee. If the API ever returns a comment without a comments field (or with null), the call to comment.comments.map(...) will throw:

TypeError: Cannot read properties of undefined (reading 'map')

Notably, the original Angular implementation at src/app/item-details/comment/comment.component.html:11 uses *ngFor="let subComment of comment.comments", which silently handles null/undefined by simply not iterating. The React port loses this safety.

Impact: A single comment with a missing comments field will crash the entire comment tree (and potentially the whole page if there's no error boundary), since React will propagate the error up.

Suggested change
{comment.comments.map((subComment) => (
{(comment.comments || []).map((subComment) => (
Open in Devin Review

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

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.

0 participants