Skip to content

Comments

fix: prevent modal from closing when team/channel creation fails#38611

Open
Naetiksoni08 wants to merge 4 commits intoRocketChat:developfrom
Naetiksoni08:fix/prevent-modal-close-on-error
Open

fix: prevent modal from closing when team/channel creation fails#38611
Naetiksoni08 wants to merge 4 commits intoRocketChat:developfrom
Naetiksoni08:fix/prevent-modal-close-on-error

Conversation

@Naetiksoni08
Copy link

@Naetiksoni08 Naetiksoni08 commented Feb 11, 2026

About this PR

Fixes #38607

onClose() was being called inside a finally block in both CreateTeamModal.tsx and CreateChannelModal.tsx. Since finally always executes regardless of success or failure, the modal was closing even when the API call failed — losing all the user's form data.

This PR moves onClose() to the success path only, so the modal stays open on error and users can retry without re-entering their data.

Affected files

  • apps/meteor/client/navbar/NavBarPagesGroup/actions/CreateTeamModal.tsx
  • apps/meteor/client/views/navbar/NavBarPagesGroup/actions/CreateChannelModal.tsx

Testing

Error scenario (before fix): Modal closed on failure, form data lost.
Error scenario (after fix): Modal stays open, error toast shown, form data preserved.
Success scenario: Modal closes and redirects as expected.

Before fix:
Screenshot 2026-02-11 at 7 44 01 AM (form Filled)

Screenshot 2026-02-11 at 7 44 30 AM (modal closed, data lost)

After fix:
Screenshot 2026-02-11 at 9 04 43 PM (modal stays open, data preserved)

Summary by CodeRabbit

  • Bug Fixes
    • Channel and team creation modals now remain open when server errors occur and only close after a successful creation.

Task: ARCH-1958

@Naetiksoni08 Naetiksoni08 requested a review from a team as a code owner February 11, 2026 15:41
@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Feb 11, 2026

Looks like this PR is not ready to merge, because of the following issues:

  • This PR is missing the 'stat: QA assured' label
  • This PR is targeting the wrong base branch. It should target 8.3.0, but it targets 8.2.0

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@CLAassistant
Copy link

CLAassistant commented Feb 11, 2026

CLA assistant check
All committers have signed the CLA.

@changeset-bot
Copy link

changeset-bot bot commented Feb 11, 2026

⚠️ No Changeset found

Latest commit: 5cff527

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 11, 2026

Walkthrough

Moved modal-close behavior so CreateTeam and CreateChannel modals only close after successful creation; on error the modal remains open and server error is surfaced via form error state (root.serverError).

Changes

