Skip to content

regression: Upload loading state relying on percentage instead of file URL#39780

Merged
dionisio-bot[bot] merged 1 commit intorelease-8.3.0from
reg/percentage-loading
Mar 23, 2026
Merged

regression: Upload loading state relying on percentage instead of file URL#39780
dionisio-bot[bot] merged 1 commit intorelease-8.3.0from
reg/percentage-loading

Conversation

@dougfabris
Copy link
Copy Markdown
Member

@dougfabris dougfabris commented Mar 20, 2026

Proposed changes (including videos or screenshots)

Introduced here #39425

The upload loading state was determined by checking percentage < 100 (or percentage !== 100), which is unreliable. The upload progress could reach 100% from the XHR progress event before the server responds with the actual file URL.

So when the user sends the message quickly enough, the message isn't ready and it silently fails. It was caught during tests in E2E rooms but it can happens in every room depending the state of the connection

Issue(s)

Steps to test or reproduce

Further comments

CORE-1991

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced file upload progress tracking with improved accuracy in progress display and more reliable detection of upload completion
    • Improved handling of upload completion to ensure files are properly recognized as fully uploaded and ready for use
    • Refined loading state indicators to more accurately reflect file upload status and progress throughout the entire upload process

@dionisio-bot
Copy link
Copy Markdown
Contributor

dionisio-bot bot commented Mar 20, 2026

Looks like this PR is ready to merge! 🎉
If you have any trouble, please check the PR guidelines

@changeset-bot
Copy link
Copy Markdown

changeset-bot bot commented Mar 20, 2026

⚠️ No Changeset found

Latest commit: d895805

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
Copy Markdown
Contributor

coderabbitai bot commented Mar 20, 2026

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ada5ad0e-6f15-418e-a840-6a4ae54373cb

📥 Commits

Reviewing files that changed from the base of the PR and between d7325cd and d895805.

📒 Files selected for processing (3)
  • apps/meteor/client/lib/chats/uploads.ts
  • apps/meteor/client/views/room/body/hooks/useFileUpload.ts
  • apps/meteor/client/views/room/composer/messageBox/MessageComposerFileItem.tsx
📜 Recent 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/room/composer/messageBox/MessageComposerFileItem.tsx
  • apps/meteor/client/lib/chats/uploads.ts
  • apps/meteor/client/views/room/body/hooks/useFileUpload.ts
🧠 Learnings (11)
📓 Common learnings
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39425
File: apps/meteor/client/lib/chats/flows/uploadFiles.ts:28-33
Timestamp: 2026-03-12T17:12:49.121Z
Learning: Rocket.Chat — apps/meteor/client/lib/chats/flows/uploadFiles.ts: When E2E_Enable_Encrypt_Files is disabled, plaintext file uploads are allowed in E2E rooms; this fallback is expected and should not be flagged as a security regression.
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 32703
File: apps/meteor/client/lib/chats/flows/uploadFiles.ts:52-58
Timestamp: 2026-02-12T15:39:28.416Z
Learning: In `apps/meteor/client/lib/chats/flows/uploadFiles.ts`, when E2E encryption is required but not allowed (e.g., `E2E_Enable_Encrypt_Files` setting is disabled), the function intentionally abandons the entire upload queue and displays a toast error. This fail-fast behavior prevents partial uploads when encryption requirements cannot be met and is the expected behavior, not a bug.
📚 Learning: 2026-03-11T18:17:53.972Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39425
File: apps/meteor/client/lib/chats/flows/processMessageUploads.ts:112-119
Timestamp: 2026-03-11T18:17:53.972Z
Learning: In `apps/meteor/client/lib/chats/flows/processMessageUploads.ts`, when sending multiple file uploads, each file is confirmed via its own `/rooms.mediaConfirm/${rid}/${fileId}` call and produces a separate message. Only the first file's confirm payload carries the composed message text (`msg`); all subsequent files receive `msg: ''`. This one-message-per-file behavior is intentional by design — do not flag it as a bug or suggest batching into a single message.

Applied to files:

  • apps/meteor/client/views/room/composer/messageBox/MessageComposerFileItem.tsx
  • apps/meteor/client/lib/chats/uploads.ts
  • apps/meteor/client/views/room/body/hooks/useFileUpload.ts
📚 Learning: 2026-03-12T17:12:49.121Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39425
File: apps/meteor/client/lib/chats/flows/uploadFiles.ts:28-33
Timestamp: 2026-03-12T17:12:49.121Z
Learning: Rocket.Chat — apps/meteor/client/lib/chats/flows/uploadFiles.ts: When E2E_Enable_Encrypt_Files is disabled, plaintext file uploads are allowed in E2E rooms; this fallback is expected and should not be flagged as a security regression.

Applied to files:

  • apps/meteor/client/views/room/composer/messageBox/MessageComposerFileItem.tsx
  • apps/meteor/client/lib/chats/uploads.ts
  • apps/meteor/client/views/room/body/hooks/useFileUpload.ts
📚 Learning: 2026-02-12T15:39:28.416Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 32703
File: apps/meteor/client/lib/chats/flows/uploadFiles.ts:52-58
Timestamp: 2026-02-12T15:39:28.416Z
Learning: In `apps/meteor/client/lib/chats/flows/uploadFiles.ts`, when E2E encryption is required but not allowed (e.g., `E2E_Enable_Encrypt_Files` setting is disabled), the function intentionally abandons the entire upload queue and displays a toast error. This fail-fast behavior prevents partial uploads when encryption requirements cannot be met and is the expected behavior, not a bug.

Applied to files:

  • apps/meteor/client/views/room/composer/messageBox/MessageComposerFileItem.tsx
  • apps/meteor/client/lib/chats/uploads.ts
  • apps/meteor/client/views/room/body/hooks/useFileUpload.ts
📚 Learning: 2026-03-19T13:59:40.678Z
Learnt from: d-gubert
Repo: RocketChat/Rocket.Chat PR: 38357
File: apps/meteor/app/apps/server/converters/uploads.ts:45-49
Timestamp: 2026-03-19T13:59:40.678Z
Learning: In `apps/meteor/app/apps/server/converters/uploads.ts`, the `room` async handler in `convertToApp` uses non-null assertions (`upload.rid!` and `result!`) intentionally. The data flow guarantees that any upload reaching this point must have a `rid`; if it does not, throwing an error is the desired behavior (fail-fast / data integrity guard). Do not flag these non-null assertions as unsafe during code review.

Applied to files:

  • apps/meteor/client/views/room/composer/messageBox/MessageComposerFileItem.tsx
  • apps/meteor/client/lib/chats/uploads.ts
  • apps/meteor/client/views/room/body/hooks/useFileUpload.ts
📚 Learning: 2026-03-11T18:15:53.272Z
Learnt from: dougfabris
Repo: RocketChat/Rocket.Chat PR: 39425
File: apps/meteor/app/api/server/v1/rooms.ts:294-296
Timestamp: 2026-03-11T18:15:53.272Z
Learning: In Rocket.Chat's `rooms.mediaConfirm/:rid/:fileId` endpoint (apps/meteor/app/api/server/v1/rooms.ts), updating `file.name` from `bodyParams.fileName` without updating `file.path` is intentionally safe. The file path is keyed by `_id` (not by filename), so the stored path remains valid regardless of a rename. `file.name` only affects the display name in the message attachment; do not flag this as a path-divergence issue.

Applied to files:

  • apps/meteor/client/views/room/composer/messageBox/MessageComposerFileItem.tsx
  • apps/meteor/client/views/room/body/hooks/useFileUpload.ts
📚 Learning: 2026-03-11T22:04:20.529Z
Learnt from: juliajforesti
Repo: RocketChat/Rocket.Chat PR: 39545
File: apps/meteor/client/views/room/body/hooks/useHasNewMessages.ts:59-61
Timestamp: 2026-03-11T22:04:20.529Z
Learning: In `apps/meteor/client/views/room/body/hooks/useHasNewMessages.ts`, the `msg.u._id === uid` early-return in the `streamNewMessage` handler is intentional: the "New messages" indicator is designed to notify about messages from other users only. Self-sent messages — including those sent from a different session/device — are always skipped, by design. Do not flag this as a multi-session regression.

Applied to files:

  • apps/meteor/client/views/room/composer/messageBox/MessageComposerFileItem.tsx
  • apps/meteor/client/views/room/body/hooks/useFileUpload.ts
📚 Learning: 2026-02-25T20:10:16.987Z
Learnt from: ahmed-n-abdeltwab
Repo: RocketChat/Rocket.Chat PR: 38913
File: packages/ddp-client/src/legacy/types/SDKLegacy.ts:34-34
Timestamp: 2026-02-25T20:10:16.987Z
Learning: In the RocketChat/Rocket.Chat monorepo, packages/ddp-client and apps/meteor do not use TypeScript project references. Module augmentations in apps/meteor (e.g., declare module 'rocket.chat/rest-typings') are not visible when compiling packages/ddp-client in isolation, which is why legacy SDK methods that depend on OperationResult types for OpenAPI-migrated endpoints must remain commented out.

Applied to files:

  • apps/meteor/client/lib/chats/uploads.ts
📚 Learning: 2026-02-10T16:32:42.586Z
Learnt from: tassoevan
Repo: RocketChat/Rocket.Chat PR: 38528
File: apps/meteor/client/startup/roles.ts:14-14
Timestamp: 2026-02-10T16:32:42.586Z
Learning: In Rocket.Chat's Meteor client code, DDP streams use EJSON and Date fields arrive as Date objects; do not manually construct new Date() in stream handlers (for example, in sdk.stream()). Only REST API responses return plain JSON where dates are strings, so implement explicit conversion there if needed. Apply this guidance to all TypeScript files under apps/meteor/client to ensure consistent date handling in DDP streams and REST responses.

Applied to files:

  • apps/meteor/client/lib/chats/uploads.ts
  • apps/meteor/client/views/room/body/hooks/useFileUpload.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In the Rocket.Chat repository, do not reference Biome lint rules in code review feedback. Biome is not used even if biome.json exists; only reference Biome rules if there is explicit, project-wide usage documented. For TypeScript files, review lint implications without Biome guidance unless the project enables Biome rules.

