Skip to content

Conversation

@ValentinH
Copy link
Owner

@ValentinH ValentinH commented Oct 1, 2025

Summary

This PR fixes issue #626 where cropping and zooming sometimes doesn't work when the component is rendered inside animated modals.

Problem

The issue was introduced in PR #623 (v5.5.2) when the applyCanonical approach was replaced with a new scaling mechanism using previousCropSize. The scaling logic in recomputeCropPosition would run during component initialization/mount, causing incorrect crop positioning especially when:

  • The cropper is rendered inside an animated modal
  • Container size changes occur during the mount sequence
  • previousCropSize hasn't been properly initialized yet

This resulted in the crop area being positioned incorrectly, sometimes making interactions non-functional.

Solution

Added an isInitialized flag that prevents the scaling logic from running until the component is fully initialized via onMediaLoad. The changes:

  1. Added isInitialized flag - Tracks whether the component has completed initialization
  2. Updated onMediaLoad - Sets previousCropSize and isInitialized = true when media loads
  3. Updated recomputeCropPosition - Only applies scaling when isInitialized && previousCropSize exist

This ensures the scaling logic only runs during legitimate window resize events, not during the initial mount sequence.

Additional Changes

Reverted the unnecessary windowResizeHandler wrapper that was introduced in #623, as it's no longer needed.

The fix would benefit from validation by @TobiTRy (the original reporter) with their specific use case.

Fixes #626

This fixes an issue where the crop position scaling logic would run
during component mount/initialization, causing incorrect crop positioning
especially when the cropper is rendered inside animated modals.

The fix adds an `isInitialized` flag that ensures the scaling logic in
`recomputeCropPosition` only runs after the component is fully initialized
via `onMediaLoad`. This prevents the scaling from being applied at the
wrong time during mount sequences.

Also reverts the unnecessary `windowResizeHandler` wrapper that was
introduced in the previous fix attempt.

Fixes #626
@codesandbox-ci
Copy link

codesandbox-ci bot commented Oct 1, 2025

This pull request is automatically built and testable in CodeSandbox.

To see build info of the built libraries, click here or the icon next to each commit SHA.

@ValentinH ValentinH added bug Something isn't working patch Increment the patch version when merged labels Oct 1, 2025
@ValentinH ValentinH merged commit e5a491b into main Oct 1, 2025
5 checks passed
@ValentinH ValentinH deleted the fix/crop-initialization-timing-626 branch October 1, 2025 21:05
@github-actions
Copy link

github-actions bot commented Oct 1, 2025

🚀 PR was released in v5.5.3 🚀

@github-actions github-actions bot added the released This issue/pull request has been released. label Oct 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working patch Increment the patch version when merged released This issue/pull request has been released.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Since version 5.5.2 i cant crop and zoom in the Canvas anymore

2 participants