Cohort / File(s) Summary
Create modals
apps/meteor/client/navbar/NavBarPagesGroup/actions/CreateChannelModal.tsx, apps/meteor/client/navbar/NavBarPagesGroup/actions/CreateTeamModal.tsx
Removed unconditional onClose() from finally; invoke onClose() only on success. Use setError to set errors.root.serverError and render it so server errors are shown while preserving form data.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ModalForm as Modal Form
    participant API as Server API
    participant UI as Error UI

    User->>ModalForm: submit form
    ModalForm->>API: createTeam/createChannel request
    alt success
        API-->>ModalForm: 200 OK
        ModalForm->>ModalForm: call onClose()
    else failure
        API-->>ModalForm: error
        ModalForm->>ModalForm: setError('root.serverError', message)
        ModalForm->>UI: render server error field
        UI-->>User: show error, modal remains open
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Possibly related issues

  • #38607: Prevent modal from closing when team/channel creation fails — this PR moves onClose() out of finally, directly addressing the reported modal-closing-on-error behavior.
  • ARCH-1958: [PR #38611] fix: prevent modal from closing when team/channel creation fails — same objective; changes match the described fix.

Poem

🐰
I hopped through lines where close-hooks slept,
Kept your inputs safe when servers wept.
On triumph I bow and softly close the door,
On error I sit and guard your form once more. ✨

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main change: preventing modals from closing on team/channel creation failures by moving onClose() out of finally blocks.
Linked Issues check ✅ Passed All coding objectives from issues #38607 and ARCH-1958 are met: onClose() moved from finally to success path, modal stays open on error preserving form data, and existing success behavior preserved.
Out of Scope Changes check ✅ Passed All changes are strictly scoped to the two targeted files (CreateTeamModal.tsx and CreateChannelModal.tsx) with focused modifications to error handling logic as specified in linked issues.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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


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.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 2 files

@dougfabris
Copy link
Member

Hi there, thanks for the contribution 🚀

I see this as a nice improvement, but in that case the toast will be displayed under the modal, we would need to work on this first, would you like to?

@dougfabris dougfabris added the contrib: valid A valid contribution where maintainers will review based on priority label Feb 11, 2026
@Naetiksoni08
Copy link
Author

@dougfabris Thanks for the feedback. You're right. I’ve identified the issue and will address it. I’ll push the changes and update the PR soon.

@Naetiksoni08
Copy link
Author

Hi @dougfabris , I'm thinking of replacing the toast with an inline form error using react-hook-form's setError, so the error is displayed directly inside the modal. Would that approach work, or would you prefer fixing the toast z-index instead?

@Naetiksoni08 Naetiksoni08 force-pushed the fix/prevent-modal-close-on-error branch from 0cb6dda to 00c828f Compare February 13, 2026 10:12
Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
apps/meteor/client/navbar/NavBarPagesGroup/actions/CreateChannelModal.tsx (1)

106-126: ⚠️ Potential issue | 🟡 Minor

Stale server error persists across retries — destructure clearErrors too.

root.serverError set via setError is not automatically cleared by react-hook-form on resubmission. If the user clicks "Create" again after a failure, the old error message remains visible throughout the new request. Destructure clearErrors here and call it at the top of handleCreateChannel.

Proposed fix
 	const {
 		register,
 		formState: { errors },
 		handleSubmit,
 		control,
 		setValue,
 		setError,
+		clearErrors,
 		watch,
 	} = useForm({

Then at the start of handleCreateChannel:

 const handleCreateChannel = async ({ name, members, readOnly, topic, broadcast, encrypted, federated }: CreateChannelModalPayload) => {
+		clearErrors('root.serverError');
 		let roomData;
🧹 Nitpick comments (1)
apps/meteor/client/navbar/NavBarPagesGroup/actions/CreateChannelModal.tsx (1)

407-413: Consider adding top margin for visual separation from the accordion.

This Field sits directly after the Accordion with no spacing. Other field groups use mbe={24}. A small margin (e.g., mbs={16}) would prevent the error from visually colliding with the accordion panel.

Suggested tweak
-			{errors?.root?.serverError ? (
-				<Field>
+			{errors?.root?.serverError ? (
+				<Field mbs={16}>
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 0cb6dda and 00c828f.

📒 Files selected for processing (2)
  • apps/meteor/client/navbar/NavBarPagesGroup/actions/CreateChannelModal.tsx
  • apps/meteor/client/navbar/NavBarPagesGroup/actions/CreateTeamModal.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/client/navbar/NavBarPagesGroup/actions/CreateTeamModal.tsx
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/client/navbar/NavBarPagesGroup/actions/CreateChannelModal.tsx
🔇 Additional comments (1)
apps/meteor/client/navbar/NavBarPagesGroup/actions/CreateChannelModal.tsx (1)

191-196: Error handling approach looks good.

Using setError('root.serverError', ...) to surface the API error inline is a solid approach that addresses the reviewer feedback about toast z-index. The instanceof Error guard with a fallback message is appropriate for the untyped catch.

✏️ Tip: You can disable this entire section by setting review_details to false in your review settings.

@Naetiksoni08
Copy link
Author

Hi there, thanks for the contribution 🚀

I see this as a nice improvement, but in that case the toast will be displayed under the modal, we would need to work on this first, would you like to?

Hi @dougfabris, I've addressed the toast visibility issue and updated the PR as discussed. Instead of fixing the z-index, I replaced the toast with an inline form error using react-hook-form’s setError. The error now displays directly inside the modal, which is cleaner and avoids any z-index concerns entirely. Please take a look!

Screenshot 2026-02-13 at 3 24 40 PM

@Naetiksoni08
Copy link
Author

hey @dougfabris, just following up on pr #38611 I've addressed the requested changes.
Could you please take another look when you get a chance?

@ggazzo ggazzo added this to the 8.2.0 milestone Feb 18, 2026
@ggazzo
Copy link
Member

ggazzo commented Feb 18, 2026

/jira ARCH-1935

@dougfabris
Copy link
Member

@Naetiksoni08 as we use toast messages to display generic errors I would suggest raising a separate PR to display the toasts over modal. I'm not sure, but maybe it's just a matter of replacing their position in DOM, so I would start investigating from there

@codecov
Copy link

codecov bot commented Feb 18, 2026

Codecov Report

❌ Patch coverage is 15.38462% with 22 lines in your changes missing coverage. Please review.
✅ Project coverage is 70.47%. Comparing base (f59bc92) to head (00c828f).
⚠️ Report is 11 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #38611      +/-   ##
===========================================
- Coverage    70.48%   70.47%   -0.02%     
===========================================
  Files         3174     3174              
  Lines       111075   111095      +20     
  Branches     19991    20051      +60     
===========================================
+ Hits         78293    78294       +1     
- Misses       30740    30756      +16     
- Partials      2042     2045       +3     
Flag Coverage Δ
unit 71.43% <15.38%> (-0.03%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Naetiksoni08
Copy link
Author

@Naetiksoni08 as we use toast messages to display generic errors I would suggest raising a separate PR to display the toasts over modal. I'm not sure, but maybe it's just a matter of replacing their position in DOM, so I would start investigating from there

Thanks for the feedback @dougfabris! That makes sense - I'll revert the inline error changes and keep this PR focused on just preventing the modal from closing on failure.

I'll investigate the toast positioning issue separately and raise a new PR for that. I'll look into the DOM hierarchy approach you mentioned.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
apps/meteor/client/navbar/NavBarPagesGroup/actions/CreateChannelModal.tsx (1)

106-112: Disable the Create button during submission to prevent duplicate channel creation.

Before this fix, the finally block closed the modal immediately, so in-flight re-clicks were never observable. Now that the modal stays open on error, there is a window where a user can re-click Create while the first request is still in flight, resulting in a concurrent duplicate channels.create / groups.create call. isSubmitting from formState indicates whether the form is currently being submitted and is the idiomatic way to dynamically disable the submit button. Since errors are already caught in the try/catch, isSubmitting will correctly reset to false after the error path resolves.

♻️ Proposed fix
 const {
   register,
-  formState: { errors },
+  formState: { errors, isSubmitting },
   handleSubmit,
   control,
   setValue,
   watch,
 } = useForm({
-  <Button type='submit' primary>
+  <Button type='submit' primary disabled={isSubmitting}>
     {t('Create')}
   </Button>

Also applies to: 407-409

🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.

In `@apps/meteor/client/navbar/NavBarPagesGroup/actions/CreateChannelModal.tsx`
around lines 106 - 112, The form destructuring should include isSubmitting from
formState and the Create button must be disabled while the form is submitting:
add isSubmitting to the destructure (alongside register, formState: { errors },
handleSubmit, control, setValue, watch) and update the submit button rendering
used in CreateChannelModal (and the similar button at the other occurrence) to
set disabled={isSubmitting} (or equivalent) so users cannot trigger duplicate
channels.create / groups.create calls while a submission is in flight.
📜 Review details

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 00c828f and 5cff527.

📒 Files selected for processing (2)
  • apps/meteor/client/navbar/NavBarPagesGroup/actions/CreateChannelModal.tsx
  • apps/meteor/client/navbar/NavBarPagesGroup/actions/CreateTeamModal.tsx
🚧 Files skipped from review as they are similar to previous changes (1)
  • apps/meteor/client/navbar/NavBarPagesGroup/actions/CreateTeamModal.tsx
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{ts,tsx,js}

📄 CodeRabbit inference engine (.cursor/rules/playwright.mdc)

**/*.{ts,tsx,js}: Write concise, technical TypeScript/JavaScript with accurate typing in Playwright tests
Avoid code comments in the implementation

Files:

  • apps/meteor/client/navbar/NavBarPagesGroup/actions/CreateChannelModal.tsx
🔇 Additional comments (1)
apps/meteor/client/navbar/NavBarPagesGroup/actions/CreateChannelModal.tsx (1)

187-189: LGTM — onClose() correctly gated to the success path.

Sequencing reload?.() then onClose() inside the try block, with the finally removed, is the minimal and correct fix: the modal now stays open (and form data is preserved) when the API call fails.

🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.

Nitpick comments:
In `@apps/meteor/client/navbar/NavBarPagesGroup/actions/CreateChannelModal.tsx`:
- Around line 106-112: The form destructuring should include isSubmitting from
formState and the Create button must be disabled while the form is submitting:
add isSubmitting to the destructure (alongside register, formState: { errors },
handleSubmit, control, setValue, watch) and update the submit button rendering
used in CreateChannelModal (and the similar button at the other occurrence) to
set disabled={isSubmitting} (or equivalent) so users cannot trigger duplicate
channels.create / groups.create calls while a submission is in flight.

@Naetiksoni08
Copy link
Author

Hey @dougfabris , as suggested I've raised a separate PR to display toasts above modals: #38870

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

contrib: valid A valid contribution where maintainers will review based on priority

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Prevent modal from closing when team/channel creation fails

5 participants