Skip to content

Conversation

@aleksandernsilva
Copy link
Contributor

@aleksandernsilva aleksandernsilva commented Oct 6, 2025

Proposed changes (including videos or screenshots)

Fixes an issue causing the GUI to crash when editing users with custom fields.

The crash occurred when a custom field had an invalid type. The React component responsible for rendering these fields failed to handle invalid types, leading to a rendering error.

Solution

  • Added validation to skip rendering custom fields with invalid types, preventing the crash.
  • Added unit tests for the component, including scenarios with invalid field types.
  • Added an E2E test case to ensure custom fields with invalid types are not rendered and the UI remains stable.

Issue(s)

CORE-1313

Steps to test or reproduce

  • Workspace > Settings > Accounts > Registration
  • Set a custom field json with an invalid type
  • Workspace > Users
  • Edit an user
  • GUI will crash

Further comments

A separate PR refactoring the CustomFieldForm will be opened with more improvements, including recent best practices, error boundary, etc.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed a crash on the Admin > Users page when an invalid custom field is configured. Invalid fields are now ignored while valid fields continue to render.
  • Refactor

    • Improved form labeling and error handling for clearer messages and better accessibility; errors are shown only when present.
  • Tests

    • Added end-to-end and component tests covering invalid custom field types, required/min/max validation, and rendering of text/select fields.
  • Chores

    • Updated dependencies to the latest patch versions.

@changeset-bot
Copy link

changeset-bot bot commented Oct 6, 2025

🦋 Changeset detected

Latest commit: 77f158b

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 42 packages
Name Type
@rocket.chat/meteor Patch
@rocket.chat/ui-client Patch
@rocket.chat/gazzodown Patch
@rocket.chat/ui-voip Patch
@rocket.chat/web-ui-registration Patch
@rocket.chat/fuselage-ui-kit Patch
@rocket.chat/livechat Patch
@rocket.chat/uikit-playground Patch
@rocket.chat/core-typings Patch
@rocket.chat/rest-typings Patch
@rocket.chat/api-client Patch
@rocket.chat/apps Patch
@rocket.chat/core-services Patch
@rocket.chat/cron Patch
@rocket.chat/ddp-client Patch
@rocket.chat/freeswitch Patch
@rocket.chat/http-router Patch
@rocket.chat/model-typings Patch
@rocket.chat/ui-avatar Patch
@rocket.chat/ui-contexts Patch
@rocket.chat/account-service Patch
@rocket.chat/authorization-service Patch
@rocket.chat/ddp-streamer Patch
@rocket.chat/federation-service Patch
@rocket.chat/omnichannel-transcript Patch
@rocket.chat/presence-service Patch
@rocket.chat/queue-worker Patch
@rocket.chat/stream-hub-service Patch
@rocket.chat/federation-matrix Patch
@rocket.chat/license Patch
@rocket.chat/media-calls Patch
@rocket.chat/omnichannel-services Patch
@rocket.chat/pdf-worker Patch
@rocket.chat/presence Patch
rocketchat-services Patch
@rocket.chat/models Patch
@rocket.chat/network-broker Patch
@rocket.chat/omni-core-ee Patch
@rocket.chat/mock-providers Patch
@rocket.chat/ui-video-conf Patch
@rocket.chat/instance-status Patch
@rocket.chat/omni-core Patch

Not sure what this means? Click here to learn what changesets are.

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

@dionisio-bot
Copy link
Contributor

dionisio-bot bot commented Oct 6, 2025

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

  • This PR is targeting the wrong base branch. It should target 7.12.0, but it targets 7.11.0

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Oct 6, 2025

Walkthrough

Adds a dependency patch changeset and release note for an admin GUI crash. Updates CustomFieldsForm to safely skip invalid custom field types and refine label/ARIA handling. Introduces component unit tests and an end-to-end test to verify that invalid custom fields are not rendered while valid ones are shown.

Changes

Cohort / File(s) Summary
Release note and dependency bumps
\.changeset/beige-planets-suffer.md
Adds changeset patching @rocket.chat/meteor and @rocket.chat/ui-client; documents admin page crash fix for invalid custom field rendering.
UI custom fields form logic and tests
packages/ui-client/src/components/CustomFieldsForm.tsx, packages/ui-client/src/components/CustomFieldsForm.spec.tsx
Adds guard to skip unavailable field types; restructures label/id/ARIA wiring; conditionally renders error messages; passes label via prop; adds tests for text/select rendering, validation, and invalid type handling.
E2E admin users invalid custom field test
apps/meteor/tests/e2e/admin-users-custom-fields.spec.ts
Adds E2E suite ensuring invalid-type custom fields are not rendered while valid fields remain visible in the admin user edit form.

