Skip to content

fix(DesignerV2): Add re-entry guard to autoCreateConnectionIfPossible#9220

Merged
rllyy97 merged 2 commits into
mainfrom
rileyevans/fix/9131-auto-create-connection-loop
May 27, 2026
Merged

fix(DesignerV2): Add re-entry guard to autoCreateConnectionIfPossible#9220
rllyy97 merged 2 commits into
mainfrom
rileyevans/fix/9131-auto-create-connection-loop

Conversation

@rllyy97
Copy link
Copy Markdown
Contributor

@rllyy97 rllyy97 commented May 27, 2026

Commit Type

  • feature - New functionality
  • fix - Bug fix
  • refactor - Code restructuring without behavior change
  • perf - Performance improvement
  • docs - Documentation update
  • test - Test-related changes
  • chore - Maintenance/tooling

Risk Level

  • Low - Minor changes, limited scope
  • Medium - Moderate changes, some user impact
  • High - Major changes, significant user/system impact

What & Why

Fixes #9131. ConnectionPanel in designer-v2 invokes autoCreateConnectionIfPossible from a useEffect without a re-entry guard, which causes an infinite loop for connectors with single auth.

Root cause: useConnectionsForConnector is configured with cacheTime: 0 and staleTime: 0. When the effect calls autoCreateConnectionIfPossible, it transitively calls getUniqueConnectionNamegetConnectionsForConnector, which writes to the same React Query cache key as the hook. That cache write produces a new connections array reference, which changes the effect's dependency, re-runs the effect, and restarts the cycle. The result is a flood of redundant getConnections and 404 getConnection calls (and for connectors with no visible params, multiple concurrent createConnection PUTs).

Fix: Add a useRef-based re-entry guard so the auto-create flow runs at most once per panel instance until it resolves (success / manual creation / error).

Impact of Change

  • Users: Consumption-designer (v2) users opening the connection panel for a connector with single auth, visible connection parameters, and no existing connection will no longer see the panel stall behind redundant network calls. No behavior change for connectors with connectionParameterSets (multi-auth), since they exit autoCreateConnectionIfPossible early at the connectorHasMultiAuth check.
  • Developers: No API changes. Internal re-entry guard local to ConnectionPanel. The deeper architectural smell — useConnectionsForConnector and getConnectionsForConnector sharing a query key while the hook has cacheTime: 0/staleTime: 0 — is documented in a NOTE comment but not refactored here.
  • System: Eliminates a per-panel-open API call storm (many getConnections + recursive getConnection 404s). Reduces latency before the create-connection panel renders. No new dependencies.

Test Plan

  • Unit tests added/updated
  • E2E tests added/updated
  • Manual testing completed
  • Tested in: standalone designer-v2; verified existing related unit tests (selectConnectionFromConnector.spec.tsx) still pass. Other v2 connection panel tests were unaffected by this change (failures observed elsewhere in the folder also reproduce on main — pre-existing).

Contributors

  • @Xiaoyu-Huang — reported the issue with root-cause analysis and proposed the re-entry-guard fix that is implemented here.

Screenshots/Videos

N/A — no visual change. Observable difference is in the browser network panel (no more loop of getConnections / getConnection 404 calls when opening the connection panel for an affected connector).

… useEffect

Fixes #9131. The useEffect in ConnectionPanel called autoCreateConnectionIfPossible without a re-entry guard, creating a loop.

autoCreateConnectionIfPossible -> getUniqueConnectionName -> getConnectionsForConnector writes to the same React Query cache key as useConnectionsForConnector (which uses cacheTime/staleTime 0). The cache write produces a new connections array reference, re-triggering the effect, and the cycle repeats.

The loop affects consumption-designer connectors with single auth (no connectionParameterSets), visible connection parameters, and an ARM resource ID — these reach getUniqueConnectionName before exiting.

Add a useRef-based re-entry guard so the auto-create flow runs at most once per panel instance until it resolves (success / manual creation / error).
Copilot AI review requested due to automatic review settings May 27, 2026 15:26
@rllyy97 rllyy97 added risk:low Low risk change with minimal impact DesignerV2 labels May 27, 2026
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 27, 2026

🤖 AI PR Validation Report

PR Review Results

Thank you for your submission! Here's detailed feedback on your PR title and body compliance:

PR Title

  • Current: fix(DesignerV2): Add re-entry guard to autoCreateConnectionIfPossible
  • Issue: None. This is a clear, specific title that describes the scope and intent well.
  • Recommendation: No change needed.

Commit Type

  • Properly selected (fix).
  • Only one commit type is selected, which is correct.

Risk Level

  • The selected risk level is Low, and that matches the PR scope and the code change. I do not see a need to raise it based on the diff.

What & Why

  • Current: Clear explanation of the bug, root cause, and fix.
  • Issue: None. This section is strong and sufficiently detailed.
  • Recommendation: No change needed.

Impact of Change

  • The impact section is well written and maps to the actual change.
  • Recommendation:
    • Users: Good as written.
    • Developers: Good as written.
    • System: Good as written.

Test Plan

  • The test plan passes because the diff includes unit tests added/updated in connectionsPanel.spec.tsx.
  • Manual testing is also documented, and the explanation is sufficient.

Contributors

  • Contributor credit is present and appropriate.
  • No action needed.

Screenshots/Videos

  • N/A is appropriate because this is not a visual change.
  • No action needed.

Summary Table

Section Status Recommendation
Title No change needed
Commit Type No change needed
Risk Level No change needed
What & Why No change needed
Impact of Change No change needed
Test Plan No change needed
Contributors No change needed
Screenshots/Videos No change needed

This PR passes review for title and body compliance. The advised risk level is low and matches the submitter’s estimate.


Last updated: Wed, 27 May 2026 15:57:37 GMT

Copy link
Copy Markdown
Contributor

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 an infinite re-render/network-call loop in the Designer V2 ConnectionPanel by adding a re-entry guard around the useEffect that triggers autoCreateConnectionIfPossible, preventing repeated invocation caused by React Query cache writes producing new connections array references.

Changes:

  • Added a useRef-based re-entry guard to ensure autoCreateConnectionIfPossible is not invoked concurrently/repeatedly due to cache updates.
  • Ensured the guard is released on success, manual creation path, and error (catch) to avoid permanently blocking the flow.

@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented May 27, 2026

📊 Coverage Check

🎉 All changed files have adequate test coverage!

Covers the fix from #9220 / #9131 for the autoCreateConnectionIfPossible loop.

Adds 15 tests across panel rendering and auto-create behavior, including the critical regression test that verifies autoCreateConnectionIfPossible is invoked exactly once even when the parent re-renders with a fresh empty connections array reference (the cache-write -> re-render cycle that caused the original loop).
@rllyy97 rllyy97 enabled auto-merge (squash) May 27, 2026 17:27
@rllyy97 rllyy97 merged commit 8953a35 into main May 27, 2026
33 of 36 checks passed
@rllyy97 rllyy97 deleted the rileyevans/fix/9131-auto-create-connection-loop branch May 27, 2026 20:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

DesignerV2 pr-validated risk:low Low risk change with minimal impact

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Logic Apps Designer: autoCreateConnectionIfPossible fires in a loop due to unguarded useEffect

3 participants