Skip to content

Optimize add-provider dialog state derivation#2602

Draft
cursor[bot] wants to merge 2 commits intomainfrom
cursor/react-performance-optimization-48e7
Draft

Optimize add-provider dialog state derivation#2602
cursor[bot] wants to merge 2 commits intomainfrom
cursor/react-performance-optimization-48e7

Conversation

@cursor
Copy link
Copy Markdown
Contributor

@cursor cursor Bot commented May 8, 2026

What Changed

  • Removed the add-provider dialog's reset and auto-derived instance-id useEffect chain.
  • Render the dialog's stateful content only while open so each open starts from fresh state without a cascading reset effect.
  • Derive the instance id during render until the user manually edits it, avoiding an extra render after every label/driver change.
  • Added react-scan before/after recordings:
    • docs/perf-recordings/add-provider-dialog-before-react-scan.webm
    • docs/perf-recordings/add-provider-dialog-after-react-scan.webm

Why

React Doctor flagged AddProviderInstanceDialog for both cascading state updates in an effect and an effect chain derived from driver/label. This change follows React's "You Might Not Need an Effect" guidance by replacing derived state synchronization with render-time derivation and state ownership scoped to the open dialog content.

React Doctor result improved from 68/100 to 69/100, reducing total findings from 763 to 760 and state/effects findings from 28 to 26. The add-provider dialog no longer appears in react-doctor/no-effect-chain or react-doctor/no-cascading-set-state.

UI Changes

No intended visual UI changes. Interaction recordings with react-scan enabled are included in this PR:

  • Before: docs/perf-recordings/add-provider-dialog-before-react-scan.webm
  • After: docs/perf-recordings/add-provider-dialog-after-react-scan.webm

Checklist

  • This PR is small and focused
  • I explained what changed and why
  • I included before/after screenshots for any UI changes
  • I included a video for animation/interaction changes

Verification:

  • bun fmt
  • bun lint (passes with existing warnings)
  • bun typecheck
  • bunx react-doctor@latest apps/web --verbose --offline --fail-on none
Open in Web View Automation 

Note

Optimize state derivation in AddProviderInstanceDialog by removing useEffect resets

  • Extracts dialog logic into a new AddProviderInstanceDialogContent child component that only mounts when the dialog is open, replacing useEffect-driven form resets with natural unmount/remount behavior.
  • Replaces the instanceId/instanceIdDirty state pair and its two useEffect hooks with a single manualInstanceId state and a derived instanceId computed as manualInstanceId ?? deriveInstanceId(driver, label).
  • Adds before/after React Scan performance recordings under docs/perf-recordings/.

Macroscope summarized f991605.

cursoragent and others added 2 commits May 8, 2026 17:07
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
Co-authored-by: Julius Marminge <juliusmarminge@users.noreply.github.com>
@github-actions github-actions Bot added size:M 30-99 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. labels May 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M 30-99 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant