Skip to content

fix: resolve FBD editor infinite render loop causing high CPU#651

Merged
thiagoralves merged 2 commits into
developmentfrom
fix/fbd-editor-performance
Mar 9, 2026
Merged

fix: resolve FBD editor infinite render loop causing high CPU#651
thiagoralves merged 2 commits into
developmentfrom
fix/fbd-editor-performance

Conversation

@thiagoralves
Copy link
Copy Markdown
Contributor

@thiagoralves thiagoralves commented Mar 9, 2026

Summary

  • Strip hasDivergence UI property from store comparisons in updateRungState to prevent isEqual mismatch (undefined vs false) that triggered a continuous render loop
  • Use selective Zustand selectors in FbdEditor wrapper instead of whole-store destructuring to avoid unnecessary re-renders
  • Memoize divergence computation with useMemo to prevent recalculation on every render
  • Narrow styledEdges dependencies from entire project object to only pouRef?.data.variables and project.data.configuration.resource.instances

These are the same fixes applied in openplc-web (PR #266, merged).

Root Cause

The hasDivergence property was set on nodes for UI display but leaked into store comparisons. isEqual({hasDivergence: undefined}, {hasDivergence: false}) always returned false, causing updateRungState to write back to the store on every comparison cycle, which triggered flow.updated = trueupdatePou → pous change → FbdEditor re-render → loop.

Test plan

  • Open a large FBD diagram and verify CPU usage stays low (~0% idle)
  • Verify FBD blocks still display divergence indicators correctly
  • Verify variable sync still works when editing the variable table
  • Test adding, removing, and connecting FBD blocks
  • Verify save/load cycle preserves FBD flow data

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Bug Fixes

    • Fixed variable type filtering in autocomplete to properly handle mixed-case entries in restrictions.
    • Improved variable type restriction checks to handle both array and non-array values robustly.
  • Performance

    • Optimized component rendering with memoization to reduce unnecessary recalculations.

thiagoralves and others added 2 commits March 9, 2026 13:06
Strip hasDivergence UI property from store comparisons to prevent
isEqual mismatch (undefined vs false) that triggered continuous
re-renders. Use selective Zustand selectors and memoize divergence
computation in FbdEditor wrapper.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Case-sensitivity mismatch in type filtering: getVariableRestrictionType
returns user-defined types in original case (e.g. "Irrigation_State")
but the filter lowercased only the variable side, causing the comparison
to always fail. Normalize both sides with .toLowerCase().

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Mar 9, 2026

Caution

Review failed

The pull request is closed.

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: dfb87791-2d3b-4928-b770-d137a38a5257

📥 Commits

Reviewing files that changed from the base of the PR and between e414315 and 9f13289.

📒 Files selected for processing (4)
  • src/renderer/components/_atoms/graphical-editor/fbd/autocomplete/index.tsx
  • src/renderer/components/_atoms/graphical-editor/ladder/autocomplete/index.tsx
  • src/renderer/components/_features/[workspace]/editor/graphical/FBD/index.tsx
  • src/renderer/components/_molecules/graphical-editor/fbd/index.tsx

Disabled knowledge base sources:

  • Linear integration is disabled

You can enable these sources in your CodeRabbit configuration.


Walkthrough

The PR fixes case-sensitivity issues in autocomplete variable type filtering across FBD and ladder editors, and refactors divergence calculation logic in FBD components using memoization while introducing data cleaning to strip divergence flags from node state.

Changes

Cohort / File(s) Summary
Autocomplete Variable Type Filtering
src/renderer/components/_atoms/graphical-editor/fbd/autocomplete/index.tsx, src/renderer/components/_atoms/graphical-editor/ladder/autocomplete/index.tsx
Standardize variable type restriction checks by normalizing comparison values to lowercase and handling both array and non-array value formats for robust case-insensitive matching.
FBD Divergence Calculation & Optimization
src/renderer/components/_features/[workspace]/editor/graphical/FBD/index.tsx, src/renderer/components/_molecules/graphical-editor/fbd/index.tsx
Refactor divergence computation into memoized selectors, introduce stripDivergence helper to remove hasDivergence flag from node data during rung updates, and optimize styledEdges memoization dependencies.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested labels

bug

Suggested reviewers

  • JoaoGSP
  • Gustavohsdp

Poem

🐰 A fix for case and divergence woes,
Where rabbit code now cleaning flows,
Memoized logic, fast and bright,
Autocomplete works just right,
No more confusion, side to side!

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/fbd-editor-performance

Tip

Try Coding Plans. Let us write the prompt for your AI agent so you can ship faster (with fewer bugs).
Share your feedback on Discord.


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.

@thiagoralves thiagoralves merged commit 4a9f400 into development Mar 9, 2026
8 of 9 checks passed
@thiagoralves thiagoralves deleted the fix/fbd-editor-performance branch March 9, 2026 17:36
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.

1 participant