Skip to content

🗜️ feat: Let Users Toggle Client-Side Image Resizing - #14883

Open
berry-13 wants to merge 16 commits into
devfrom
feat/check-image-upload-compression
Open

🗜️ feat: Let Users Toggle Client-Side Image Resizing#14883
berry-13 wants to merge 16 commits into
devfrom
feat/check-image-upload-compression

Conversation

@berry-13

Copy link
Copy Markdown
Collaborator

Summary

Client-side image resizing has existed since it was added under fileConfig.clientImageResize, but it could only be turned on in librechat.yaml and it defaults to off. Users had no way to enable it for themselves, and admins had no way to express "on for everyone" versus "let people choose".

This adds a Resize images before upload toggle in Settings > Chat > Sending, stored per device in localStorage, and gives the admin config the final say over it:

  • Admin sets clientImageResize.enabled in librechat.yaml → that value wins, and the toggle renders it read-only with an explanation in its info popover.
  • Admin omits enabled → the user's toggle decides. Admin-provided maxWidth, maxHeight, and quality still apply.
  • Neither → off, as before.

The precedence is computed in mergeFileConfig, which now marks the served config enforced when the admin supplied enabled. useClientResize reads that first and falls back to the user's setting.

This also fixes a bug that made the feature inert. shouldResizeImage compared the file size against 10% of a 512MB fallback limit, so it only returned true for images larger than roughly 51MB. Almost nothing is, which meant that even with clientImageResize.enabled: true an ordinary phone photo was uploaded at full size. It now uses a 512KB floor, below which the decode and encode round trip costs more than it saves. resizeImage already returns the original file untouched when the image is within the configured dimensions, so no image is re-encoded needlessly.

A follow-up documentation PR for librechat.ai is still to be submitted, covering the new override semantics.

Change Type

  • New feature (non-breaking change which adds functionality)
  • This change requires a documentation update

Testing

Unit tests cover both halves of the precedence rule and the corrected size gate:

cd packages/data-provider && npx jest file-config.spec.ts
  187 passed, including 5 new cases: no dynamic config, admin config without
  clientImageResize, admin enabled true, admin enabled false, and admin
  parameters supplied without enabled

cd client && npx jest src/hooks/Files/__tests__/useClientResize.spec.tsx \
                     src/utils/__tests__/imageResize.test.ts \
                     src/hooks/Files/__tests__/useFileHandling.test.ts
  21 passed, covering both override directions, parameters without enforcement,
  the default-off case, and the new 512KB threshold

cd client && npx jest src/components/Nav/Settings
  27 suites, 131 passed

npx eslint <changed files>   clean
cd client && npx tsc --noEmit   clean

Manual verification in the browser, in light and dark mode:

  • With no clientImageResize in librechat.yaml, the toggle is interactive. Turning it on writes clientImageResize: "true" to localStorage and the switch reports data-state="checked".
  • With clientImageResize.enabled: false in the config while the user preference was still true, the switch renders unchecked and disabled, and its info popover reads "This setting is managed by your administrator and cannot be changed here."

Test Configuration:

Node v24.16.0, MongoDB, backend and Vite dev server running from the same worktree. The admin override was verified against a throwaway config copy so the shared librechat.yaml was left untouched.

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have made pertinent documentation changes
  • My changes do not introduce new warnings
  • I have written tests demonstrating that my changes are effective or that my feature works
  • Local unit tests pass with my changes

Copilot AI lite review requested due to automatic review settings August 16, 2026 01:53

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d19ea675f5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread client/src/hooks/Files/useClientResize.ts Outdated
Comment thread client/src/utils/imageResize.ts Outdated

Copilot AI 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.

Pull request overview

Adds a user-facing toggle for client-side image resizing (stored per device via localStorage) while allowing admins to enforce a global on/off value via librechat.yaml. The change also fixes a size-gating bug that previously prevented resizing from triggering for typical images.

Changes:

  • Introduces clientImageResize.enforced in merged file config to indicate when admin-supplied enabled should override user preference.
  • Adds a Settings > Chat > Sending toggle (“Resize images before upload”) with enforced/managed UI messaging.
  • Fixes shouldResizeImage gating by switching from a ~51MB effective threshold to a 512KB minimum floor and adds tests for the new behavior.