Sequence Diagram(s)

sequenceDiagram
  autonumber
  participant Admin as Admin User
  participant UI as Admin UI (Users)
  participant Form as CustomFieldsForm
  participant Meta as Custom Fields Metadata

  Admin->>UI: Open user edit form
  UI->>Meta: Load custom fields metadata
  Meta-->>UI: Field definitions (types, labels, rules)
  UI->>Form: Render with metadata
  loop For each field
    Form->>Form: Resolve field component by type
    alt Valid type
      Form->>UI: Render input with label/id and ARIA
      note right of Form: aria-labelledby set to label id<br/>aria-describedby set only on error
    else Invalid type
      Form->>Form: Skip rendering (no throw)
      note right of Form: Guard: render nothing
    end
  end
  Admin->>UI: Interact/validate
  UI-->>Admin: Form renders without crash
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested labels

stat: ready to merge, stat: QA assured

Suggested reviewers

  • ggazzo
  • scuciatto

Poem

A hop, a skip, I twitch my ear—
The fields were odd, but now they’re clear.
Invalid types? I’ll let them pass;
No crash today upon the glass.
I thump with joy, forms render right—
Carrot-coded, bug in flight! 🥕✨

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Out of Scope Changes Check ⚠️ Warning The PR introduces broader refactoring of accessibility attributes, label management, and expanded validation tests for required fields, minLength, and maxLength behaviors that were not specified in the CORE-1313 issue or the PR objectives, thus extending beyond the narrow bug fix scope. Please isolate the bug fix and its associated tests for handling invalid custom field types in this PR and defer the accessibility refactors and expanded coverage for valid field behaviors to a separate follow-up PR.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The pull request title “fix: User admin GUI crash when rendering an invalid custom field type” concisely and accurately describes the primary change, namely preventing a crash when encountering an invalid custom field, and clearly signals the nature of the bug and its context within the admin UI.
Linked Issues Check ✅ Passed The changes implement a guard to skip rendering invalid custom fields, include unit tests simulating invalid type scenarios in CustomFieldsForm, and provide an E2E test ensuring stability of the admin user form, thereby addressing the crash described in CORE-1313.
Docstring Coverage ✅ Passed No functions found in the changes. Docstring coverage check skipped.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/user-custom-fields

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.

@codecov
Copy link

codecov bot commented Oct 6, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 67.38%. Comparing base (e64c9a8) to head (77f158b).
⚠️ Report is 1 commits behind head on develop.

Additional details and impacted files

Impacted file tree graph

@@             Coverage Diff             @@
##           develop   #37154      +/-   ##
===========================================
- Coverage    67.39%   67.38%   -0.01%     
===========================================
  Files         3286     3287       +1     
  Lines       111584   111684     +100     
  Branches     20377    20408      +31     