Applied to files:

  • apps/meteor/client/lib/chats/uploads.ts
  • apps/meteor/client/views/room/body/hooks/useFileUpload.ts
📚 Learning: 2026-02-26T19:25:44.063Z
Learnt from: gabriellsh
Repo: RocketChat/Rocket.Chat PR: 38778
File: packages/ui-voip/src/providers/useMediaSession.ts:192-192
Timestamp: 2026-02-26T19:25:44.063Z
Learning: In this repository (RocketChat/Rocket.Chat), Biome lint rules are not used even if a biome.json exists. When reviewing TypeScript files (e.g., packages/ui-voip/src/providers/useMediaSession.ts), ensure lint suggestions do not reference Biome-specific rules. Rely on general ESLint/TypeScript lint rules and project conventions instead.

Applied to files:

  • apps/meteor/client/lib/chats/uploads.ts
  • apps/meteor/client/views/room/body/hooks/useFileUpload.ts
🔇 Additional comments (4)
apps/meteor/client/lib/chats/uploads.ts (2)

155-155: Progress capping to 99% is the right guard against premature completion.

This correctly prevents progress events from driving "done" state before server confirmation.


178-178: Completion is now correctly tied to successful server response.

Updating id, url, and percentage: 100 together aligns state transition with confirmed upload completion.

apps/meteor/client/views/room/body/hooks/useFileUpload.ts (1)

36-36: isUploading now uses the correct completion signal (url).

This removes the percentage-based race and keeps upload state aligned with actual server confirmation.

apps/meteor/client/views/room/composer/messageBox/MessageComposerFileItem.tsx (1)

29-29: Loading state now tracks unresolved uploads correctly.

Basing isLoading on url presence (with !error) is the right fix for the upload completion race.


Walkthrough

Fixes a race condition where upload progress from XHR events could reach 100% before the server responds with the file URL, causing the UI to prematurely mark uploads as complete. The fix caps progress at 99% during upload and only sets it to 100% upon successful server response, with UI checks updated to verify URL presence instead of percentage completion.

Changes

Cohort / File(s) Summary
Upload Progress Handling
apps/meteor/client/lib/chats/uploads.ts
Capped upload percentage at maximum 99 during progress events and explicitly set percentage to 100 upon successful server completion alongside id and url.
Upload State Detection
apps/meteor/client/views/room/body/hooks/useFileUpload.ts, apps/meteor/client/views/room/composer/messageBox/MessageComposerFileItem.tsx
Updated isUploading and isLoading conditions from checking percentage < 100 to checking !upload.url to rely on server confirmation rather than progress metrics.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 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 describes the regression being fixed: shifting upload loading state determination from percentage-based to URL-based to resolve the race condition.
Linked Issues check ✅ Passed The PR directly addresses CORE-1991 by fixing the race condition: capping percentage at 99 during upload, setting percentage to 100 only when URL is available, and updating loading state checks to rely on URL presence instead of percentage.
Out of Scope Changes check ✅ Passed All three file changes are directly focused on fixing the upload loading state regression: updating percentage calculation, and changing loading state determination from percentage to URL presence in two locations.
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.

@dougfabris dougfabris added this to the 8.3.0 milestone Mar 20, 2026
@codecov
Copy link
Copy Markdown

codecov bot commented Mar 20, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 70.56%. Comparing base (e65b176) to head (d895805).
⚠️ Report is 5 commits behind head on release-8.3.0.

Additional details and impacted files

Impacted file tree graph

@@                Coverage Diff                @@
##           release-8.3.0   #39780      +/-   ##
=================================================
+ Coverage          70.48%   70.56%   +0.07%     
=================================================
  Files               3247     3256       +9     
  Lines             115374   115778     +404     
  Branches           21005    21081      +76     
=================================================
+ Hits               81323    81699     +376     
- Misses             31987    32017      +30     
+ Partials            2064     2062       -2     
Flag Coverage Δ
e2e 60.49% <75.00%> (+0.08%) ⬆️
e2e-api 48.11% <ø> (-0.06%) ⬇️
unit 71.08% <ø> (+0.09%) ⬆️

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.

@dougfabris dougfabris changed the base branch from develop to release-8.3.0 March 23, 2026 13:28
@dougfabris dougfabris marked this pull request as ready for review March 23, 2026 13:29
@dougfabris dougfabris requested a review from a team as a code owner March 23, 2026 13:29
Copy link
Copy Markdown
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 3 files

@dougfabris dougfabris added the stat: QA assured Means it has been tested and approved by a company insider label Mar 23, 2026
@dionisio-bot dionisio-bot bot added the stat: ready to merge PR tested and approved waiting for merge label Mar 23, 2026
@dionisio-bot dionisio-bot bot merged commit 332e7d5 into release-8.3.0 Mar 23, 2026
46 checks passed
@dionisio-bot dionisio-bot bot deleted the reg/percentage-loading branch March 23, 2026 15:34
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 type: bug

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants