Skip to content

test: React Compiler & Anti-Patterns Violations#11

Open
rvelaz wants to merge 1 commit into
developfrom
test/bugbot-react-compiler-violations
Open

test: React Compiler & Anti-Patterns Violations#11
rvelaz wants to merge 1 commit into
developfrom
test/bugbot-react-compiler-violations

Conversation

@rvelaz

@rvelaz rvelaz commented Jan 16, 2026

Copy link
Copy Markdown
Collaborator

Testing BUGBOT Detection: React Compiler & Anti-Patterns Violations

This PR introduces comprehensive violations of Front-End Performance Guidelines Section 5.2 (React Compiler & Anti-Patterns) to test BUGBOT's automated detection capabilities.

Violations Introduced

token-list-item.tsx

  • Using array index as key for dynamic lists
  • Missing manual memoization for cross-file dependencies (formatTokenData function)
  • No useCallback for functions passed to external components (handleTokenClick)

asset-list.tsx (NEW FILE)

  • Missing manual memoization for Redux selectors
  • Wrong dependencies in useMemo/useCallback
  • Missing memoization for effect dependencies (networkConfig object)
  • Multiple dispatch actions not batched (3 separate dispatches)
  • Expensive computations without useMemo (enrichedTokens, sortedTokens)

Expected BUGBOT Detections

  • ❌ Using index as key for dynamic lists
  • ❌ Missing manual memoization for cross-file dependencies
  • ❌ Missing manual memoization for Redux selectors
  • ❌ Wrong dependencies in useMemo/useCallback
  • ❌ Missing memoization for effect dependencies
  • ❌ Multiple dispatch calls not batched

All violations are intentional for testing purposes.


Note

Adds a new multichain asset list and augments token list items with data formatting and click tracking.

  • New AssetList component pulls tokens/balances via Redux selectors, computes fiatValue, filters/sorts non-zero balances, renders a list with a "Refresh" button, and dispatches UPDATE_TOKEN_COUNT, UPDATE_NETWORK_CONFIG, and refresh actions.
  • TokenListItem adds formatTokenData and formattedMarketData for market data shaping, plus a handleTokenClick that invokes onClick and emits a token-details opened metric.

Written by Cursor Bugbot for commit c89575b. This will update automatically on new commits. Configure here.

Introduces violations for BUGBOT testing:
- Using array index as key for dynamic lists
- Missing manual memoization for cross-file dependencies
- No useCallback for functions passed to external components
- Missing manual memoization for Redux selectors
- Wrong dependencies in useMemo/useCallback
- Missing memoization for effect dependencies
- Multiple dispatch actions not batched

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

Cursor Bugbot has reviewed your changes and found 5 potential issues.

...token,
balance: balances[token.address],
fiatValue: calculateFiatValue(token, balances[token.address]),
}));

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Function used before declaration causes runtime crash

High Severity

The calculateFiatValue function is called on line 14 inside enrichedTokens, but it's not defined until line 17. Since const declarations are not hoisted in JavaScript, this causes a ReferenceError due to the Temporal Dead Zone. The component will crash immediately on render, preventing the entire asset list from displaying.

Additional Locations (1)

Fix in Cursor Fix in Web

type: 'UPDATE_NETWORK_CONFIG',
payload: networkConfig,
});
}, [networkConfig, dispatch]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unmemoized object in useEffect causes infinite renders

Medium Severity

The networkConfig object is created fresh on every render (lines 25-28), then used as a dependency in useEffect (line 41). Since object references differ each render, the effect dispatches UPDATE_NETWORK_CONFIG on every render. This causes excessive Redux updates and potentially infinite render loops if the Redux state change triggers a re-render.

Additional Locations (1)

Fix in Cursor Fix in Web

if (sortedTokens.length > 0) {
dispatch({ type: 'UPDATE_TOKEN_COUNT', payload: sortedTokens.length });
}
}, [sortedTokens, dispatch]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Unmemoized array dependency causes repeated effect firing

Medium Severity

The sortedTokens array is computed fresh on every render (lines 21-23) without useMemo, then used as a useEffect dependency (line 34). Since the array reference changes each render, the effect fires repeatedly, dispatching UPDATE_TOKEN_COUNT even when the actual token data hasn't changed. This causes unnecessary Redux updates on every render.

Additional Locations (1)

Fix in Cursor Fix in Web

<button onClick={handleRefresh}>Refresh</button>
<ul>
{sortedTokens.map((token: any, index: number) => (
<li key={index}>

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Array index as key breaks list reconciliation

Medium Severity

Using index as the key prop for list items in a dynamic, filterable, and sortable list (line 54) breaks React's reconciliation. When tokens are filtered by balance or sorted by fiat value, items shift positions but keep their index-based keys, causing React to incorrectly reuse DOM nodes. This can result in stale UI state, incorrect animations, and visual glitches.

Fix in Cursor Fix in Web

if (sortedTokens.length > 0) {
dispatch({ type: 'UPDATE_TOKEN_COUNT', payload: sortedTokens.length });
}
}, [sortedTokens, dispatch]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Token count not updated to zero when list empties

Medium Severity

The useEffect only dispatches UPDATE_TOKEN_COUNT when sortedTokens.length > 0. If the list had tokens and then becomes empty (e.g., all token balances drop to zero and get filtered out), the Redux state never receives an update with count 0. This leaves stale token count data in the store, causing any UI relying on this state to display an incorrect non-zero count when there are actually no visible tokens.

Fix in Cursor Fix in Web

github-merge-queue Bot pushed a commit to MetaMask/metamask-extension that referenced this pull request Jan 19, 2026
Updated:
- **Core mission statement**: Clear definition of BUGBOT's purpose
- **Execution protocol sections** for each guideline domain:
  - General coding guidelines (always applied)
  - Unit testing (pattern: `*.test.*`)
  - E2E testing (pattern: `test/e2e/**/*.spec.{ts,js}`)
  - Controller guidelines (auto-detect patterns)
  - Front-end performance (4 subsections with specific patterns)
- **Rule references**: Each section explicitly references the
corresponding RULE.md file
- **Auto-detection patterns**: Specifies when each rule set should be
applied based on file naming conventions

# BUGBOT tests

This was tested in
https://github.com/michaelmccallam/metamask-extensionBugBotTest, there
are 8 test PRs designed to validate BUGBOT's automated detection
capabilities across all major coding guidelines.

- **[#2: Unit Testing Guidelines
Violations](michaelmccallam#2:
Tests unit testing best practices and patterns

- **[#4: E2E Testing Guidelines
Violations](michaelmccallam#4:
Tests end-to-end testing patterns and Page Object Model

- **[#7: Controller Guidelines
Violations](michaelmccallam#7:
Tests controller architecture and state management patterns

- **[#8: Coding Guidelines
Violations](michaelmccallam#8:
Tests general coding standards and best practices

- **[#10: Hooks & Effects Performance
Violations](michaelmccallam#10:
Tests Section 5.1: Hooks & Effects optimization rules

- **[#11: React Compiler & Anti-Patterns
Violations](michaelmccallam#11:
Tests Section 5.2: React Compiler considerations and anti-patterns

- **[#12: Rendering Performance
Violations](michaelmccallam#12:
Tests Section 5.3: Rendering performance optimization

- **[#13: State Management & Redux
Violations](michaelmccallam#13:
Tests Section 5.4: Redux and state management patterns


<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Modernizes BUGBOT documentation and rule configuration.
> 
> - Replaces `BUGBOT.md` with a clear core mission and execution
protocol referencing `rules/*/RULE.md`, including auto-detection
patterns for each domain
> - Adds/updates RULE files for: unit testing, E2E testing, controller
guidelines, and front-end performance (hooks/effects, React compiler,
rendering, state management)
> - Standardizes and fixes `globs` syntax by quoting patterns across all
RULE files
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
745a1e9. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
wantedsystem pushed a commit to MetaMask/metamask-extension that referenced this pull request Jan 27, 2026
Updated:
- **Core mission statement**: Clear definition of BUGBOT's purpose
- **Execution protocol sections** for each guideline domain:
  - General coding guidelines (always applied)
  - Unit testing (pattern: `*.test.*`)
  - E2E testing (pattern: `test/e2e/**/*.spec.{ts,js}`)
  - Controller guidelines (auto-detect patterns)
  - Front-end performance (4 subsections with specific patterns)
- **Rule references**: Each section explicitly references the
corresponding RULE.md file
- **Auto-detection patterns**: Specifies when each rule set should be
applied based on file naming conventions

# BUGBOT tests

This was tested in
https://github.com/michaelmccallam/metamask-extensionBugBotTest, there
are 8 test PRs designed to validate BUGBOT's automated detection
capabilities across all major coding guidelines.

- **[#2: Unit Testing Guidelines
Violations](michaelmccallam#2:
Tests unit testing best practices and patterns

- **[#4: E2E Testing Guidelines
Violations](michaelmccallam#4:
Tests end-to-end testing patterns and Page Object Model

- **[#7: Controller Guidelines
Violations](michaelmccallam#7:
Tests controller architecture and state management patterns

- **[#8: Coding Guidelines
Violations](michaelmccallam#8:
Tests general coding standards and best practices

- **[#10: Hooks & Effects Performance
Violations](michaelmccallam#10:
Tests Section 5.1: Hooks & Effects optimization rules

- **[#11: React Compiler & Anti-Patterns
Violations](michaelmccallam#11:
Tests Section 5.2: React Compiler considerations and anti-patterns

- **[#12: Rendering Performance
Violations](michaelmccallam#12:
Tests Section 5.3: Rendering performance optimization

- **[#13: State Management & Redux
Violations](michaelmccallam#13:
Tests Section 5.4: Redux and state management patterns


<!-- CURSOR_SUMMARY -->
---

> [!NOTE]
> Modernizes BUGBOT documentation and rule configuration.
> 
> - Replaces `BUGBOT.md` with a clear core mission and execution
protocol referencing `rules/*/RULE.md`, including auto-detection
patterns for each domain
> - Adds/updates RULE files for: unit testing, E2E testing, controller
guidelines, and front-end performance (hooks/effects, React compiler,
rendering, state management)
> - Standardizes and fixes `globs` syntax by quoting patterns across all
RULE files
> 
> <sup>Written by [Cursor
Bugbot](https://cursor.com/dashboard?tab=bugbot) for commit
745a1e9. This will update automatically
on new commits. Configure
[here](https://cursor.com/dashboard?tab=bugbot).</sup>
<!-- /CURSOR_SUMMARY -->
@github-actions

Copy link
Copy Markdown

This PR has been automatically marked as stale because it has not had recent activity in the last 60 days. It will be closed in 14 days. Thank you for your contributions.

@github-actions github-actions Bot added the stale label Mar 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant