Skip to content

fix: prevent crash when rendering Section blocks with fields#7423

Open
Shevilll wants to merge 1 commit into
RocketChat:developfrom
Shevilll:fix/uikit-section-fields-render-crash
Open

fix: prevent crash when rendering Section blocks with fields#7423
Shevilll wants to merge 1 commit into
RocketChat:developfrom
Shevilll:fix/uikit-section-fields-render-crash

Conversation

@Shevilll

@Shevilll Shevilll commented Jun 20, 2026

Copy link
Copy Markdown

Proposed changes

Opening a modal or message that contains a Section block with fields (e.g. the ModalSectionSelects view) crashed the app.

Root cause: in app/containers/UIKit/Section.tsx, the Fields sub-component wrapped each field in a React Native <Text>:

<Text style={[styles.text, styles.field, { color: themes[theme].fontDefault }]}>
  {parser.text(field)}
</Text>

parser.text() returns a non-<Text> node (a block/markdown element) for section/select fields, and React Native throws when a non-<Text> child is nested inside a <Text>. The section's main text is already rendered correctly inside a <View> (line 48); the Fields path simply didn't follow the same pattern.

This wraps each field in a <View> instead, matching the existing text rendering. The redundant text-color override — and the now-unused theme/themes/useTheme plumbing (including the theme prop on the IFields interface) — are removed, since parser.text() renders its own styled text.

Issue(s)

Closes #6951

How to test or reproduce

  1. Open a UiKit modal/message that contains a section block with a fields array (the ModalSectionSelects story reproduces it).
  2. Before this change the screen crashes; after it, the fields render normally.

Automated: TZ=UTC pnpm test --testPathPattern='UiKit' — all UiKit suites pass (46 tests). The UiKitModal/UiKitMessage Section snapshots were regenerated to reflect the <Text><View> wrapper change (the inner text node rendered by parser.text() is unchanged). pnpm lint (ESLint + tsc) passes.

Types of changes

  • Bugfix (non-breaking change which fixes an issue)

Checklist

  • I have read the Contributing Guide
  • Lint and unit tests pass locally with my changes
  • I have added/updated tests (regenerated the affected Section snapshots)

Summary by CodeRabbit

  • Refactor
    • Updated field rendering mechanism by removing theme-dependent styling, simplifying the display logic.
    • Streamlined component interfaces to reduce complexity and dependencies in field rendering.

UiKit Section fields were each wrapped in a <Text> element, but parser.text() returns a non-Text node for select/section fields. React Native throws when a non-Text child is nested inside <Text>, so opening a modal or message containing a section with `fields` crashed the app.

Wrap each field in a <View> instead, mirroring how the section's main `text` is already rendered. The redundant text-color override and the now-unused theme plumbing are removed, since parser.text() renders its own styled text.

Snapshots for the UiKit Section stories were regenerated to reflect the wrapper change.

Closes RocketChat#6951
@CLAassistant

CLAassistant commented Jun 20, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@coderabbitai

coderabbitai Bot commented Jun 20, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The IFields interface drops its theme: TSupportedThemes property. In Section.tsx, imports of Text, themes, and useTheme are removed, and the Fields helper is rewritten to render each field as a View instead of a Text, eliminating theme-dependent styling from section field rendering.

Changes

Section Fields Theme Removal

Layer / File(s) Summary
IFields contract and Fields component refactor
app/containers/UIKit/interfaces.ts, app/containers/UIKit/Section.tsx
IFields removes the theme property. Section.tsx removes Text, themes, and useTheme imports; Fields now renders each field as a View and Section no longer passes theme to Fields.

Estimated code review effort

🎯 1 (Trivial) | ⏱️ ~3 minutes

Suggested labels

type: bug

🚥 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 clearly and accurately describes the main fix: preventing a crash when rendering Section blocks with fields by replacing Text with View wrappers.
Linked Issues check ✅ Passed Changes resolve issue #6951 by replacing Text wrapper with View wrapper for fields in Section component, eliminating React Native constraint violation that caused crashes.
Out of Scope Changes check ✅ Passed All changes are directly related to fixing the crash: Section.tsx field rendering structure, IFields interface theme prop removal, and redundant imports/props cleanup are all necessary for the fix.
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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
app/containers/UIKit/Section.tsx (1)

30-30: Remove unnecessary any cast to enforce TypeScript type safety.

The field parameter in the map callback is already properly typed as IText from the readonly IText[] array. Since IText includes an optional type property, the any cast is unnecessary and violates strict TypeScript mode.