Reviewed changes

Copilot reviewed 13 out of 13 changed files in this pull request and generated no comments.

Show a summary per file
File Description
packages/data-provider/src/types/files.ts Adds enforced?: boolean to clientImageResize so clients can detect admin override.
packages/data-provider/src/file-config.ts Sets default enforced: false and marks configs as enforced when admin provides enabled.
packages/data-provider/src/file-config.spec.ts Adds unit tests covering admin/user precedence and parameter-only overrides.
librechat.example.yaml Documents admin override semantics vs user-controlled behavior for clientImageResize.enabled.
client/src/utils/imageResize.ts Replaces the ineffective size gate with MIN_RESIZE_BYTES = 512KB and updates shouldResizeImage semantics.
client/src/utils/tests/imageResize.test.ts Adds test cases for the default 512KB threshold and updates existing expectations.
client/src/store/settings.ts Adds a persisted localStorage-backed atom for clientImageResize user preference.
client/src/locales/en/translation.json Adds label + info strings for the new setting and enforced-state messaging.
client/src/hooks/Files/useClientResize.ts Implements enforced-vs-user precedence and removes any-based config access.
client/src/hooks/Files/index.ts Re-exports useClientResize from the Files hooks barrel.
client/src/hooks/Files/tests/useClientResize.spec.tsx Adds tests validating both override directions and parameter-only admin config behavior.
client/src/components/Nav/SettingsTabs/Chat/ImageResize.tsx Adds the new UI toggle with an enforced-state info message and disabled behavior.
client/src/components/Nav/Settings/registry.tsx Registers the new setting under Chat → Sending.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@berry-13

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: d19ea675f5

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread client/src/utils/imageResize.ts Outdated
Comment thread client/src/utils/imageResize.ts Outdated
Comment thread client/src/hooks/Files/useClientResize.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2fc9850f5a

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread client/src/utils/imageResize.ts Outdated
Comment thread client/src/utils/imageResize.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 788f1398af

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread client/src/utils/imageResize.ts
Comment thread client/src/utils/imageResize.ts Outdated
Comment thread client/src/hooks/Files/useClientResize.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 2b8ef6b1b0

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread client/src/utils/imageResize.ts
Client-side image resizing could only be configured in librechat.yaml and
defaulted to off, so users had no way to enable it for themselves.

Add a "Resize images before upload" toggle in Settings > Chat > Sending,
stored per device in localStorage. When librechat.yaml sets
clientImageResize.enabled, mergeFileConfig marks the value as enforced and
the toggle renders the admin value read-only. Admin resize parameters still
apply without locking the toggle when enabled is omitted.

Also fix shouldResizeImage, which compared file size against 10% of a 512MB
fallback limit and so only triggered above roughly 51MB. It now uses a 512KB
floor, which lets the setting affect everyday photos.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 943d6f1ef2

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread client/src/hooks/Files/useClientResize.ts
Comment thread client/src/utils/imageResize.ts Outdated
@berry-13
berry-13 force-pushed the feat/check-image-upload-compression branch from 943d6f1 to 2562d0f Compare August 16, 2026 05:31

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: f9b13955c8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread client/src/components/Nav/SettingsTabs/Chat/ImageResize.tsx Outdated
Comment thread client/src/utils/imageResize.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 32f9e0e806

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread client/src/hooks/Files/useFileHandling.ts Outdated

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 65dee9e7f6

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread client/src/hooks/Files/useClientResize.ts
Comment thread client/src/utils/imageResize.ts
Comment thread client/src/hooks/Files/useFileHandling.ts Outdated
@berry-13

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 3893aa4ccb

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@berry-13

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Nice work!

Reviewed commit: e18be77139

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

@berry-13

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: db8333f632

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread client/src/hooks/Files/useFileHandling.ts
@berry-13

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 4b46f6d194

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread client/src/components/Nav/SettingsTabs/Chat/ImageResize.tsx Outdated
The switch stayed clickable during the initial file-config load even
though the checked state cannot update until that query settles.

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: a9bd9c4b3c

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread client/src/hooks/Files/useFileHandling.ts
@berry-13

Copy link
Copy Markdown
Collaborator Author

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Already looking forward to the next diff.

Reviewed commit: 05eff8cd92

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

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.

2 participants