utopia icon indicating copy to clipboard operation
utopia copied to clipboard

Validate the use of style props during reparenting.

Open seanparsons opened this issue 3 years ago • 3 comments

Problem: If a component does not carry positional properties (like left) from the style attribute into the root element making that component up, then it very likely will not be repositionable. We want something that can't be repositioned to also not be reparentable as well.

Fix: Some very basic static analysis is performed to see if the appropriate properties are carried into the root element's style attribute or if the style attribute of the component props are spread into the style attribute of the root element.

Commit Details:

  • Implemented componentHonoursPropsPosition and componentHonoursPropsSize which check if a component honours the position and size properties respectively by passing them into the root element.
  • Created propsStyleIsSpreadInto which checks if the attributes provided have props.style spread into them.
  • Added propertyComesFromPropsStyle which analyses the attributes of an element to see if a certain property has been utilised from the props parameter.
  • Added targetHonoursPropsSize and targetHonoursPropsPosition to MetadataUtils which provide a higher level call over the componentHonours... functions.
  • Added honoursPropsPosition and honoursPropsSize to simplify checking for canvas strategies.
  • Prevent component instances from being reparented if they do not honour the position properties in the root element of the component.

seanparsons avatar Aug 11 '22 15:08 seanparsons

Job #1973: Bundle Size — 48.19MB (+0.08%).

6744435ba6b942901a2ee45839828efa9ccb75a8 vs 75343b88b8942649e7608d555b87b50fd69d8166

Changed metrics (3/10)
Metric Current Baseline
Initial JS 31.04MB(+0.07%) 31.01MB
Cache Invalidation 19.56% 19.57%
Duplicate Code 16.14%(+0.25%) 16.1%
Changed assets by type (1/7)
            Current     Baseline
JS 48.18MB (+0.08%) 48.14MB

View Job #1973 report on app.relative-ci.com

relativeci[bot] avatar Aug 11 '22 15:08 relativeci[bot]

Link to test editor Performance test results: Highlight Regular (-4%)

Highlight All Elements (8%)
Before: 14.3ms (13.4-39ms)
After: 15.4ms (12.1-40.7ms)

Selection (3%)

De-Selection (5%)

Selection Change (9%)
Before: 29.3ms (27.8-47.5ms)
After: 31.8ms (29.3-48.9ms)

Scroll Canvas (3%)

Resize (-3%)

Absolute Move (Just Move, Large) (0%)

Absolute Move (Just Move, Small) (-2%)

Absolute Move (Interaction, Large) (2%)

Absolute Move (Interaction, Small) (-1%)

(Chart1)
(Chart2)

github-actions[bot] avatar Aug 11 '22 15:08 github-actions[bot]

nice! (just in case you don't plan it already) I think a follow-up PR should also disable moving and resizing strategies for elements that don't respect the relevant props. IIRC the Delta-based absolute move doesn't need the size props, and there used to be a delta-based absolute resize but maybe that has been removed.

That seems like a natural progression, I thought I would keep it out of this PR since that's not the purpose of it.

seanparsons avatar Aug 11 '22 16:08 seanparsons