Skip to content

fix(ui): prevent app crash when import type is an object#41570

Open
SrijanGupta2006 wants to merge 2 commits into
RocketChat:developfrom
SrijanGupta2006:fix-import-object-crash
Open

fix(ui): prevent app crash when import type is an object#41570
SrijanGupta2006 wants to merge 2 commits into
RocketChat:developfrom
SrijanGupta2006:fix-import-object-crash

Conversation

@SrijanGupta2006

@SrijanGupta2006 SrijanGupta2006 commented Jul 25, 2026

Copy link
Copy Markdown

Proposed changes (including videos or screenshots)

Added a safeguard in the ImportOperationSummary component to check the data type of the type prop before rendering it in the table cell. If it receives an object, it now uses JSON.stringify() to safely display it, preventing the application from crashing with an "Objects are not valid as a React child" error on narrow viewports.

BEFORE: The application crashes completely when the component attemtps to render an object.
Screenshot 2026-07-25 at 5 27 52 PM

AFTER: The UI remains stable, and the object is safely stringified in the table cell.
Screenshot 2026-07-25 at 5 28 18 PM

Issue(s)

Fixes #29509

Steps to test or reproduce

  1. Start the Rocket.Chat local development server.
  2. Open the file apps/meteor/client/views/admin/import/ImportOperationSummary.tsx.
  3. Temporarily inject a dummy object into the total or type props at the top of the component (e.g., total = { _isPromise: true } as any;).
  4. Navigate to Administration -> Workspace -> Import in the browser.
  5. Ensure the browser window is wider than 768px so the total column renders.
  6. Observe that without this PR, the application throws a fatal Objects are not valid as a React child error. With this PR, the object is safely stringified and the UI remains stable.

Further comments

Issue #29509 indicates that an unresolved Promise/object is occasionally being passed from the backend to the total field during the "Download Pending Avatars" phase of a Slack import. While the root cause likely lies in the backend importer logic, this PR adds a defensive frontend safeguard. By checking if type or total are objects and safely stringifying them, we prevent a complete React Error Boundary crash, ensuring the rest of the Admin UI remains accessible to the user.

Review in cubic

Summary by CodeRabbit

  • Bug Fixes
    • Improved import operation summaries so operation types and totals display correctly even when they contain structured values.
    • Preserved row actions such as selection and click behavior for actionable import operations.
    • Prevented display errors caused by unexpected data formats.

@SrijanGupta2006
SrijanGupta2006 requested a review from a team as a code owner July 25, 2026 12:00
@dionisio-bot

dionisio-bot Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

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 missing the required milestone or project

Please fix the issues and try again

If you have any trouble, please check the PR guidelines

@changeset-bot

changeset-bot Bot commented Jul 25, 2026

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 24ac019

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

coderabbitai Bot commented Jul 25, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

Import operation summaries now safely render non-string type and object-valued total data, while passing conditional row interaction properties through TableRow’s props object.

Changes

Import summary rendering

Layer / File(s) Summary
Defensive summary row rendering
apps/meteor/client/views/admin/import/ImportOperationSummary.tsx
Interactive TableRow properties are provided through the computed props object, and type and total values are JSON-stringified when necessary for rendering.

Estimated code review effort: 2 (Simple) | ~10 minutes

Suggested labels: type: bug

Suggested reviewers: tassoevan

🚥 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 is specific and matches the main fix: preventing an import-page crash when type is an object.
Linked Issues check ✅ Passed The changes defensively render import type and total, which addresses the import-history React crash on desktop views.
Out of Scope Changes check ✅ Passed The TableRow prop cleanup and safe rendering changes are tied to the import summary crash fix, with no unrelated additions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

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.

@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.

Actionable comments posted: 1

🤖 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.

Inline comments:
In `@apps/meteor/client/views/admin/import/ImportOperationSummary.tsx`:
- Line 109: Normalize total and all sibling counter fields before they reach the
ImportOperationSummary render, resolving pending values and converting
object-wrapped counters into usable numeric or string values. Update the data
preparation branches feeding ImportOperationSummary rather than relying on the
TableCell’s JSON.stringify fallback, while preserving the existing displayed
counter values.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 119aed53-57e4-47d0-89dd-78bfda277c66

📥 Commits

Reviewing files that changed from the base of the PR and between 6dc66fb and 24ac019.

📒 Files selected for processing (1)
  • apps/meteor/client/views/admin/import/ImportOperationSummary.tsx
📜 Review details
🧰 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/views/admin/import/ImportOperationSummary.tsx
🧠 Learnings (2)
📚 Learning: 2026-03-27T14:52:56.865Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39892
File: apps/meteor/client/views/room/contextualBar/Threads/Thread.tsx:150-155
Timestamp: 2026-03-27T14:52:56.865Z
Learning: In Rocket.Chat, there are two different `ModalBackdrop` components with different prop APIs. During review, confirm the import source: (1) `rocket.chat/fuselage` `ModalBackdrop` uses `ModalBackdropProps` based on `BoxProps` (so it supports `onClick` and other Box/DOM props) and does not have an `onDismiss` prop; (2) `rocket.chat/ui-client` `ModalBackdrop` uses a narrower props interface like `{ children?: ReactNode; onDismiss?: () => void }` and handles Escape keypress and outside mouse-up, and it does not forward arbitrary DOM props such as `onClick`. Flag mismatched props (e.g., `onDismiss` passed to the fuselage component or `onClick` passed to the ui-client component) and ensure the usage matches the correct component being imported.

Applied to files:

  • apps/meteor/client/views/admin/import/ImportOperationSummary.tsx
📚 Learning: 2026-05-06T12:21:44.083Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 40256
File: apps/meteor/client/components/CreateDiscussion/CreateDiscussion.tsx:121-149
Timestamp: 2026-05-06T12:21:44.083Z
Learning: Field wrappers in rocket.chat/fuselage-forms (Field, FieldLabel, FieldRow, FieldError, FieldHint) auto-create htmlFor/id associations, aria-describedby, and role="alert" for errors. Do not manually set htmlFor, id, aria-describedby, or role attributes when using these wrappers. This automatic wiring does not apply to plain rocket.chat/fuselage components, which require explicit ID wiring per the accessibility docs. In code reviews, prefer using fuselage-forms wrappers for form fields and verify there is no unnecessary manual ID/aria wiring in files that use these wrappers. If a component uses plain fuselage components, ensure proper id wiring as per docs.

Applied to files:

  • apps/meteor/client/views/admin/import/ImportOperationSummary.tsx
🔇 Additional comments (2)
apps/meteor/client/views/admin/import/ImportOperationSummary.tsx (2)

90-98: LGTM!


99-99: 🗄️ Data Integrity & Integration

No change needed.

IImport defines type as string and count.total as number; ImportOperationSummaryProps matches that contract.

			> Likely an incorrect or invalid review comment.

<TableCell align='center'>{channels}</TableCell>
<TableCell align='center'>{messages}</TableCell>
<TableCell align='center'>{total}</TableCell>
<TableCell align='center'>{typeof total === 'object'?JSON.stringify(total):total}</TableCell>

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.

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Locate file:"
fd -a 'ImportOperationSummary\.tsx$' . || true

file="$(fd 'ImportOperationSummary\.tsx$' . | head -n1 || true)"
if [ -n "${file:-}" ]; then
  echo "File: $file"
  wc -l "$file"
  echo "--- outline ---"
  ast-grep outline "$file" || true
  echo "--- relevant lines 1-160 ---"
  sed -n '1,160p' "$file" | cat -n
fi

echo "--- Search for total usage / import summary producers ---"
rg -n "total|ImportOperationSummary|JSON\.stringify\(total\)|Promise\.resolve|0\[object Promise\]" . -g '*.{ts,tsx,js}' -S

Repository: RocketChat/Rocket.Chat

Length of output: 50379


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "Behavioral probes for current rendering candidates"
node - <<'JS'
const values = [1, "ok", Promise.resolve(1), Promise.resolve(null), null, undefined, 0n];
for (const total of values) {
  try {
    const child = typeof total === 'object' ? JSON.stringify(total) : total;
    console.log(JSON.stringify({
      input: total === undefined ? 'undefined' : total === null ? 'null' : typeof total,
      json: child === undefined ? 'undefined' : child === null ? 'null' : child
    }));
  } catch (e) {
    console.log(JSON.stringify({ input: typeof total, error: e.toString() }));
  }
}
JS

Repository: RocketChat/Rocket.Chat

Length of output: 482


🏁 Script executed:

#!/bin/bash
set -euo pipefail

target="$(fd 'ImportOperationSummary\.tsx$' . | head -n1 || true)"
if [ -z "${target:-}" ]; then
  echo "Target file not found"
  exit 0
fi

echo "Target: $target"
wc -l "$target"
echo "--- relevant lines 1-160 ---"
sed -n '1,160p' "$target" | cat -n

echo "--- focused imports/usages around ImportOperationSummary ---"
rg -n "ImportOperationSummary|import.*ImportOperation|Total|import.*Total|importTotal|total.*Promise|Promise.*total|0\\[object Promise\\]" apps/meteor/client apps/meteor/server -S \
  --iglob '*.{ts,tsx,js}' --max-count 220

echo "--- list candidate files under import summaries ---"
fd -i 'import|Import' apps/meteor/client apps/meteor/server -e ts -e tsx -e js -e jsp | sed -n '1,120p'

echo "--- git diff stat/name-only ---"
git diff --stat || true
git diff --name-only || true

Repository: RocketChat/Rocket.Chat

Length of output: 40211


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "--- GetLatestImportOperations implementation ---"
method_file="$(fd 'getLatestImportOperations\.ts$' apps/meteor/server/meteor-methods/import | head -n1 || true)"
if [ -n "${method_file:-}" ]; then
  wc -l "$method_file"
  sed -n '1,220p' "$method_file" | cat -n
fi

echo "--- ImportHistoryPage usage of currentOperation.data ---"
sed -n '140,200p' apps/meteor/client/views/admin/import/ImportHistoryPage.tsx | cat -n

echo "--- import data type definitions for progress/count data ---"
rg -n "IImportOperation|ImportOperation|addCountToTotal|progress\\.count\\.total|progress\\.count|increaseTotalCount|totalCount" apps/meteor/server/lib/import apps/meteor/server/services/import apps/meteor/server/meteor-methods/import app/importer apps/meteor -g '*.{ts,tsx,js}' -S \
  | sed -n '1,240p'

Repository: RocketChat/Rocket.Chat

Length of output: 34715


Render ImportOperationSummary with normalized counters.

The current rendering path passes raw operation data into the summary through several branches, so JSON.stringify(total) can hide unresolved values as {} or show values like 0[object Promise] unchanged. Ensure total (and the sibling counter fields) is normalized to a numeric/string value before rendering.

🤖 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 `@apps/meteor/client/views/admin/import/ImportOperationSummary.tsx` at line
109, Normalize total and all sibling counter fields before they reach the
ImportOperationSummary render, resolving pending values and converting
object-wrapped counters into usable numeric or string values. Update the data
preparation branches feeding ImportOperationSummary rather than relying on the
TableCell’s JSON.stringify fallback, while preserving the existing displayed
counter values.

@cubic-dev-ai cubic-dev-ai 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.

No issues found across 1 file

Re-trigger cubic

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.

Imports page has Application Error after Download Pending Avatars

1 participant