Skip to content

🎚️ fix: Correct Client Image Resize Threshold Handling - #12475

Open
mattdaniell wants to merge 5 commits into
LibreChat-AI:devfrom
mattdaniell:fix/client-image-resize-threshold
Open

mattdaniell wants to merge 5 commits into
LibreChat-AI:devfrom
mattdaniell:fix/client-image-resize-threshold

Conversation

@mattdaniell

@mattdaniell mattdaniell commented Mar 31, 2026 •

Copy link
Copy Markdown

Pull Request Template

⚠️ Before Submitting a PR, Please Review:

  • Please ensure that you have thoroughly read and understood the Contributing Docs before submitting your Pull Request.

⚠️ Documentation Updates Notice:

  • Kindly note that documentation updates are managed in this repository: librechat.ai

Summary

This PR fixes clientImageResize being a no-op for typical user photos due to an incorrect size threshold path in the client hook.

useClientResize previously called shouldResizeImage(file) without passing a threshold argument, which caused shouldResizeImage to use a 512MB-based default and skip all images under ~51MB. In practice, most uploads (1-10MB photos) were never reaching canvas resize, even when fileConfig.clientImageResize.enabled: true.

This change introduces clientImageResize.minFileSizeKB (default 1024) and wires it through to shouldResizeImage(file, minFileSizeBytes). This preserves the optimization for truly tiny files while allowing normal photos to proceed to dimension/quality resize logic.

Also updated librechat.example.yaml to document the new minFileSizeKB option.

Change Type

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • This change requires a documentation update
  • Translation update

Testing

Manual testing performed with clientImageResize.enabled: true and resize limits configured:

  1. Upload a large image (example: 5MB JPEG, 4032x3024)
    • Before: not resized
    • After: resized to fit configured bounds (example: 1900x1425)
  2. Upload a medium image (example: 2MB PNG, 2560x1440)
    • Before: not resized
    • After: resized to fit configured bounds (example: 1900x1069)
  3. Upload a small thumbnail (example: 150KB, 800x600)
    • Before: not resized
    • After: not resized (below minimum file-size threshold)

Test Configuration:

  • fileConfig.clientImageResize.enabled: true
  • fileConfig.clientImageResize.maxWidth: 1900
  • fileConfig.clientImageResize.maxHeight: 1900
  • fileConfig.clientImageResize.quality: 0.92
  • fileConfig.clientImageResize.minFileSizeKB: 1024

Checklist

  • My code adheres to this project's style guidelines
  • I have performed a self-review of my own code
  • I have commented in any complex areas of my 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
  • Any changes dependent on mine have been merged and published in downstream modules.
  • A pull request for updating the documentation has been submitted.

Made with Cursor

Add configurable minFileSizeKB support to clientImageResize and pass it through to shouldResizeImage so typical user photos are eligible for resize. Also document minFileSizeKB in librechat.example.yaml with a practical default.

Made-with: Cursor

@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: 5996880be1

ℹ️ 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".

// Return original file if it doesn't need resizing
if (!shouldResizeImage(file)) {
// Return original file if it's below the minimum size threshold
if (!shouldResizeImage(file, minFileSizeBytes)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Pass effective threshold expected by shouldResizeImage

minFileSizeKB is documented as the minimum file size to start resizing, but this call passes it directly into shouldResizeImage, whose implementation applies an additional * 0.1 threshold check. With the new default (1024 KB), files are skipped only below ~102 KB, not below 1 MB as intended, so many sub-1MB images still go through resize processing. This makes the new config inaccurate and can trigger unnecessary client-side work for files that should be excluded.

Useful? React with 👍 / 👎.

- Remove internal `* 0.1` multiplier in `shouldResizeImage`; rename its
  second parameter to `minSizeBytes` so the threshold matches what
  callers pass, fixing the documented behavior of `minFileSizeKB`.
- Add `minFileSizeKB` to `FileConfig` and `FileConfigInput` types so the
  field is visible to typed consumers; remove `as any` cast and the
  `eslint-disable` line in `useClientResize`.
- Tighten Zod schema to `z.number().int().min(0)` to reject fractional
  KB values; update YAML comment to describe the actual semantics
  (including `minFileSizeKB: 0` as "disable threshold").
- Introduce `DEFAULT_MIN_FILE_SIZE_KB` shared constant to dedupe the
  default across config, hook, and tests.
- Memoize `config` in `useClientResize` so its reference is stable when
  `fileConfig` is unchanged, satisfying `react-hooks/exhaustive-deps`
  without suppression.
- Expand `imageResize.test.ts` with boundary coverage (exact threshold,
  one byte below, 150KB regression case, `minSizeBytes: 0` disables
  gate, non-image and GIF gating) and add an integration test for
  `useClientResize` exercising enabled/disabled, threshold skip,
  threshold resize, and default fallback paths.
@danny-avila
danny-avila changed the base branch from main to dev April 16, 2026 18:53
@danny-avila danny-avila changed the title fix: clientImageResize is a no-op for typical photos due to incorrect shouldResizeImage threshold 🎚️ fix: Correct Client Image Resize Threshold Handling Apr 16, 2026
@danny-avila

Copy link
Copy Markdown
Collaborator

@codex review

@chatgpt-codex-connector

Copy link
Copy Markdown

Codex Review: Didn't find any major issues. Keep it up!

ℹ️ 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".

This branch has not been deployed

No deployments
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