Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inserting/reparenting into a grid component #6602

Merged
merged 3 commits into from
Oct 31, 2024

Conversation

gbalint
Copy link
Contributor

@gbalint gbalint commented Oct 30, 2024

Problem:
Inserting/reparenting into a grid component doesn't work.

Root cause:
The problem is the following:

  • We collect the global frames of grid cells using the measurement helper components (which render an invisible clone of the grid with placeholders in each cell, so they are measurable html elements)
  • getSpecialSizeMeasurements needs to find the appropriate measurement helper in the dom
  • Measurement helpers are identifiable because they have an id which includes the element path of the grid they refer to. This a path which is coming from the metadata of the element.
  • getSpecialSizeMeasurements uses the element path from the data-path attribute of the measured grid element to find the measurement helper
  • When the grid is a component, the rendered grid layouted div's data-path contains the element path of the root element of the component and not the path of the component itself (e.g. foo/bar/grid:root instead of foo/bar/grid). But the measurement helper's id includes the element path of the component (e.g. foo/bar/grid). Because of this, getSpecialMeasurements does not find the measurement helper for this grid, and it does not store the grid cell global frames in specialSizeMeasurements

Fix:

  • Instead of using the data-path of the measured element, use the paths coming from getPathsOnDomElement, which lists all the possible utopia element paths connected to this rendered html element. Try to find the measurement helper using these paths (it is enough to use the first one which is found).
  • For the measurement of parentGridCellGlobalFrames, just do the same thing on the parent element in the dom.
  • I renamed measureGlobalFramesOfGridCellsFromControl because it doesn't use the grid control anymore (but the measurement helper).

This change fixes all draw-to-insert/click-to-insert/reparent functionalities.

Manual Tests:
I hereby swear that:

  • I opened a hydrogen project and it loaded
  • I could navigate to various routes in Play mode

Copy link
Contributor

github-actions bot commented Oct 30, 2024

Try me

Copy link

relativeci bot commented Oct 30, 2024

#14969 Bundle Size — 58.03MiB (~+0.01%).

7962613(current) vs d1d46c1 master#14966(baseline)

Warning

Bundle contains 70 duplicate packages – View duplicate packages

Bundle metrics  Change 2 changes Regression 1 regression
                 Current
#14969
     Baseline
#14966
Regression  Initial JS 41.01MiB(~+0.01%) 41.01MiB
No change  Initial CSS 0B 0B
Change  Cache Invalidation 18.06% 17.95%
No change  Chunks 20 20
No change  Assets 22 22
No change  Modules 4163 4163
No change  Duplicate Modules 213 213
No change  Duplicate Code 27.31% 27.31%
No change  Packages 477 477
No change  Duplicate Packages 70 70
Bundle size by type  Change 2 changes Regression 1 regression Improvement 1 improvement
                 Current
#14969
     Baseline
#14966
Regression  JS 58.02MiB (~+0.01%) 58.02MiB
Improvement  HTML 7.37KiB (-0.25%) 7.39KiB

Bundle analysis reportBranch fix/insertion-into-componentProject dashboard


Generated by RelativeCIDocumentationReport issue

@gbalint gbalint marked this pull request as ready for review October 30, 2024 15:59
@gbalint gbalint changed the title Inserting/reparenting into a grid a component Inserting/reparenting into a grid component Oct 30, 2024
let gridCellGlobalFrames: GridCellGlobalFrames | null = null
const gridControlElement = document.getElementById(GridMeasurementHelperKey(EP.fromString(path)))
const gridControlElement = (() => {
for (let p of paths) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this work with nested grids?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Absolutely! These paths are all utopia element paths which render exactly to this html element, so there is no overlap between the paths of different grids.

@gbalint gbalint merged commit 8f9354e into master Oct 31, 2024
20 checks passed
@gbalint gbalint deleted the fix/insertion-into-component branch October 31, 2024 10:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants