test: React Compiler & Anti-Patterns Violations#11
Conversation
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
| ...token, | ||
| balance: balances[token.address], | ||
| fiatValue: calculateFiatValue(token, balances[token.address]), | ||
| })); |
There was a problem hiding this comment.
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)
| type: 'UPDATE_NETWORK_CONFIG', | ||
| payload: networkConfig, | ||
| }); | ||
| }, [networkConfig, dispatch]); |
There was a problem hiding this comment.
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)
| if (sortedTokens.length > 0) { | ||
| dispatch({ type: 'UPDATE_TOKEN_COUNT', payload: sortedTokens.length }); | ||
| } | ||
| }, [sortedTokens, dispatch]); |
There was a problem hiding this comment.
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)
| <button onClick={handleRefresh}>Refresh</button> | ||
| <ul> | ||
| {sortedTokens.map((token: any, index: number) => ( | ||
| <li key={index}> |
There was a problem hiding this comment.
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.
| if (sortedTokens.length > 0) { | ||
| dispatch({ type: 'UPDATE_TOKEN_COUNT', payload: sortedTokens.length }); | ||
| } | ||
| }, [sortedTokens, dispatch]); |
There was a problem hiding this comment.
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.
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 -->
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 -->
|
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. |
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
asset-list.tsx (NEW FILE)
Expected BUGBOT Detections
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.
AssetListcomponent pulls tokens/balances via Redux selectors, computesfiatValue, filters/sorts non-zero balances, renders a list with a "Refresh" button, and dispatchesUPDATE_TOKEN_COUNT,UPDATE_NETWORK_CONFIG, and refresh actions.TokenListItemaddsformatTokenDataandformattedMarketDatafor market data shaping, plus ahandleTokenClickthat invokesonClickand emits a token-details opened metric.Written by Cursor Bugbot for commit c89575b. This will update automatically on new commits. Configure here.