Skip to content

fix: prevent React state mutation by spreading envelope.recipients before sort - #2839

Merged
dguyen merged 2 commits into
documenso:mainfrom
Abzaek:fix/envelope-recipients-sort-mutation
May 26, 2026
Merged

dguyen merged 2 commits into
documenso:mainfrom
Abzaek:fix/envelope-recipients-sort-mutation

Conversation

@Abzaek

@Abzaek Abzaek commented May 20, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes bug #1 from the Faultmark scan (issue #2829): envelope.recipients.sort() was called directly on the React state object inside a useMemo, permanently mutating it in-place.

Root cause

const sortedRecipients = envelope.recipients.sort((a, b) => ...) on line 297 sorted the array in-place, corrupting the React state. After the first render with sequential signing enabled, selectedAssistantRecipient and assistantRecipients would produce incorrect results.

Fix

Changed to [...envelope.recipients].sort(...) — creating a shallow copy before sorting, leaving the original state array unmodified.

Verification

  • TypeScript compiles cleanly with npx tsc --noEmit

Partially addresses #2829

…fore sort

Bug #1 from Faultmark scan (issue documenso#2829): nextRecipient useMemo sorted
envelope.recipients in-place, permanently mutating the React state object.
After the first render, all downstream logic including selectedAssistantRecipient
and assistantRecipients produced incorrect results.

Fix: Spread envelope.recipients into a new array before sorting.
Signed-off-by: Abdulazez A. <[email protected]>
@vercel

vercel Bot commented May 20, 2026 •

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

3 Skipped Deployments
Project Deployment Actions Updated (UTC)
prd-docs Ignored Ignored May 22, 2026 11:01am
prd-openpage-api Ignored Ignored May 22, 2026 11:01am
stg-docs Skipped Skipped May 22, 2026 11:01am

Request Review

@coderabbitai

coderabbitai Bot commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Important

Review skipped

Auto reviews are limited based on label configuration.

🏷️ Required labels (at least one) (1)
  • coderabbit

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 496235b5-5752-48a5-9a18-a5c4719ee979

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@vercel
vercel Bot temporarily deployed to Preview – stg-docs May 20, 2026 23:01 Inactive
@Mythie

Mythie commented May 20, 2026

Copy link
Copy Markdown
Collaborator

Hey there, it looks like you haven't accepted our contributor license agreement yet. In order for us to accept your pull request we ask that you please fill out the CLA:

https://documen.so/cla

@vercel
vercel Bot temporarily deployed to Preview – stg-docs May 22, 2026 11:01 Inactive

@dguyen dguyen left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks

@dguyen
dguyen merged commit fa2c53b into documenso:main May 26, 2026
8 of 10 checks passed
scoobs-mystery-bytes pushed a commit to scoobs-mystery-bytes/documenso that referenced this pull request May 30, 2026

This branch was previously deployed

1 inactive deployment
Preview – stg-docs — 3c101c6a Deployed May 22, 2026 by vercel[bot]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants