Skip to content

🐛 Fix race condition in recommendation modal when hitting enter#28017

Open
AsishKumarDalal wants to merge 1 commit into
TryGhost:mainfrom
AsishKumarDalal:fix-recommendation-modal-state
Open

🐛 Fix race condition in recommendation modal when hitting enter#28017
AsishKumarDalal wants to merge 1 commit into
TryGhost:mainfrom
AsishKumarDalal:fix-recommendation-modal-state

Conversation

@AsishKumarDalal
Copy link
Copy Markdown

This PR fixes a bug in add-recommendation-modal.tsx where hitting 'Enter' when the URL was already fully formatted would freeze the modal and prevent submission.

Changes

  • Replaced the anti-pattern useEffect watching [formState] with an explicit evaluation in onKeyDown.
  • If the formattedUrl perfectly matches formState.url, the modal submission onOk() is triggered synchronously.
  • If it doesn't match, the state is updated and the useEffect reliably triggers submission.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 21, 2026

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 4b6c0512-5b4b-49de-8433-f18dad0c2d8b

📥 Commits

Reviewing files that changed from the base of the PR and between bd46a1c and 7072858.

📒 Files selected for processing (1)
  • apps/admin-x-settings/src/components/settings/growth/recommendations/add-recommendation-modal.tsx

Walkthrough

This PR modifies the Enter key behavior for the URL input field in the recommendation modal. When a user presses Enter, the handler now computes a formatted version of the entered URL. If formatting changes the value, it updates the form state and sets an enterPressed flag to trigger subsequent logic. If the URL is already properly formatted, the handler immediately calls onOk() instead of deferring to the flag-based workflow. This optimization avoids an unnecessary state update when the URL requires no formatting.

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately identifies the main change—fixing a race condition in the recommendation modal's Enter key behavior—and directly relates to the changeset.
Description check ✅ Passed The description is relevant and provides clear context about the bug being fixed and the implementation approach taken in the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

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