Skip to content

fix: restore initial crop selection for uploaded signatures - #9528

Open
vitormattos wants to merge 5 commits into
mainfrom
fix/9526-signature-upload-stencil-size
Open

vitormattos wants to merge 5 commits into
mainfrom
fix/9526-signature-upload-stencil-size

Conversation

@vitormattos

@vitormattos vitormattos commented Nov 17, 2026 •

Copy link
Copy Markdown
Member

Closes #9526

Root cause

FileUpload.vue passed a fixed-size defaultSize object derived from the display container to vue-advanced-cropper. The cropper interprets it in source-image coordinates rather than CSS pixels, causing a tiny initial stencil with high-resolution uploads.

Fix

  • Delegate initial selection dimensions to the cropper's native image-relative algorithm.
  • Retain the configured signature aspect ratio (signature-width / signature-height), the PNG result and existing zoom controls.
  • Remove the obsolete ResizeObserver, container-width sizing code and stale assertions.
  • Preserve state-reset assertions and add a regression test for the cropper's initial props.

Verified red → green regression

Before the fix — 2d02d914d8d707fa2573e5a5e68587b002dd78ec:

  • Node tests run 44085839150 successfully built, then failed in the new test (1 failed, 3,675 passed).
  • Actual: defaultSize = {width: 700, height: 200}. Expected: no fixed defaultSize.

After the fix — 5683304f1b61f4cf4581cfee98ff2da8df77e109:

  • Node tests run 44086404214: 283 test files, 3,675 tests passed, including the regression; coverage step passed.
  • TypeScript type checking, ESLint, stylelint, and JavaScript build: passed.
  • Other CI jobs (including Playwright) may still be in progress and must be inspected before merge.

PHP image quality and scope

SignatureBackgroundService::scaleDimensions() already preserves smaller stamp-background images and proportionally downsizes images larger than 3× the configured full stamp dimensions; SignatureBackgroundServiceTest covers both cases. This is the stamp background, not the user's cropped signature. The latter is validated as PNG (including a 5 MiB size limit) in FileInputValidator and stored by SignerElementsService. The signing engine controls final PDF rendering.

No PHP image processing, resolution rules or file validation are changed by this PR.

Validation limitation

The regression checks the Vue component's integration contract with the cropper and the preserved aspect ratio. It does not assert actual CSS-frame measurements in a real browser using a 3000×1200 image; those measurements were supplied in the original issue report.

Both commits were made with signed DCO trailers.

Follow-up from code review (2026-11-18)

The original change fixes the initial stencil, but a high-entropy 3000 px image can now export a PNG larger than the backend's 5000 KiB visible-element limit.

  • Regression test: 5fd31e3.
  • Fix: b5bb0d2.
  • The cropper's export canvas is limited to 3× the configured signature width/height and 1,000,000 pixels total. No forced output width or height is configured, so smaller images retain their resolution. The megapixel limit also bounds uncompressed RGBA pixel data to around 4 MB, below the current 5000 KiB backend PNG limit, even when compression is ineffective.
  • The new unit test verifies that the application passes these constraints to the cropper. It is not a real-browser validation of the exported PNG or the visible crop frame.
  • At b5bb0d2, NPM lint failed on @stylistic/multiline-ternary at FileUpload.vue:218,220, while the Node tests passed. Both ESLint formatting errors were addressed in 4c2cc7d, a signed DCO commit without a logic change. The new CI for this head is running; it must finish before merge.

@vitormattos
vitormattos marked this pull request as ready for review November 17, 2026 12:51
@vitormattos
vitormattos requested a review from a team as a code owner November 17, 2026 12:51
@lfals lfals self-assigned this Nov 23, 2026

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

This PR conflicts with main in src/components/Draw/FileUpload.vue (commit 30dca7f7c reformatted the same template attributes). Please rebase and re-run lint and the Node tests.

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

Only need to resolve the merge conflicts

Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
Signed-off-by: Vitor Mattos <1079143+vitormattos@users.noreply.github.com>
@coderabbitai

coderabbitai Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Explain Change →

No actionable comments were generated in the recent review.

Summary

Intended behavior: Remove the fixed default-size binding so the cropper sets the initial crop frame. This fixes the tiny frame described in #9526. The change keeps the aspect ratio, PNG output, and zoom controls.

Confirmed in the diff (FileUpload.vue, +46/−89 across two files):

  • :default-size="defaultStencilSize" is removed.
  • The ResizeObserver, container-width state, and resize listeners are removed.
  • A canvasConstraints computed is passed to Cropper as :canvas. It sets maxWidth and maxHeight to 3× the signature dimensions (only when finite and positive) and maxArea to 1,000,000 px.
  • The hasImage watcher now only resets zoom, pending centering, and imageData when the image is cleared.

Verification:

  • Unit tests check the props passed to the cropper. They do not check exported image size or the rendered crop frame.
  • The PR reports Node tests passing on the initial fix. The PR reports lint failure on the follow-up, fixed in commit 4c2cc7d. CI results for the current head were not verified here.
  • Real-browser validation of the export and crop frame is not reported.

Size bound: The 5000 KiB claim is consistent with arithmetic. A 1,000,000-pixel RGBA image is about 3.9 MiB raw, before PNG compression. The code comment says the canvas "stays under" the limit, but no test verifies this.

Open items:

  • Confirm that the crop frame and export are correct in a browser.
  • Confirm CI passes on the current head before merge.
  • No confirmed defects found.

Changes

The upload cropper no longer receives a container-derived default stencil size. It now receives canvas export limits based on the configured signature dimensions and a maximum area of 1,000,000 pixels. The component removes resize-observer handling. Tests cover the cropper configuration and image-clear resets.

Signature cropper sizing

Layer / File(s) Summary
Cropper configuration and reset behavior
src/components/Draw/FileUpload.vue, src/tests/components/Draw/FileUpload.spec.ts
The component replaces the default stencil size with canvas limits and removes container-width and resize-observer handling. Tests check the configured aspect ratio, cropper-managed initial sizing, canvas limits, and image-clear resets.

Suggested reviewers: lfals

Change: Bug fix · Severity of issue fixed: Medium

Merge Risk: Minimal · up to 19a56

The upload cropper now lets the library choose the initial crop frame, so large images should get a sensibly sized selection. Exported signature size is capped by canvas limits. No actionable merge-blocking risk was found.

Security architecture risk: Minimal · up to 19a56

The signature uploader now lets the cropper choose the initial selection and scales the exported image when needed. It still uses the same confirmation and save flow. No material increase in security or operational risk was identified in the change.

Retained concerns
No architecture-level concerns identified.

Security review details

Trust Boundaries and Controls

  • observed — The new constraints apply after the selected image has been read, at browser canvas export. They do not limit source image decoding, and a pixel limit is not a server-side upload limit.
Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI (base), Organization UI (inherited)
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: 87888ce7-6167-4c15-9a59-63489cc0d688
Commits

Reviewing files that changed from the base of the PR and between 9918c99 and 19a560b.

Files selected for processing: 2

  • src/components/Draw/FileUpload.vue
  • src/tests/components/Draw/FileUpload.spec.ts
Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 9 remain after this review.

Recent review details

Context from checks skipped due to timeout: 3

  • GitHub Check: CodeRabbit
  • GitHub Check: Playwright E2E Tests (master)
  • GitHub Check: test
Additional context used

Code guidelines: 4

AGENTS.md — configured
3 cross-repository guideline sources
Path-based instructions: 4

Source excerpt: Frontend unit tests should mirror the source tree under `src/tests/`.

CodeRabbit inference engine (AGENTS.md)

Files:

  • src/tests/components/Draw/FileUpload.spec.ts
Source excerpt: Prefer named independent cases for inputs that share the **same** setup, action, contract and expectation.

CodeRabbit inference engine

Files:

  • src/components/Draw/FileUpload.vue
  • src/tests/components/Draw/FileUpload.spec.ts
Source excerpt: Tests are also code to review.

CodeRabbit inference engine

Files:

  • src/components/Draw/FileUpload.vue
  • src/tests/components/Draw/FileUpload.spec.ts
Source excerpt: For integration tests changing persistent state, snapshot only the relevant pre-test values and restore them in a reliable teardown/finally path; preserve absent-vs-empty and types.

CodeRabbit inference engine

Files:

  • src/components/Draw/FileUpload.vue
  • src/tests/components/Draw/FileUpload.spec.ts

@lfals
lfals force-pushed the fix/9526-signature-upload-stencil-size branch from 1eb286a to 19a560b Compare November 27, 2026 02:16

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.

Signature upload: crop frame is fixed at 350×100 *image pixels*, so it is tiny on any real photo or scan

2 participants