Skip to content

Commit

Permalink
DomWalkerObservers know about ElementsToRerenderGLOBAL (#6383)
Browse files Browse the repository at this point in the history
**Problem:**
The dom-walker observers (now used for triggering the dom-sampler) fire
for continuous interactions that don't have
`editor.canvas.interactionSession`, such as scrubbing in the inspector.

**Fix:**
The mutation callback now checks if `ElementsToRerenderGLOBAL.current`
is in selective mode, and then it will behave similarly to when there is
an active interactionSession.

**Commit Details:**

- Renamed `selectCanvasInteractionHappening ` to
`isCanvasInteractionHappening`
- `isCanvasInteractionHappening` is aware of
ElementsToRerenderGLOBAL.current
  • Loading branch information
balazsbajorics authored Sep 18, 2024
1 parent 57d569c commit b75611c
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions editor/src/components/canvas/dom-walker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ import { getFlexAlignment, getFlexJustifyContent, MaxContent } from '../inspecto
import type { EditorDispatch } from '../editor/action-types'
import { runDOMWalker } from '../editor/actions/action-creators'
import { CanvasContainerOuterId } from './canvas-component-entry'
import { ElementsToRerenderGLOBAL } from './ui-jsx-canvas'

export const ResizeObserver =
window.ResizeObserver ?? ResizeObserverSyntheticDefault.default ?? ResizeObserverSyntheticDefault
Expand Down Expand Up @@ -306,9 +307,9 @@ export function resubscribeObservers(domWalkerMutableState: {
}
}

function selectCanvasInteractionHappening(store: EditorStorePatched): boolean {
function isCanvasInteractionHappening(store: EditorStorePatched): boolean {
const interactionSessionActive = store.editor.canvas.interactionSession != null
return interactionSessionActive
return interactionSessionActive || ElementsToRerenderGLOBAL.current !== 'rerender-all-elements'
}

export function initDomWalkerObservers(
Expand All @@ -329,7 +330,7 @@ export function initDomWalkerObservers(
// adequately assess the performance impact of doing so, and ideally find a way to only do so when the observed
// change was not triggered by a user interaction
const resizeObserver = new ResizeObserver((entries: ResizeObserverEntry[]) => {
const canvasInteractionHappening = selectCanvasInteractionHappening(editorStore.getState())
const canvasInteractionHappening = isCanvasInteractionHappening(editorStore.getState())
const selectedViews = editorStore.getState().editor.selectedViews
if (canvasInteractionHappening) {
// Warning this only adds the selected views instead of the observed element
Expand All @@ -352,7 +353,7 @@ export function initDomWalkerObservers(
})

const mutationObserver = new window.MutationObserver((mutations: MutationRecord[]) => {
const canvasInteractionHappening = selectCanvasInteractionHappening(editorStore.getState())
const canvasInteractionHappening = isCanvasInteractionHappening(editorStore.getState())
const selectedViews = editorStore.getState().editor.selectedViews

if (canvasInteractionHappening) {
Expand Down

0 comments on commit b75611c

Please sign in to comment.