Proposed change
-			<View key={`${(field as any).type || 'field'}-${index}`} style={[styles.text, styles.field]}>
+			<View key={`${field.type || 'field'}-${index}`} style={[styles.text, styles.field]}>

Per coding guidelines: "**/*.{ts,tsx}: Use TypeScript for type safety; add explicit type annotations to function parameters and return types" and "**/*.{ts,tsx}: Use TypeScript with strict mode enabled."

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@app/containers/UIKit/Section.tsx` at line 30, The key generation in the View
component contains an unnecessary `(field as any)` cast that violates TypeScript
strict mode. Since the `field` parameter is already properly typed as `IText`
from the array iteration, and the `IText` interface includes an optional `type`
property, remove the `as any` cast and access `field.type` directly in the
template string. Update the line with the key prop to use `${field.type ||
'field'}-${index}` instead of `${(field as any).type || 'field'}-${index}`.

Source: Coding guidelines

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@app/containers/UIKit/Section.tsx`:
- Line 30: The key generation in the View component contains an unnecessary
`(field as any)` cast that violates TypeScript strict mode. Since the `field`
parameter is already properly typed as `IText` from the array iteration, and the
`IText` interface includes an optional `type` property, remove the `as any` cast
and access `field.type` directly in the template string. Update the line with
the key prop to use `${field.type || 'field'}-${index}` instead of `${(field as
any).type || 'field'}-${index}`.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: cf6db105-e7f3-4ee5-969a-41d308792dd8

📥 Commits

Reviewing files that changed from the base of the PR and between 6bbf88a and 5062f39.

⛔ Files ignored due to path filters (2)
  • app/containers/UIKit/__snapshots__/UiKitMessage.test.tsx.snap is excluded by !**/*.snap
  • app/containers/UIKit/__snapshots__/UiKitModal.test.tsx.snap is excluded by !**/*.snap
📒 Files selected for processing (2)
  • app/containers/UIKit/Section.tsx
  • app/containers/UIKit/interfaces.ts
💤 Files with no reviewable changes (1)
  • app/containers/UIKit/interfaces.ts
📜 Review details
🧰 Additional context used
📓 Path-based instructions (5)
**/*.{js,ts,jsx,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{js,ts,jsx,tsx}: Use descriptive names for functions, variables, and classes that clearly convey their purpose
Write comments that explain the 'why' behind code decisions, not the 'what'
Keep functions small and focused on a single responsibility
Use const by default, let when reassignment is needed, and avoid var
Prefer async/await over .then() chains for handling asynchronous operations
Use explicit error handling with try/catch blocks for async operations
Avoid deeply nested code; refactor complex logic into helper functions

Files:

  • app/containers/UIKit/Section.tsx
**/*.{ts,tsx}

📄 CodeRabbit inference engine (AGENTS.md)

**/*.{ts,tsx}: Use TypeScript for type safety; add explicit type annotations to function parameters and return types
Prefer interfaces over type aliases for defining object shapes in TypeScript
Use enums for sets of related constants rather than magic strings or numbers

Use TypeScript with strict mode enabled

Files:

  • app/containers/UIKit/Section.tsx
**/*.{js,jsx,ts,tsx,json}

📄 CodeRabbit inference engine (CLAUDE.md)

Use Prettier formatting with tabs, single quotes, 130 character line width, no trailing commas, and avoid arrow function parentheses

Files:

  • app/containers/UIKit/Section.tsx
**/*.{js,jsx,ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Enforce ESLint rules from @rocket.chat/eslint-config with React, React Native, TypeScript, and Jest plugins

Files:

  • app/containers/UIKit/Section.tsx
app/containers/**/*.{ts,tsx}

📄 CodeRabbit inference engine (CLAUDE.md)

Place reusable UI components in 'app/containers/' directory

Files:

  • app/containers/UIKit/Section.tsx
🧠 Learnings (1)
📚 Learning: 2026-04-30T17:07:51.020Z
Learnt from: diegolmello
Repo: RocketChat/Rocket.Chat.ReactNative PR: 7274
File: app/lib/services/voip/MediaCallEvents.ts:0-0
Timestamp: 2026-04-30T17:07:51.020Z
Learning: In this Rocket.Chat React Native codebase, the ESLint rule `no-void: error` is enforced. When you see a promise returned from an async call that is not awaited (a “floating promise”), do not silence it with the `void somePromise()` pattern. Instead, handle the promise explicitly by attaching `.catch(...)` (or otherwise awaiting/handling the error) so unhandled-rejection risks are addressed in a way that satisfies the existing ESLint configuration.

Applied to files:

  • app/containers/UIKit/Section.tsx

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug: app crashes when opening ModalSectionSelects

2 participants