===========================================
+ Hits         75197    75256      +59     
- Misses       33695    33739      +44     
+ Partials      2692     2689       -3     
Flag Coverage Δ
e2e 57.29% <ø> (+<0.01%) ⬆️
unit 71.40% <100.00%> (-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.

@aleksandernsilva aleksandernsilva changed the title fix: Invalid custom field type causes the user admin GUI to crash fix: User admin GUI crash when rendering an invalid custom field type Oct 6, 2025
Fixes a GUI crash happening in the admin user page when attempting to display an invalid custom field
@aleksandernsilva aleksandernsilva marked this pull request as ready for review October 7, 2025 17:01
@aleksandernsilva aleksandernsilva requested a review from a team as a code owner October 7, 2025 17:01
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.

Actionable comments posted: 1

🧹 Nitpick comments (1)
apps/meteor/tests/e2e/admin-users-custom-fields.spec.ts (1)

145-161: Isolate the invalid custom field test by using a fresh user
The test in with invalid custom field type (lines 145–161) reuses addTestUser shared with earlier tests, risking cross‐test state leakage; wrap it in a local beforeAll/afterAll to create and delete its own test user.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

Disabled knowledge base sources:

  • Jira integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 46f8110 and fda72e9.

📒 Files selected for processing (4)
  • .changeset/beige-planets-suffer.md (1 hunks)
  • apps/meteor/tests/e2e/admin-users-custom-fields.spec.ts (1 hunks)
  • packages/ui-client/src/components/CustomFieldsForm.spec.tsx (1 hunks)
  • packages/ui-client/src/components/CustomFieldsForm.tsx (3 hunks)
🧰 Additional context used
📓 Path-based instructions (3)
apps/meteor/tests/e2e/**/*.spec.ts

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

apps/meteor/tests/e2e/**/*.spec.ts: All Playwright test files must be located under apps/meteor/tests/e2e/ and use the .spec.ts extension (e.g., login.spec.ts)
Use descriptive test names that clearly communicate expected behavior
Use test.beforeAll() and test.afterAll() for setup and teardown
Use test.step() to organize complex test scenarios
Group related tests in the same file
Utilize Playwright fixtures (test, page, expect) consistently
Prefer web-first assertions (e.g., toBeVisible, toHaveText)
Use expect matchers (toEqual, toContain, toBeTruthy, toHaveLength, etc.) instead of assert statements
Maintain test isolation between test cases
Ensure a clean state for each test execution
Ensure tests run reliably in parallel without shared state conflicts

Files:

  • apps/meteor/tests/e2e/admin-users-custom-fields.spec.ts
apps/meteor/tests/e2e/**/*.{ts,tsx,js,jsx}

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

apps/meteor/tests/e2e/**/*.{ts,tsx,js,jsx}: Write concise, technical TypeScript/JavaScript with accurate typing
Follow DRY by extracting reusable logic into helper functions or page objects
Avoid code comments in the implementation

Files:

  • apps/meteor/tests/e2e/admin-users-custom-fields.spec.ts
apps/meteor/tests/e2e/**/*.{ts,tsx}

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

apps/meteor/tests/e2e/**/*.{ts,tsx}: Avoid using page.locator(); prefer semantic locators like page.getByRole, page.getByLabel, page.getByText, and page.getByTitle
Store commonly used locators in variables/constants for reuse
Use page.waitFor() with specific conditions and avoid hardcoded timeouts
Implement proper wait strategies for dynamic content
Follow the Page Object Model pattern consistently

Files:

  • apps/meteor/tests/e2e/admin-users-custom-fields.spec.ts
🧠 Learnings (1)
📚 Learning: 2025-09-16T22:08:51.490Z
Learnt from: CR
PR: RocketChat/Rocket.Chat#0
File: .cursor/rules/playwright.mdc:0-0
Timestamp: 2025-09-16T22:08:51.490Z
Learning: Applies to apps/meteor/tests/e2e/**/*.spec.ts : Use descriptive test names that clearly communicate expected behavior

Applied to files:

  • apps/meteor/tests/e2e/admin-users-custom-fields.spec.ts
🧬 Code graph analysis (1)
packages/ui-client/src/components/CustomFieldsForm.spec.tsx (2)
packages/mock-providers/src/index.ts (1)
  • mockAppRoot (3-3)
packages/ui-client/src/components/CustomFieldsForm.tsx (1)
  • CustomFieldsForm (105-111)
🔇 Additional comments (8)
.changeset/beige-planets-suffer.md (1)

1-6: LGTM!

The changeset follows the correct format and clearly describes the GUI crash fix for invalid custom field types.

packages/ui-client/src/components/CustomFieldsForm.tsx (5)

67-69: LGTM!

The guard prevents rendering and subsequent crashes when an invalid field type is encountered. This is the core fix for the GUI crash issue.


79-81: LGTM!

Using an explicit id on the label (rendered as a span) allows proper ARIA association via aria-labelledby on Line 86. This is a valid accessibility pattern when the label is not a clickable <label> element.


86-87: LGTM!

The ARIA attributes correctly associate the input with its label and conditionally with error messaging. The aria-describedby only includes the error ID when an error message exists, preventing invalid references to non-existent elements.


93-97: LGTM!

Conditionally rendering the error only when errorMessage exists prevents empty error containers in the DOM and aligns with the conditional aria-describedby on Line 87.


107-109: LGTM!

Deriving the label from metadata and providing a fallback to fieldName is cleaner than mutating props inline. This change simplifies the label handling logic.

packages/ui-client/src/components/CustomFieldsForm.spec.tsx (2)

1-31: LGTM!

The test setup properly wraps the component with react-hook-form and provides translation mocking via mockAppRoot. The TestComponent wrapper follows best practices for testing form-controlled components.


128-138: LGTM!

This test validates the critical fix: invalid field types do not crash the component and are not rendered. The test uses expect().not.toThrow() to verify no crash occurs and queryByLabelText().not.toBeInTheDocument() to confirm the field is not rendered.

@dougfabris dougfabris added this to the 7.12.0 milestone Oct 7, 2025
@tassoevan tassoevan added the stat: QA assured Means it has been tested and approved by a company insider label Oct 8, 2025
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Oct 8, 2025
@kodiakhq kodiakhq bot merged commit 085d653 into develop Oct 9, 2025
86 of 88 checks passed
@kodiakhq kodiakhq bot deleted the fix/user-custom-fields branch October 9, 2025 10:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stat: QA assured Means it has been tested and approved by a company insider stat: ready to merge PR tested and approved waiting for merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants