Commit f819461
authored
fix: debounce onCropComplete/onCropAreaChange during resize bursts (#653)
* fix: debounce onCropComplete/onCropAreaChange during resize bursts
Fixes #309. recomputeCropPosition() always called emitCropData()
unconditionally, and computeSizes() now runs on every ResizeObserver
tick, so dragging the window/container edge fired onCropComplete and
onCropAreaChange dozens of times during a single resize.
Resize-triggered computeSizes() calls are now flagged, and their
resulting emitCropData() call is debounced (250ms), while all other
callers (rotation/aspect/zoom/cropSize changes, media load, etc.)
keep firing immediately as before. The crop area itself still updates
visually in real time during the resize; only the completion
callbacks are debounced.
* fix: cancel pending resize debounce timer on immediate crop emit
Addresses Copilot review feedback on PR #653: if a resize burst
schedules debouncedEmitCropData() and then a non-resize completion
(e.g. drag stop, keyboard end) calls emitCropData() immediately, the
still-pending resize timer would later fire and call emitCropData()
again, causing a duplicate onCropComplete/onCropAreaChange after the
user interaction. Clearing the pending timer whenever an immediate
emit happens fixes this.
* refactor: use named param for isResizeTriggered
Per @ValentinH's review, computeSizes and recomputeCropPosition now
take { isResizeTriggered } instead of a positional boolean, so call
sites are self-documenting.1 parent 2cd9217 commit f819461
2 files changed
Lines changed: 86 additions & 7 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
70 | 70 | | |
71 | 71 | | |
72 | 72 | | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
73 | 117 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
15 | 15 | | |
16 | 16 | | |
17 | 17 | | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
18 | 23 | | |
19 | 24 | | |
20 | 25 | | |
| |||
123 | 128 | | |
124 | 129 | | |
125 | 130 | | |
| 131 | + | |
126 | 132 | | |
127 | 133 | | |
128 | 134 | | |
| |||
148 | 154 | | |
149 | 155 | | |
150 | 156 | | |
151 | | - | |
| 157 | + | |
152 | 158 | | |
153 | 159 | | |
154 | 160 | | |
| |||
189 | 195 | | |
190 | 196 | | |
191 | 197 | | |
192 | | - | |
| 198 | + | |
193 | 199 | | |
194 | 200 | | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
195 | 204 | | |
196 | 205 | | |
197 | 206 | | |
| |||
250 | 259 | | |
251 | 260 | | |
252 | 261 | | |
253 | | - | |
| 262 | + | |
254 | 263 | | |
255 | 264 | | |
256 | 265 | | |
257 | 266 | | |
| 267 | + | |
| 268 | + | |
| 269 | + | |
| 270 | + | |
258 | 271 | | |
259 | 272 | | |
260 | 273 | | |
| |||
348 | 361 | | |
349 | 362 | | |
350 | 363 | | |
351 | | - | |
| 364 | + | |
352 | 365 | | |
353 | 366 | | |
354 | 367 | | |
| |||
435 | 448 | | |
436 | 449 | | |
437 | 450 | | |
438 | | - | |
| 451 | + | |
439 | 452 | | |
440 | 453 | | |
441 | 454 | | |
| |||
705 | 718 | | |
706 | 719 | | |
707 | 720 | | |
| 721 | + | |
| 722 | + | |
| 723 | + | |
| 724 | + | |
| 725 | + | |
708 | 726 | | |
709 | 727 | | |
710 | 728 | | |
| |||
728 | 746 | | |
729 | 747 | | |
730 | 748 | | |
731 | | - | |
| 749 | + | |
732 | 750 | | |
733 | 751 | | |
734 | 752 | | |
| |||
763 | 781 | | |
764 | 782 | | |
765 | 783 | | |
766 | | - | |
| 784 | + | |
| 785 | + | |
| 786 | + | |
| 787 | + | |
| 788 | + | |
| 789 | + | |
| 790 | + | |
| 791 | + | |
| 792 | + | |
| 793 | + | |
| 794 | + | |
| 795 | + | |
| 796 | + | |
| 797 | + | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
767 | 802 | | |
768 | 803 | | |
769 | 804 | | |
| |||
0 commit comments