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

Fix subscribing mutation/resize observers during a build error #6344

Merged
merged 10 commits into from
Sep 11, 2024

Conversation

gbalint
Copy link
Contributor

@gbalint gbalint commented Sep 9, 2024

Problem:
Followup to #6326
In a Remix project it can happen that in the dispatch flow we don't have the results of the rendering in the dom yet. It can even happen, that after a build error is fixed, we still don't have the canvas root container in the dom.
That is a critical issue, because we attach the mutation/resize observers to the canvas root container element, so when we don't have that we can subscribe them, so the dom sample is not going to run when the rendering is finished.

Fix:
I needed an element, which is an ancestor of the canvas root container and
1 is always rendered
2 does not contain canvas controls or other content
I choose canvas-container-outer, but I needed to modify its ancestors so it is always rendered, even when there is a build error.
To make sure we don't observe unnecessary elements, I filtered the query for the resize observer to only include elements with the data-uid attribute.

I needed to update the tests to make sure the observers from the previous domwalkermutablestate don't continue to fire when there is a change, because the outer canvas container can stay persistent between test runs.

Manual Tests:
I hereby swear that:

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

Fixes #6345

Copy link
Contributor

github-actions bot commented Sep 9, 2024

Try me

Copy link

relativeci bot commented Sep 9, 2024

#14173 Bundle Size — 62.61MiB (~+0.01%).

ee20966(current) vs 916e8b9 master#14171(baseline)

Warning

Bundle contains 70 duplicate packages – View duplicate packages

Bundle metrics  Change 2 changes Regression 1 regression
                 Current
#14173
     Baseline
#14171
Regression  Initial JS 45.74MiB(~+0.01%) 45.74MiB
No change  Initial CSS 0B 0B
Change  Cache Invalidation 21.67% 21.65%
No change  Chunks 30 30
No change  Assets 33 33
No change  Modules 4385 4385
No change  Duplicate Modules 523 523
No change  Duplicate Code 31.65% 31.65%
No change  Packages 472 472
No change  Duplicate Packages 70 70
Bundle size by type  Change 2 changes Regression 1 regression Improvement 1 improvement
                 Current
#14173
     Baseline
#14171
Regression  JS 62.6MiB (~+0.01%) 62.6MiB
Improvement  HTML 11.12KiB (-0.32%) 11.16KiB

Bundle analysis reportBranch fix/observer-without-canvas-rootProject dashboard


Generated by RelativeCIDocumentationReport issue

@gbalint gbalint changed the title Mutation/Resize observers are attached to the CanvasWrapperComponent Fix subscribing mutation/resize observers during a build error Sep 9, 2024
@gbalint gbalint marked this pull request as ready for review September 10, 2024 15:12
windowToCanvasPosition: this.getPosition,
cursor,
})
const canvasControls = (
Copy link
Contributor

Choose a reason for hiding this comment

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

so I am only reading this code and haven't tried it yet, but doesn't this mean this will become another div that is mounted a bit higher in the tree?

Copy link
Contributor

Choose a reason for hiding this comment

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

This was always there. Balint has just updated this to use JSX syntax rather than React.createElement

@gbalint gbalint merged commit a2d6ac7 into master Sep 11, 2024
22 checks passed
@gbalint gbalint deleted the fix/observer-without-canvas-root branch September 11, 2024 12:09
liady pushed a commit that referenced this pull request Dec 13, 2024
**Problem:**
Followup to #6326
In a Remix project it can happen that in the dispatch flow we don't have
the results of the rendering in the dom yet. It can even happen, that
after a build error is fixed, we still don't have the canvas root
container in the dom.
That is a critical issue, because we attach the mutation/resize
observers to the canvas root container element, so when we don't have
that we can subscribe them, so the dom sample is not going to run when
the rendering is finished.

**Fix:**
I needed an element, which is an ancestor of the canvas root container
and
1 is always rendered
2 does not contain canvas controls or other content
I choose canvas-container-outer, but I needed to modify its ancestors so
it is always rendered, even when there is a build error.
To make sure we don't observe unnecessary elements, I filtered the query
for the resize observer to only include elements with the `data-uid`
attribute.

I needed to update the tests to make sure the observers from the
previous domwalkermutablestate don't continue to fire when there is a
change, because the outer canvas container can stay persistent between
test runs.

**Manual Tests:**
I hereby swear that:

- [x] I opened a hydrogen project and it loaded
- [x] I could navigate to various routes in Preview mode

Fixes #6345
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.

remix project canvasrootcontainer is null after code editing
5 participants