-
Notifications
You must be signed in to change notification settings - Fork 172
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
Don't render when code ahead #6069
Changes from all commits
61044c8
db36d50
b55430b
1c41ac1
aa79ac5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -127,6 +127,7 @@ import { hasReactRouterErrorBeenLogged } from '../core/shared/runtime-report-log | |
import { InitialOnlineState, startOnlineStatusPolling } from '../components/editor/online-status' | ||
import { useAnimate } from 'framer-motion' | ||
import { AnimationContext } from '../components/canvas/ui-jsx-canvas-renderer/animation-context' | ||
import { anyCodeAhead } from '../components/assets' | ||
|
||
if (PROBABLY_ELECTRON) { | ||
let { webFrame } = requireElectron() | ||
|
@@ -450,7 +451,12 @@ export class Editor { | |
const reactRouterErrorPreviouslyLogged = hasReactRouterErrorBeenLogged() | ||
|
||
const runDomWalker = shouldRunDOMWalker(dispatchedActions, dispatchResult) | ||
const shouldRerender = !dispatchResult.nothingChanged || runDomWalker | ||
|
||
const somethingChanged = !dispatchResult.nothingChanged | ||
|
||
const shouldRerender = | ||
(somethingChanged || runDomWalker) && | ||
!anyCodeAhead(dispatchResult.unpatchedEditor.projectContents) | ||
|
||
const updateId = canvasUpdateId++ | ||
if (shouldRerender) { | ||
|
@@ -467,102 +473,101 @@ export class Editor { | |
}) | ||
}) | ||
}) | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. :narrows_eyes: the original code assumes that it only makes sense to run the dom-walker if there was a canvas render. is that assumption false? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I updated it to There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hmmm, but shouldRerender is already There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The dom walker should run whenever the canvas is rendered, hence the |
||
|
||
// run the dom-walker | ||
if (shouldRerender || runDomWalker) { | ||
const domWalkerDispatchResult = runDomWalkerAndSaveResults( | ||
this.boundDispatch, | ||
this.domWalkerMutableState, | ||
this.storedState, | ||
this.spyCollector, | ||
ElementsToRerenderGLOBAL.current, | ||
) | ||
|
||
// run the dom-walker | ||
if (runDomWalker) { | ||
const domWalkerDispatchResult = runDomWalkerAndSaveResults( | ||
if (domWalkerDispatchResult != null) { | ||
this.storedState = domWalkerDispatchResult | ||
entireUpdateFinished = Promise.all([ | ||
entireUpdateFinished, | ||
domWalkerDispatchResult.entireUpdateFinished, | ||
]) | ||
} | ||
} | ||
|
||
// true up groups if needed | ||
if (this.storedState.unpatchedEditor.trueUpElementsAfterDomWalkerRuns.length > 0) { | ||
// updated editor with trued up groups | ||
Measure.taskTime(`Group true up ${updateId}`, () => { | ||
const projectContentsBeforeGroupTrueUp = this.storedState.unpatchedEditor.projectContents | ||
const dispatchResultWithTruedUpGroups = editorDispatchActionRunner( | ||
this.boundDispatch, | ||
this.domWalkerMutableState, | ||
[{ action: 'TRUE_UP_ELEMENTS' }], | ||
this.storedState, | ||
this.spyCollector, | ||
ElementsToRerenderGLOBAL.current, | ||
) | ||
this.storedState = dispatchResultWithTruedUpGroups | ||
|
||
if (domWalkerDispatchResult != null) { | ||
this.storedState = domWalkerDispatchResult | ||
entireUpdateFinished = Promise.all([ | ||
entireUpdateFinished, | ||
domWalkerDispatchResult.entireUpdateFinished, | ||
]) | ||
entireUpdateFinished = Promise.all([ | ||
entireUpdateFinished, | ||
dispatchResultWithTruedUpGroups.entireUpdateFinished, | ||
]) | ||
|
||
if ( | ||
projectContentsBeforeGroupTrueUp === this.storedState.unpatchedEditor.projectContents | ||
) { | ||
// no group-related re-render / re-measure is needed, bail out | ||
return | ||
} | ||
} | ||
|
||
// true up groups if needed | ||
if (this.storedState.unpatchedEditor.trueUpElementsAfterDomWalkerRuns.length > 0) { | ||
// updated editor with trued up groups | ||
Measure.taskTime(`Group true up ${updateId}`, () => { | ||
const projectContentsBeforeGroupTrueUp = | ||
this.storedState.unpatchedEditor.projectContents | ||
const dispatchResultWithTruedUpGroups = editorDispatchActionRunner( | ||
// re-render the canvas | ||
Measure.taskTime(`Canvas re-render because of groups ${updateId}`, () => { | ||
ElementsToRerenderGLOBAL.current = fixElementsToRerender( | ||
this.storedState.patchedEditor.canvas.elementsToRerender, | ||
dispatchedActions, | ||
) // Mutation! | ||
|
||
ReactDOM.flushSync(() => { | ||
ReactDOM.unstable_batchedUpdates(() => { | ||
this.canvasStore.setState( | ||
patchedStoreFromFullStore(this.storedState, 'canvas-store'), | ||
) | ||
}) | ||
}) | ||
}) | ||
|
||
// re-run the dom-walker | ||
Measure.taskTime(`Dom walker re-run because of groups ${updateId}`, () => { | ||
const domWalkerDispatchResult = runDomWalkerAndSaveResults( | ||
this.boundDispatch, | ||
[{ action: 'TRUE_UP_ELEMENTS' }], | ||
this.domWalkerMutableState, | ||
this.storedState, | ||
this.spyCollector, | ||
ElementsToRerenderGLOBAL.current, | ||
) | ||
this.storedState = dispatchResultWithTruedUpGroups | ||
|
||
entireUpdateFinished = Promise.all([ | ||
entireUpdateFinished, | ||
dispatchResultWithTruedUpGroups.entireUpdateFinished, | ||
]) | ||
|
||
if ( | ||
projectContentsBeforeGroupTrueUp === this.storedState.unpatchedEditor.projectContents | ||
) { | ||
// no group-related re-render / re-measure is needed, bail out | ||
return | ||
if (domWalkerDispatchResult != null) { | ||
this.storedState = domWalkerDispatchResult | ||
entireUpdateFinished = Promise.all([ | ||
entireUpdateFinished, | ||
domWalkerDispatchResult.entireUpdateFinished, | ||
]) | ||
} | ||
|
||
// re-render the canvas | ||
Measure.taskTime(`Canvas re-render because of groups ${updateId}`, () => { | ||
ElementsToRerenderGLOBAL.current = fixElementsToRerender( | ||
this.storedState.patchedEditor.canvas.elementsToRerender, | ||
dispatchedActions, | ||
) // Mutation! | ||
|
||
ReactDOM.flushSync(() => { | ||
ReactDOM.unstable_batchedUpdates(() => { | ||
this.canvasStore.setState( | ||
patchedStoreFromFullStore(this.storedState, 'canvas-store'), | ||
) | ||
}) | ||
}) | ||
}) | ||
|
||
// re-run the dom-walker | ||
Measure.taskTime(`Dom walker re-run because of groups ${updateId}`, () => { | ||
const domWalkerDispatchResult = runDomWalkerAndSaveResults( | ||
this.boundDispatch, | ||
this.domWalkerMutableState, | ||
this.storedState, | ||
this.spyCollector, | ||
ElementsToRerenderGLOBAL.current, | ||
) | ||
|
||
if (domWalkerDispatchResult != null) { | ||
this.storedState = domWalkerDispatchResult | ||
entireUpdateFinished = Promise.all([ | ||
entireUpdateFinished, | ||
domWalkerDispatchResult.entireUpdateFinished, | ||
]) | ||
} | ||
}) | ||
}) | ||
} | ||
|
||
this.storedState = editorDispatchClosingOut( | ||
this.boundDispatch, | ||
dispatchedActions, | ||
oldEditorState, | ||
{ | ||
...this.storedState, | ||
entireUpdateFinished: entireUpdateFinished, | ||
nothingChanged: dispatchResult.nothingChanged, | ||
}, | ||
reactRouterErrorPreviouslyLogged, | ||
) | ||
}) | ||
} | ||
|
||
this.storedState = editorDispatchClosingOut( | ||
this.boundDispatch, | ||
dispatchedActions, | ||
oldEditorState, | ||
{ | ||
...this.storedState, | ||
entireUpdateFinished: entireUpdateFinished, | ||
nothingChanged: dispatchResult.nothingChanged, | ||
}, | ||
reactRouterErrorPreviouslyLogged, | ||
) | ||
|
||
Measure.taskTime(`Update Editor ${updateId}`, () => { | ||
ReactDOM.flushSync(() => { | ||
ReactDOM.unstable_batchedUpdates(() => { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that
shouldRerender
was actually very badly named here, and so changed some of the gating of the code below accordingly. It's worth expanding the diff below to understand what is actually happening now