Skip to content

Commit a9a93c2

Browse files
authored
Fix parsing parent element container from props (#6681)
**Problem:** The `parentContainerGridPropertiesFromProps` in the special size measurements is incorrectly calcluated off of the computed style of the parent. This results, among other issues, into the template being serialized to its computed values whenever `gridMoveStrategiesExtraCommands` is applied inside strategies (e.g. right after moving a grid item). **Fix:** Try to use the parent element style directly when parsing. | Before | After | |--------|------------| | https://github.com/user-attachments/assets/3a3a62b4-c030-422d-bd69-d80e52a76ef5 | https://github.com/user-attachments/assets/ffbc2c3e-e7b3-4812-b9b4-71d096030b94 | **Manual Tests:** I hereby swear that: - [x] I opened a hydrogen project and it loaded - [x] I could navigate to various routes in Play mode Fixes #6680
1 parent 84b3781 commit a9a93c2

File tree

2 files changed

+113
-2
lines changed

2 files changed

+113
-2
lines changed

editor/src/components/canvas/canvas-strategies/strategies/grid-element-change-location-strategy.spec.browser2.tsx

+110-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import * as EP from '../../../../core/shared/element-path'
22
import { offsetPoint, windowPoint } from '../../../../core/shared/math-utils'
3-
import { selectComponentsForTest } from '../../../../utils/utils.test-utils'
3+
import { selectComponentsForTest, wait } from '../../../../utils/utils.test-utils'
44
import CanvasActions from '../../canvas-actions'
55
import { GridCellTestId } from '../../controls/grid-controls-for-strategies'
66
import { mouseDownAtPoint, mouseMoveToPoint, mouseUpAtPoint } from '../../event-helpers.test-utils'
@@ -28,6 +28,34 @@ describe('grid element change location strategy', () => {
2828
})
2929
})
3030

31+
it('does not alter the grid template', async () => {
32+
const editor = await renderTestEditorWithCode(
33+
ProjectCodeFractionalTemplate,
34+
'await-first-dom-report',
35+
)
36+
37+
const testId = 'aaa'
38+
const { gridRowStart, gridRowEnd, gridColumnStart, gridColumnEnd } = await runGridMoveTest(
39+
editor,
40+
{
41+
scale: 1,
42+
gridPath: 'sb/scene/grid',
43+
testId: testId,
44+
},
45+
)
46+
47+
expect({ gridRowStart, gridRowEnd, gridColumnStart, gridColumnEnd }).toEqual({
48+
gridColumnEnd: '7',
49+
gridColumnStart: '3',
50+
gridRowEnd: '4',
51+
gridRowStart: '2',
52+
})
53+
54+
const grid = await editor.renderedDOM.findByTestId('grid')
55+
expect(grid.style.gridTemplateColumns).toEqual('1fr 1fr 2fr 2fr 1fr 1fr')
56+
expect(grid.style.gridTemplateRows).toEqual('1fr 1fr 2fr 1fr')
57+
})
58+
3159
describe('component items', () => {
3260
it('can change the location of components on a grid when component takes style prop', async () => {
3361
const editor = await renderTestEditorWithCode(
@@ -881,6 +909,87 @@ export var storyboard = (
881909
)
882910
`
883911

912+
const ProjectCodeFractionalTemplate = `import * as React from 'react'
913+
import { Scene, Storyboard, Placeholder } from 'utopia-api'
914+
915+
export var storyboard = (
916+
<Storyboard data-uid='sb'>
917+
<Scene
918+
id='playground-scene'
919+
commentId='playground-scene'
920+
style={{
921+
width: 847,
922+
height: 895,
923+
position: 'absolute',
924+
left: 46,
925+
top: 131,
926+
}}
927+
data-label='Playground'
928+
data-uid='scene'
929+
>
930+
<div
931+
style={{
932+
display: 'grid',
933+
gridTemplateRows: '1fr 1fr 2fr 1fr',
934+
gridTemplateColumns:
935+
'1fr 1fr 2fr 2fr 1fr 1fr',
936+
gridGap: 16,
937+
height: 482,
938+
width: 786,
939+
position: 'absolute',
940+
left: 31,
941+
top: 0,
942+
}}
943+
data-uid='grid'
944+
data-testid='grid'
945+
>
946+
<div
947+
style={{
948+
minHeight: 0,
949+
backgroundColor: '#f3785f',
950+
gridColumnEnd: 5,
951+
gridColumnStart: 1,
952+
gridRowEnd: 3,
953+
gridRowStart: 1,
954+
}}
955+
data-uid='aaa'
956+
data-testid='aaa'
957+
/>
958+
<div
959+
style={{
960+
minHeight: 0,
961+
backgroundColor: '#23565b',
962+
}}
963+
data-uid='bbb'
964+
data-testid='bbb'
965+
/>
966+
<Placeholder
967+
style={{
968+
minHeight: 0,
969+
gridColumnEnd: 5,
970+
gridRowEnd: 4,
971+
gridColumnStart: 1,
972+
gridRowStart: 3,
973+
backgroundColor: '#0074ff',
974+
}}
975+
data-uid='ccc'
976+
/>
977+
<Placeholder
978+
style={{
979+
minHeight: 0,
980+
gridColumnEnd: 9,
981+
gridRowEnd: 4,
982+
gridColumnStart: 5,
983+
gridRowStart: 3,
984+
}}
985+
data-uid='ddd'
986+
/>
987+
</div>
988+
</Scene>
989+
</Storyboard>
990+
)
991+
`
992+
884993
const makeProjectCodeWithItemComponent = (
885994
itemComponentCode: string,
886995
) => `import * as React from 'react'

editor/src/components/canvas/dom-walker.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -930,7 +930,9 @@ function getSpecialMeasurements(
930930
: null
931931

932932
const containerGridPropertiesFromProps = getGridContainerProperties(element.style)
933-
const parentContainerGridPropertiesFromProps = getGridContainerProperties(parentElementStyle)
933+
const parentContainerGridPropertiesFromProps = getGridContainerProperties(
934+
element.parentElement?.style ?? parentElementStyle,
935+
)
934936
const containerGridProperties = getGridContainerProperties(computedStyle, {
935937
dynamicCols: isDynamicGridTemplate(containerGridPropertiesFromProps.gridTemplateColumns),
936938
dynamicRows: isDynamicGridTemplate(containerGridPropertiesFromProps.gridTemplateRows),

0 commit comments

Comments
 (0)