utopia
utopia copied to clipboard
Validate the use of style props during reparenting.
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
componentHonoursPropsPositionandcomponentHonoursPropsSizewhich check if a component honours the position and size properties respectively by passing them into the root element. - Created
propsStyleIsSpreadIntowhich checks if the attributes provided haveprops.stylespread into them. - Added
propertyComesFromPropsStylewhich analyses the attributes of an element to see if a certain property has been utilised from the props parameter. - Added
targetHonoursPropsSizeandtargetHonoursPropsPositiontoMetadataUtilswhich provide a higher level call over thecomponentHonours...functions. - Added
honoursPropsPositionandhonoursPropsSizeto 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.
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% |
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%)

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.