Skip to content

fix: address missing hook dependencies to remove exhaustive-deps disables#447

Closed
narutamaaurum wants to merge 0 commit into
piyushdotcomm:developfrom
narutamaaurum:fix/exhaustive-deps
Closed

fix: address missing hook dependencies to remove exhaustive-deps disables#447
narutamaaurum wants to merge 0 commit into
piyushdotcomm:developfrom
narutamaaurum:fix/exhaustive-deps

Conversation

@narutamaaurum

@narutamaaurum narutamaaurum commented Jun 1, 2026

Copy link
Copy Markdown

Changes

Resolves missing hook dependencies as described in #442.

1. modules/webcontainers/components/terminal.tsx

  • Removed 2 eslint-disable-next-line react-hooks/exhaustive-deps comments
  • Dependencies were already correct — refs (terminalRef, term) don't need to be listed

2. modules/playground/components/playground-editor.tsx

  • Wrapped updateEditorLanguage in React.useCallback with [activeFile] dependency
  • Added updateEditorLanguage to the useEffect dependency array
  • Prevents stale closure and ensures language updates when function identity changes

3. modules/home/code-line.tsx

  • Moved highlight and highlightCode functions outside the component body
  • These functions have no dependency on props/state, so they belong at module scope
  • Eliminates the need for the eslint-disable without changing behavior

Closes #442

Summary by CodeRabbit

  • Refactor

    • Optimized code organization for syntax highlighting implementation.
    • Improved editor language switching with enhanced callback handling.
  • Chores

    • Code cleanup and linting improvements.

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown

Review Change Stack

Walkthrough

This PR addresses missing React hook dependencies across three components by removing // eslint-disable-next-line react-hooks/exhaustive-deps comments and fixing dependencies properly. The code-line component extracts helpers, the playground-editor memoizes its callback, and the terminal effect cleanup confirms safe dependencies.

Changes

Hook Dependencies Refactor

Layer / File(s) Summary
code-line: Extract syntax helpers and simplify component
modules/home/code-line.tsx
highlightCode and highlight helpers extracted to top-level functions; CodeLine component simplified to reference these pure helpers in useEffect without dependency issues or eslint suppressions.
playground-editor: Memoize updateEditorLanguage callback
modules/playground/components/playground-editor.tsx
updateEditorLanguage wrapped in React.useCallback with activeFile dependency; effect updated to include both activeFile and the memoized callback in the dependency array.
terminal: Remove unnecessary eslint suppressions
modules/webcontainers/components/terminal.tsx
Two eslint-disable-next-line react-hooks/exhaustive-deps comments removed from initialization and cleanup effects; terminal setup and process cleanup behavior unchanged.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

Suggested labels

type:refactor, type:bug, quality:exceptional

Suggested reviewers

  • piyushdotcomm
  • Maxd646

Poem

🐰 Dependencies now flow so clean,
No more eslint tricks between,
Callbacks memoized, helpers extracted right,
Three components shining bright! ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly and specifically describes the main change: addressing missing hook dependencies and removing exhaustive-deps eslint disables.
Description check ✅ Passed The description follows the template structure with a clear summary, lists specific changes with explanations, and references the related issue #442.
Linked Issues check ✅ Passed All coding objectives from issue #442 are met: eslint-disable comments removed, React.useCallback applied where needed, and functions moved to module scope to address stale closures and missing dependencies.
Out of Scope Changes check ✅ Passed All changes are directly related to addressing the missing hook dependencies and removing eslint suppressions as specified in issue #442, with no out-of-scope modifications.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown

👋 Thanks for opening a PR, @narutamaaurum!

Your PR has entered the 🚦 PR Review Pipeline.

Standard PR detected — your PR will follow the standard review pipeline.


What happens next

Stage Reviewer Checks
Stage 1 — Automated Validation 🤖 Bot DCO · Format · AI/Slop · Duplicate
Stage 2 — Human Review 👥 Maintainer Code + Quality Review
Stage 3 — PA / Maintainer Review 🔑 Project Admin Final Merge Decision

A pipeline status comment will appear below and update automatically as your PR progresses.


While you wait

  • Sign all commits (git commit -s)
  • Link your issue (Closes #123)
  • Use a feature branch (not main)
  • Avoid unrelated changes

This comment is posted only once.

@qodo-code-review

Copy link
Copy Markdown

Review Summary by Qodo

Fix missing React hook dependencies and remove eslint-disable comments

🐞 Bug fix

Grey Divider

Walkthroughs

Description
• Remove eslint-disable comments by fixing missing hook dependencies
• Wrap updateEditorLanguage in React.useCallback with proper dependencies
• Move highlight and highlightCode functions to module scope
• Ensure hook dependency arrays are exhaustive and accurate
Diagram
flowchart LR
  A["Identify missing dependencies"] --> B["playground-editor.tsx: useCallback wrapper"]
  A --> C["code-line.tsx: Move functions outside"]
  A --> D["terminal.tsx: Remove unnecessary disables"]
  B --> E["Remove eslint-disable comments"]
  C --> E
  D --> E
  E --> F["Exhaustive-deps compliance"]

Loading

Grey Divider

File Changes

1. modules/home/code-line.tsx 🐞 Bug fix +15/-25

Move highlight functions to module scope

• Moved highlightCode and highlight functions outside component body to module scope
• Removed eslint-disable-next-line react-hooks/exhaustive-deps comment
• Functions have no dependency on component props/state, eliminating need for disable

modules/home/code-line.tsx


2. modules/playground/components/playground-editor.tsx 🐞 Bug fix +3/-4

Wrap updateEditorLanguage in useCallback

• Wrapped updateEditorLanguage function in React.useCallback with [activeFile] dependency
• Added updateEditorLanguage to useEffect dependency array
• Removed eslint-disable-next-line react-hooks/exhaustive-deps comment
• Prevents stale closure and ensures proper function identity tracking

modules/playground/components/playground-editor.tsx


3. modules/webcontainers/components/terminal.tsx 🐞 Bug fix +0/-2

Remove unnecessary eslint-disable comments

• Removed two eslint-disable-next-line react-hooks/exhaustive-deps comments
• Dependencies in useEffect hooks were already correct and complete
• No functional changes needed, only cleanup of unnecessary disables

modules/webcontainers/components/terminal.tsx


Grey Divider

Qodo Logo

@qodo-code-review

qodo-code-review Bot commented Jun 1, 2026

Copy link
Copy Markdown

Code Review by Qodo

🐞 Bugs (1) 📘 Rule violations (2) 📎 Requirement gaps (0)

Context used
✅ Compliance rules (platform): 22 rules

Grey Divider


Action required

1. CodeLine uses dangerouslySetInnerHTML 📘 Rule violation ⛨ Security
Description
CodeLine renders line via dangerouslySetInnerHTML using highlightCode() output that is not
HTML-escaped or sanitized, enabling XSS if line can contain attacker-controlled markup. This can
lead to script execution in the browser.
Code

modules/home/code-line.tsx[R15-19]

Evidence
The checklist requires sanitizing/escaping user-facing rendered output to prevent XSS. The code
injects unescaped HTML via dangerouslySetInnerHTML using transformed code derived directly from
line.

Rule 599987: Sanitize or escape all user-facing rendered output to prevent XSS
modules/home/code-line.tsx[5-20]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`CodeLine` uses `dangerouslySetInnerHTML` with a string produced from raw `line` content without escaping/sanitization, which can enable XSS.

## Issue Context
The component builds HTML strings via `.replace(...)` and injects them with `dangerouslySetInnerHTML`. If `line` ever contains `<`, `>`, event handlers, or tags, they can be interpreted as HTML.

## Fix Focus Areas
- modules/home/code-line.tsx[5-20]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


2. terminal.tsx exceeds 500 lines 📘 Rule violation ⚙ Maintainability
Description
modules/webcontainers/components/terminal.tsx is over the 500-line maximum allowed for source
files. Oversized files reduce maintainability and make review/auditing harder.
Code

modules/webcontainers/components/terminal.tsx[R325-329]

Evidence
The compliance rule limits source files to 500 lines. The file clearly extends beyond line 500
(reaching line 550), demonstrating the violation.

Rule 599989: Limit individual source files to 500 lines maximum
modules/webcontainers/components/terminal.tsx[521-550]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

## Issue description
`modules/webcontainers/components/terminal.tsx` exceeds the 500-line limit and must be refactored into smaller cohesive modules.

## Issue Context
The current file length reaches at least line 550, violating the 500-line cap.

## Fix Focus Areas
- modules/webcontainers/components/terminal.tsx[1-550]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


3. Undefined React reference 🐞 Bug ≡ Correctness
Description
modules/playground/components/playground-editor.tsx now calls React.useCallback but the file does
not import React (nor declares a global React), causing a compile/runtime failure ("React is not
defined"). This breaks PlaygroundEditor rendering/bundling.
Code

modules/playground/components/playground-editor.tsx[R256-259]

Evidence
The file imports only named hooks from react and contains no other React identifier definition,
but it references React.useCallback, so React will be undefined.

modules/playground/components/playground-editor.tsx[3-6]
modules/playground/components/playground-editor.tsx[256-271]

Agent prompt
The issue below was found during a code review. Follow the provided context and guidance below and implement a solution

### Issue description
`React.useCallback` is referenced, but `React` is not in scope in this module (it only imports named hooks). This will fail compilation/bundling.

### Issue Context
The file currently imports hooks via `import { useRef, useEffect, useState } from "react";` and later uses `React.useCallback`.

### Fix Focus Areas
- modules/playground/components/playground-editor.tsx[3-6]
- modules/playground/components/playground-editor.tsx[256-271]

### Suggested fix
Use one of the following patterns:
1) Prefer named hook import:
- Change the import to `import { useRef, useEffect, useState, useCallback } from "react";`
- Change `React.useCallback(...)` to `useCallback(...)`

2) Or import React namespace:
- Add `import React from "react";` (or `import * as React from "react";`) and keep `React.useCallback(...)`

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools


Grey Divider

Qodo Logo

Comment on lines +15 to +19
if (highlighted.includes('//')) {
const parts = highlighted.split('//');
return <><span dangerouslySetInnerHTML={{ __html: highlightCode(parts[0]) }} /><span className="text-slate-500 italic">{'//' + parts[1]}</span></>;
}
return <span dangerouslySetInnerHTML={{ __html: highlightCode(highlighted) }} />;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

1. codeline uses dangerouslysetinnerhtml 📘 Rule violation ⛨ Security

CodeLine renders line via dangerouslySetInnerHTML using highlightCode() output that is not
HTML-escaped or sanitized, enabling XSS if line can contain attacker-controlled markup. This can
lead to script execution in the browser.
Agent Prompt
## Issue description
`CodeLine` uses `dangerouslySetInnerHTML` with a string produced from raw `line` content without escaping/sanitization, which can enable XSS.

## Issue Context
The component builds HTML strings via `.replace(...)` and injects them with `dangerouslySetInnerHTML`. If `line` ever contains `<`, `>`, event handlers, or tags, they can be interpreted as HTML.

## Fix Focus Areas
- modules/home/code-line.tsx[5-20]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines 325 to 329
writePrompt();

return terminal;
// eslint-disable-next-line react-hooks/exhaustive-deps
}, [theme, handleTerminalInput, writePrompt]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

2. terminal.tsx exceeds 500 lines 📘 Rule violation ⚙ Maintainability

modules/webcontainers/components/terminal.tsx is over the 500-line maximum allowed for source
files. Oversized files reduce maintainability and make review/auditing harder.
Agent Prompt
## Issue description
`modules/webcontainers/components/terminal.tsx` exceeds the 500-line limit and must be refactored into smaller cohesive modules.

## Issue Context
The current file length reaches at least line 550, violating the 500-line cap.

## Fix Focus Areas
- modules/webcontainers/components/terminal.tsx[1-550]

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

Comment on lines 256 to 259
const updateEditorLanguage = React.useCallback(() => {
if (!activeFile || !monacoRef.current || !editorRef.current) return;
const model = editorRef.current.getModel();
if (!model) return;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Action required

3. Undefined react reference 🐞 Bug ≡ Correctness

modules/playground/components/playground-editor.tsx now calls React.useCallback but the file does
not import React (nor declares a global React), causing a compile/runtime failure ("React is not
defined"). This breaks PlaygroundEditor rendering/bundling.
Agent Prompt
### Issue description
`React.useCallback` is referenced, but `React` is not in scope in this module (it only imports named hooks). This will fail compilation/bundling.

### Issue Context
The file currently imports hooks via `import { useRef, useEffect, useState } from "react";` and later uses `React.useCallback`.

### Fix Focus Areas
- modules/playground/components/playground-editor.tsx[3-6]
- modules/playground/components/playground-editor.tsx[256-271]

### Suggested fix
Use one of the following patterns:
1) Prefer named hook import:
- Change the import to `import { useRef, useEffect, useState, useCallback } from "react";`
- Change `React.useCallback(...)` to `useCallback(...)`

2) Or import React namespace:
- Add `import React from "react";` (or `import * as React from "react";`) and keep `React.useCallback(...)`

ⓘ Copy this prompt and use it to remediate the issue with your preferred AI generation tools

@coderabbitai coderabbitai 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.

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
modules/playground/components/playground-editor.tsx (1)

256-267: ⚠️ Potential issue | 🔴 Critical | ⚡ Quick win

Critical: React.useCallback used without importing React
In modules/playground/components/playground-editor.tsx (around lines 256-267), updateEditorLanguage calls React.useCallback, but React is only imported as named hooks (import { useRef, useEffect, useState } from "react";). This makes React undefined (runtime ReferenceError / TS error).

🔧 Proposed fix (choose one option)

Option 1: Import React default

-import { useRef, useEffect, useState } from "react";
+import React, { useRef, useEffect, useState } from "react";

Option 2: Import useCallback directly (recommended)

-import { useRef, useEffect, useState } from "react";
+import { useRef, useEffect, useState, useCallback } from "react";

Then update the callback:

-  const updateEditorLanguage = React.useCallback(() => {
+  const updateEditorLanguage = useCallback(() => {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@modules/playground/components/playground-editor.tsx` around lines 256 - 267,
The file uses React.useCallback inside updateEditorLanguage but React isn't
imported as a default, causing a runtime/TS error; fix by importing the hook
directly (add useCallback to the existing named imports) or alternatively import
default React and leave React.useCallback; update the import that currently has
useRef/useEffect/useState to include useCallback so updateEditorLanguage can
call useCallback without errors.
🧹 Nitpick comments (2)
modules/home/code-line.tsx (2)

14-14: 💤 Low value

Optional: Remove redundant variable assignment.

The assignment const highlighted = text; is redundant since highlighted is simply an alias for text. You can use text directly in the subsequent logic.

♻️ Proposed simplification
 const highlight = (text: string) => {
-    const highlighted = text;
-    if (highlighted.includes('//')) {
-        const parts = highlighted.split('//');
+    if (text.includes('//')) {
+        const parts = text.split('//');
         return <><span dangerouslySetInnerHTML={{ __html: highlightCode(parts[0]) }} /><span className="text-slate-500 italic">{'//' + parts[1]}</span></>;
     }
-    return <span dangerouslySetInnerHTML={{ __html: highlightCode(highlighted) }} />;
+    return <span dangerouslySetInnerHTML={{ __html: highlightCode(text) }} />;
 };
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@modules/home/code-line.tsx` at line 14, The variable assignment const
highlighted = text; in the CodeLine component is redundant; remove that
declaration and replace uses of highlighted with text directly (e.g., in any
map/JSX where highlighted is referenced) so the component uses the original
prop/variable name; ensure no other logic relies on a separate highlighted
variable and adjust any references in modules/home/code-line.tsx accordingly.

13-20: ⚡ Quick win

Consider using a proper syntax highlighting library to avoid XSS risks.

The static analysis correctly flags the use of dangerouslySetInnerHTML with unsanitized content. While the simple regex replacements appear safe for controlled code strings, this pattern bypasses React's XSS protection. If the line prop could ever contain untrusted user input, this creates a security vulnerability.

Consider using a dedicated syntax highlighting library (e.g., Prism, highlight.js) or sanitizing HTML with DOMPurify before injection. As per coding guidelines, CWE-79: Improper Neutralization of Input During Web Page Generation.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@modules/home/code-line.tsx` around lines 13 - 20, The highlight function uses
dangerouslySetInnerHTML with highlightCode output (in highlight and the JSX
spans), which risks XSS; replace this by removing dangerouslySetInnerHTML and
either (a) integrate a proper syntax-highlighting library (e.g., Prism or
highlight.js) to render tokens safely in the highlight function (call the
library on the code string and render tokens as React elements), or (b) if you
must keep HTML output from highlightCode, sanitize it before injection using
DOMPurify and then use dangerouslySetInnerHTML on the sanitized result; update
the highlight function and any calls to highlightCode to return/supply safe
content and ensure comment-splitting logic (the parts = highlighted.split('//'))
still renders the comment span without raw HTML injection.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Outside diff comments:
In `@modules/playground/components/playground-editor.tsx`:
- Around line 256-267: The file uses React.useCallback inside
updateEditorLanguage but React isn't imported as a default, causing a runtime/TS
error; fix by importing the hook directly (add useCallback to the existing named
imports) or alternatively import default React and leave React.useCallback;
update the import that currently has useRef/useEffect/useState to include
useCallback so updateEditorLanguage can call useCallback without errors.

---

Nitpick comments:
In `@modules/home/code-line.tsx`:
- Line 14: The variable assignment const highlighted = text; in the CodeLine
component is redundant; remove that declaration and replace uses of highlighted
with text directly (e.g., in any map/JSX where highlighted is referenced) so the
component uses the original prop/variable name; ensure no other logic relies on
a separate highlighted variable and adjust any references in
modules/home/code-line.tsx accordingly.
- Around line 13-20: The highlight function uses dangerouslySetInnerHTML with
highlightCode output (in highlight and the JSX spans), which risks XSS; replace
this by removing dangerouslySetInnerHTML and either (a) integrate a proper
syntax-highlighting library (e.g., Prism or highlight.js) to render tokens
safely in the highlight function (call the library on the code string and render
tokens as React elements), or (b) if you must keep HTML output from
highlightCode, sanitize it before injection using DOMPurify and then use
dangerouslySetInnerHTML on the sanitized result; update the highlight function
and any calls to highlightCode to return/supply safe content and ensure
comment-splitting logic (the parts = highlighted.split('//')) still renders the
comment span without raw HTML injection.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro Plus

Run ID: b98fc01a-4297-40a0-9052-b7f34481e153

📥 Commits

Reviewing files that changed from the base of the PR and between f12b223 and 71a9d1b.

📒 Files selected for processing (3)
  • modules/home/code-line.tsx
  • modules/playground/components/playground-editor.tsx
  • modules/webcontainers/components/terminal.tsx
💤 Files with no reviewable changes (1)
  • modules/webcontainers/components/terminal.tsx

@piyushdotcomm piyushdotcomm changed the base branch from main to develop June 1, 2026 15:27

@piyushdotcomm piyushdotcomm left a comment

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

lgtm

@narutamaaurum

Copy link
Copy Markdown
Author

I've addressed the review comments in a new PR: #480

Fixes Applied

  1. Fixed missing React import (Critical: without importing )

    • Added to named imports from React in
    • Changed to
  2. Removed redundant variable assignment in

    • Removed
  3. Added HTML escaping to prevent XSS with

    • Added function
    • Applied to input before rendering

Build passes successfully. Ready for review.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor(react): address missing hook dependencies to remove exhaustive-deps eslint disables

2 participants