BUG: Resizing an absolutely positioned element with a CSS transform causes it to jump
GrapesJS version
- I confirm to use the latest version of GrapesJS
What browser are you using?
Google Chrome: Version 153.0.8010.53 (Official Build) (arm64)
Reproducible demo link
https://jsfiddle.net/o36r8umc/
Describe the bug
How to reproduce the bug?
- Open the provided JSFiddle.
- Click Run if the preview is not already running.
- The affected element is selected automatically.
- Drag the left-center or right-center resize handle horizontally.
- Observe that the element jumps significantly from its original position.
What is the expected behavior?
The element should resize from the selected handle without unexpectedly changing its visual position.
For example, when dragging the left-center handle to the left, the left edge should follow the pointer while the opposite edge remains anchored.
What is the current behavior?
When an absolutely positioned component has a positional CSS transform such as transform: translateX(-50%), resizing it causes the component to jump.
GrapesJS appears to read the element's already-transformed visual coordinates, write those coordinates into left/top, and then preserve the existing transform. The transform is therefore applied again to the newly written position.
For example, before resizing:
left: 450pxwidth: 420pxtransform: translateX(-50%)- Visual left position: approximately
240px
After dragging the left resize handle by approximately 50px:
leftbecomes approximately190pxwidthbecomes approximately470px- The transform is preserved
- Visual left position becomes approximately
-45px
The exact numbers depend on the drag distance, but the unexpected jump is consistent.
This is reproducible with GrapesJS 0.23.6 in a standalone example without any application-specific integration code.
The initial styles of the affected element are:
position: absolute;
left: 450px;
top: 150px;
width: 420px;
height: 60px;
transform: translateX(-50%);It appears that the resizer obtains the starting position from a transformed getBoundingClientRect() value and later writes that visual position into the component's CSS left/top properties while preserving the transform.
Relevant source files:
- https://github.com/GrapesJS/grapesjs/blob/v0.23.6/packages/core/src/utils/Resizer.ts
- https://github.com/GrapesJS/grapesjs/blob/v0.23.6/packages/core/src/commands/view/Resize.ts
Code of Conduct
- I agree to follow this project's Code of Conduct
Source: GrapesJS/grapesjs