Skip to content

Conversation

@m4dm4rtig4n
Copy link
Contributor

Summary

Fix React error #310 and "rendered more hooks than before" by reorganizing the Simulator component. The issue was caused by hooks being called after conditional early returns, violating React's rules of hooks.

Changes:

  • Move all hooks (useEffect, useMemo) before early returns
  • Move early return checks after all hooks
  • Move helper functions after early returns
  • Remove competing global state registration (already handled by PageHeader)

The Simulator page now follows React's rules and renders correctly without infinite loops or hook mismatch errors.

Test Plan

  • Navigate to /simulator page
  • Verify page loads without React errors
  • Verify simulation can be triggered
  • Verify filters and sorting work correctly

Clément VALENTIN and others added 2 commits December 5, 2025 00:25
Remove useEffect hooks that were registering handleSimulation in the
global dataFetchStore, which conflicted with PageHeader's unified
fetch registration. This fixes React error #310 (infinite loop).

The Simulator page now uses its own local state and button for
triggering simulations instead of conflicting with the global store.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Fix React error #310 and "rendered more hooks than before" by moving all
hooks (useEffect, useMemo) before conditional early returns. This ensures
hooks are called in the same order every render, respecting React's
rules of hooks.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
Copilot AI review requested due to automatic review settings December 4, 2025 23:41
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes React hooks violations in the Simulator component by reorganizing code to comply with React's Rules of Hooks. The main issue was that hooks were being called after conditional early returns, which caused "rendered more hooks than before" errors and infinite loops.

Key Changes:

  • Moved all hooks (useEffect, useMemo) before early return statements to comply with React's Rules of Hooks
  • Removed competing global state registration that was already handled by PageHeader
  • Reorganized code with clear section markers for hooks, early returns, and helper functions

Reviewed changes

Copilot reviewed 2 out of 3 changed files in this pull request and generated no comments.

File Description
apps/web/src/pages/Simulator.tsx Fixed React hooks violations by moving all hooks before early returns, removing unused useDataFetchStore import, and adding clear code section markers
apps/web/package-lock.json Removed unused tree-sitter peer dependencies (cleanup)
.claude/commands/sync.md Updated workflow documentation from git-based sync to rsync-based file copying (unrelated to hooks fix)

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Restore complete package-lock.json to fix npm ci sync error in CI.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
@m4dm4rtig4n m4dm4rtig4n force-pushed the fix-react-infinite-loop branch from d63e6da to 22c9430 Compare December 4, 2025 23:46
@m4dm4rtig4n m4dm4rtig4n merged commit 21d3993 into main Dec 4, 2025
5 checks passed
@m4dm4rtig4n m4dm4rtig4n deleted the fix-react-infinite-loop branch December 18, 2025 07:59
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.

2 participants