Skip to content

Virtual whiteboard for sketching hand-drawn like diagrams

fix(editor): optimize UI rendering during animation (#11604)

David Luzar9357f98a9b6c
diff --git a/packages/element/src/groups.ts b/packages/element/src/groups.ts
index 40f787a01b..b5f9282ba0 100644
--- a/packages/element/src/groups.ts
+++ b/packages/element/src/groups.ts
@@ -212,7 +212,10 @@ export const selectGroupsForSelectedElements = (function () {
* selection border around it.
*/
export const isSelectedViaGroup = (
- appState: InteractiveCanvasAppState,
+ appState: Pick<
+ InteractiveCanvasAppState,
+ "editingGroupId" | "selectedGroupIds"
+ >,
element: ExcalidrawElement,
) => getSelectedGroupForElement(appState, element) != null;
@@ -228,7 +231,7 @@ export const getSelectedGroupForElement = (
.find((groupId) => appState.selectedGroupIds[groupId]);
export const getSelectedGroupIds = (
- appState: InteractiveCanvasAppState,
+ appState: Pick<InteractiveCanvasAppState, "selectedGroupIds">,
): GroupId[] =>
Object.entries(appState.selectedGroupIds)
.filter(([groupId, isSelected]) => isSelected)
@@ -410,7 +413,7 @@ export const getNewGroupIdsForDuplication = (
export const getSelectedElementsByGroup = (
selectedElements: ExcalidrawElement[],
elementsMap: ElementsMap,
- appState: Readonly<AppState>,
+ appState: Readonly<Pick<AppState, "selectedGroupIds" | "editingGroupId">>,
): ExcalidrawElement[][] => {
const selectedGroupIds = getSelectedGroupIds(appState);
const unboundElements = selectedElements.filter(
diff --git a/packages/excalidraw/CHANGELOG.md b/packages/excalidraw/CHANGELOG.md
index 66919506e5..d403df6d04 100644
--- a/packages/excalidraw/CHANGELOG.md
+++ b/packages/excalidraw/CHANGELOG.md
@@ -53,6 +53,27 @@ Please add the latest change on the top under the correct section.
### Breaking changes
+- `UIAppState` no longer includes `zoom`, `shouldCacheIgnoreZoom`, and the canvas-interaction transients `snapLines`, `originSnapOffset`, `suggestedBinding`, `frameToHighlight`, and `elementsToHighlight`. These update per pointermove or per animation frame and no longer re-render the editor UI, so UI render props receiving `UIAppState` (`renderCustomStats`, custom `<Footer/>` content, etc.) don't receive them anymore and would render stale values if they read them off the full `AppState`. Subscribe through `useExcalidrawStateValue` instead — the component re-renders only when the selected value changes:
+
+ ```tsx
+ import { useExcalidrawStateValue } from "@excalidraw/excalidraw";
+
+ const ZoomReadout = () => {
+ // `undefined` on initial render, before the editor API initializes
+ const zoomValue = useExcalidrawStateValue(
+ (appState) => appState.zoom.value,
+ );
+
+ if (zoomValue == null) {
+ return null;
+ }
+
+ return <div>{(zoomValue * 100).toFixed(0)}%</div>;
+ };
+ ```
+
+ Outside of React components, you can also subscribe via `ExcalidrawAPI.onStateChange((appState) => appState.zoom.value, (zoomValue) => {...})`, or keep using the existing `onScrollChange(scrollX, scrollY, zoom)` prop.
+
- Theme changes initiated by the default UI are now delegated to `<Excalidraw onThemeChange={(theme) => ...} />` when supplied. If `onThemeChange` is not supplied, light/dark theme toggling still falls back to updating the internal editor state.
- `MainMenu.DefaultItems.ToggleTheme` no longer accepts the item-level `onSelect` callback. Host apps that need to control light/dark/system theme should pass `onThemeChange` to `<Excalidraw />` instead.
diff --git a/packages/excalidraw/actions/actionCanvas.tsx b/packages/excalidraw/actions/actionCanvas.tsx
index e98274060c..f6e6e88f41 100644
--- a/packages/excalidraw/actions/actionCanvas.tsx
+++ b/packages/excalidraw/actions/actionCanvas.tsx
@@ -36,6 +36,7 @@ import {
ZoomResetIcon,
} from "../components/icons";
import { setCursor } from "../cursor";
+import { useAppStateValue } from "../hooks/useAppStateValue";
import { t } from "../i18n";
import { getNormalizedZoom } from "../scene";
@@ -151,19 +152,22 @@ export const actionZoomIn = register({
captureUpdate: CaptureUpdateAction.EVENTUALLY,
};
},
- PanelComponent: ({ updateData, appState }) => (
- <ToolButton
- type="button"
- className="zoom-in-button zoom-button"
- icon={ZoomInIcon}
- title={`${t("buttons.zoomIn")} — ${getShortcutKey("CtrlOrCmd++")}`}
- aria-label={t("buttons.zoomIn")}
- disabled={appState.zoom.value >= MAX_ZOOM}
- onClick={() => {
- updateData(null);
- }}
- />
- ),
+ PanelComponent: ({ updateData }) => {
+ const zoomValue = useAppStateValue((appState) => appState.zoom.value);
+ return (
+ <ToolButton
+ type="button"
+ className="zoom-in-button zoom-button"
+ icon={ZoomInIcon}
+ title={`${t("buttons.zoomIn")} — ${getShortcutKey("CtrlOrCmd++")}`}
+ aria-label={t("buttons.zoomIn")}
+ disabled={zoomValue >= MAX_ZOOM}
+ onClick={() => {
+ updateData(null);
+ }}
+ />
+ );
+ },
keyTest: (event) =>
(event.code === CODES.EQUAL || event.code === CODES.NUM_ADD) &&
(event[KEYS.CTRL_OR_CMD] || event.shiftKey),
@@ -193,19 +197,22 @@ export const actionZoomOut = register({
captureUpdate: CaptureUpdateAction.EVENTUALLY,
};
},
- PanelComponent: ({ updateData, appState }) => (
- <ToolButton
- type="button"
- className="zoom-out-button zoom-button"
- icon={ZoomOutIcon}
- title={`${t("buttons.zoomOut")} — ${getShortcutKey("CtrlOrCmd+-")}`}
- aria-label={t("buttons.zoomOut")}
- disabled={appState.zoom.value <= MIN_ZOOM}
- onClick={() => {
- updateData(null);
- }}
- />
- ),
+ PanelComponent: ({ updateData }) => {
+ const zoomValue = useAppStateValue((appState) => appState.zoom.value);
+ return (
+ <ToolButton
+ type="button"
+ className="zoom-out-button zoom-button"
+ icon={ZoomOutIcon}
+ title={`${t("buttons.zoomOut")} — ${getShortcutKey("CtrlOrCmd+-")}`}
+ aria-label={t("buttons.zoomOut")}
+ disabled={zoomValue <= MIN_ZOOM}
+ onClick={() => {
+ updateData(null);
+ }}
+ />
+ );
+ },
keyTest: (event) =>
(event.code === CODES.MINUS || event.code === CODES.NUM_SUBTRACT) &&
(event[KEYS.CTRL_OR_CMD] || event.shiftKey),
@@ -241,21 +248,24 @@ export const actionResetZoom = register({
captureUpdate: CaptureUpdateAction.EVENTUALLY,
};
},
- PanelComponent: ({ updateData, appState }) => (
- <Tooltip label={t("buttons.resetZoom")} style={{ height: "100%" }}>
- <ToolButton
- type="button"
- className="reset-zoom-button zoom-button"
- title={t("buttons.resetZoom")}
- aria-label={t("buttons.resetZoom")}
- onClick={() => {
- updateData(null);
- }}
- >
- {(appState.zoom.value * 100).toFixed(0)}%
- </ToolButton>
- </Tooltip>
- ),
+ PanelComponent: ({ updateData }) => {
+ const zoomValue = useAppStateValue((appState) => appState.zoom.value);
+ return (
+ <Tooltip label={t("buttons.resetZoom")} style={{ height: "100%" }}>
+ <ToolButton
+ type="button"
+ className="reset-zoom-button zoom-button"
+ title={t("buttons.resetZoom")}
+ aria-label={t("buttons.resetZoom")}
+ onClick={() => {
+ updateData(null);
+ }}
+ >
+ {(zoomValue * 100).toFixed(0)}%
+ </ToolButton>
+ </Tooltip>
+ );
+ },
keyTest: (event) =>
(event.code === CODES.ZERO || event.code === CODES.NUM_ZERO) &&
(event[KEYS.CTRL_OR_CMD] || event.shiftKey),
diff --git a/packages/excalidraw/actions/actionDistribute.tsx b/packages/excalidraw/actions/actionDistribute.tsx
index 6c75603478..eb37030461 100644
--- a/packages/excalidraw/actions/actionDistribute.tsx
+++ b/packages/excalidraw/actions/actionDistribute.tsx
@@ -30,15 +30,15 @@ import { getShortcutKey } from "../shortcut";
import { register } from "./register";
-import type { AppClassProperties, AppState } from "../types";
+import type { AppClassProperties, AppState, UIAppState } from "../types";
-const enableActionGroup = (appState: AppState, app: AppClassProperties) => {
+const enableActionGroup = (appState: UIAppState, app: AppClassProperties) => {
const selectedElements = app.scene.getSelectedElements(appState);
return (
getSelectedElementsByGroup(
selectedElements,
app.scene.getNonDeletedElementsMap(),
- appState as Readonly<AppState>,
+ appState,
).length > 2 &&
// TODO enable distributing frames when implemented properly
!selectedElements.some((el) => isFrameLikeElement(el))
diff --git a/packages/excalidraw/actions/actionFrame.ts b/packages/excalidraw/actions/actionFrame.ts
index 81a43e243e..eebce334af 100644
--- a/packages/excalidraw/actions/actionFrame.ts
+++ b/packages/excalidraw/actions/actionFrame.ts
@@ -24,7 +24,7 @@ import { getSelectedElements } from "../scene";
import { register } from "./register";
-import type { AppClassProperties, AppState, UIAppState } from "../types";
+import type { AppClassProperties, UIAppState } from "../types";
const isSingleFrameSelected = (
appState: UIAppState,
@@ -123,7 +123,7 @@ export const actionupdateFrameRendering = register({
captureUpdate: CaptureUpdateAction.EVENTUALLY,
};
},
- checked: (appState: AppState) => appState.frameRendering.enabled,
+ checked: (appState) => appState.frameRendering.enabled,
});
export const actionSetFrameAsActiveTool = register({
diff --git a/packages/excalidraw/actions/actionGroup.tsx b/packages/excalidraw/actions/actionGroup.tsx
index c9bb8cf21d..fd72dfcb50 100644
--- a/packages/excalidraw/actions/actionGroup.tsx
+++ b/packages/excalidraw/actions/actionGroup.tsx
@@ -47,7 +47,7 @@ import { getShortcutKey } from "../shortcut";
import { register } from "./register";
-import type { AppClassProperties, AppState } from "../types";
+import type { AppClassProperties, UIAppState } from "../types";
const allElementsInSameGroup = (elements: readonly ExcalidrawElement[]) => {
if (elements.length >= 2) {
@@ -68,7 +68,7 @@ const allElementsInSameGroup = (elements: readonly ExcalidrawElement[]) => {
const enableActionGroup = (
elements: readonly ExcalidrawElement[],
- appState: AppState,
+ appState: UIAppState,
app: AppClassProperties,
) => {
const selectedElements = app.scene.getSelectedElements({
diff --git a/packages/excalidraw/actions/actionToggleGridMode.tsx b/packages/excalidraw/actions/actionToggleGridMode.tsx
index 1fcc882fd2..dc6be16905 100644
--- a/packages/excalidraw/actions/actionToggleGridMode.tsx
+++ b/packages/excalidraw/actions/actionToggleGridMode.tsx
@@ -6,8 +6,6 @@ import { gridIcon } from "../components/icons";
import { register } from "./register";
-import type { AppState } from "../types";
-
export const actionToggleGridMode = register({
name: "gridMode",
icon: gridIcon,
@@ -28,7 +26,7 @@ export const actionToggleGridMode = register({
captureUpdate: CaptureUpdateAction.EVENTUALLY,
};
},
- checked: (appState: AppState) => appState.gridModeEnabled,
+ checked: (appState) => appState.gridModeEnabled,
predicate: (element, appState, props) => {
return props.gridModeEnabled === undefined;
},
diff --git a/packages/excalidraw/actions/actionToggleSearchMenu.ts b/packages/excalidraw/actions/actionToggleSearchMenu.ts
index e703b54dca..ef7516160c 100644
--- a/packages/excalidraw/actions/actionToggleSearchMenu.ts
+++ b/packages/excalidraw/actions/actionToggleSearchMenu.ts
@@ -11,8 +11,6 @@ import { searchIcon } from "../components/icons";
import { register } from "./register";
-import type { AppState } from "../types";
-
export const actionToggleSearchMenu = register({
name: "searchMenu",
icon: searchIcon,
@@ -52,7 +50,7 @@ export const actionToggleSearchMenu = register({
captureUpdate: CaptureUpdateAction.EVENTUALLY,
};
},
- checked: (appState: AppState) => appState.gridModeEnabled,
+ checked: (appState) => appState.gridModeEnabled,
predicate: (element, appState, props) => {
return props.gridModeEnabled === undefined;
},
diff --git a/packages/excalidraw/actions/types.ts b/packages/excalidraw/actions/types.ts
index 54c46c02f4..ba9c64bd54 100644
--- a/packages/excalidraw/actions/types.ts
+++ b/packages/excalidraw/actions/types.ts
@@ -150,7 +150,10 @@ export type ActionName =
export type PanelComponentProps = {
elements: readonly ExcalidrawElement[];
- appState: AppState;
+ // UIAppState (not AppState) because PanelComponents only re-render when
+ // the UI does — reading UI-stripped props (zoom, scroll, …) would render
+ // stale values; subscribe via useAppStateValue for those instead
+ appState: UIAppState;
updateData: <T = any>(formData?: T) => void;
appProps: ExcalidrawProps;
data?: Record<string, any>;
@@ -167,7 +170,7 @@ export interface Action<TData = any> {
| string
| ((
elements: readonly ExcalidrawElement[],
- appState: Readonly<AppState>,
+ appState: Readonly<UIAppState>,
app: AppClassProperties,
) => string);
keywords?: string[];
@@ -192,7 +195,7 @@ export interface Action<TData = any> {
appProps: ExcalidrawProps,
app: AppClassProperties,
) => boolean;
- checked?: (appState: Readonly<AppState>) => boolean;
+ checked?: (appState: Readonly<UIAppState>) => boolean;
trackEvent:
| false
| {
diff --git a/packages/excalidraw/components/Actions.tsx b/packages/excalidraw/components/Actions.tsx
index 20ae6c8fa9..4651b87e49 100644
--- a/packages/excalidraw/components/Actions.tsx
+++ b/packages/excalidraw/components/Actions.tsx
@@ -91,7 +91,6 @@ import type {
AppClassProperties,
AppProps,
UIAppState,
- Zoom,
AppState,
} from "../types";
import type { ActionManager } from "../actions/manager";
@@ -1315,10 +1314,8 @@ export const ShapesSwitcher = ({
export const ZoomActions = ({
renderAction,
- zoom,
}: {
renderAction: ActionManager["renderAction"];
- zoom: Zoom;
}) => (
<Stack.Col gap={1} className={CLASSES.ZOOM_ACTIONS}>
<Stack.Row align="center">
diff --git a/packages/excalidraw/components/App.tsx b/packages/excalidraw/components/App.tsx
index 8af41d744a..74030f11e6 100644
--- a/packages/excalidraw/components/App.tsx
+++ b/packages/excalidraw/components/App.tsx
@@ -674,6 +674,9 @@ class App extends React.Component<AppProps, AppState> {
public fonts: Fonts;
public renderer: Renderer;
public visibleElements: readonly NonDeletedExcalidrawElement[];
+ /** whether the last render had any renderable elements (excludes e.g. the
+ * in-progress `newElement` and the edited text element) */
+ private hasRenderableElements: boolean = false;
private resizeObserver: ResizeObserver | undefined;
public library: AppClassProperties["library"];
public libraryItemsFromStorage: LibraryItems | undefined;
@@ -2132,7 +2135,7 @@ class App extends React.Component<AppProps, AppState> {
const { renderTopRightUI, renderTopLeftUI, renderCustomStats } = this.props;
const {
- elementsMap,
+ elementsMap: renderableElementsMap,
visibleElements,
canvasNonce,
/**
@@ -2156,6 +2159,7 @@ class App extends React.Component<AppProps, AppState> {
frameToHighlight: this.state.frameToHighlight,
});
this.visibleElements = visibleElements;
+ this.hasRenderableElements = renderableElementsMap.size > 0;
const allElementsMap = this.scene.getNonDeletedElementsMap();
@@ -2286,7 +2290,7 @@ class App extends React.Component<AppProps, AppState> {
isMagicFrameElement(firstSelectedElement) && (
<ElementCanvasButtons
element={firstSelectedElement}
- elementsMap={elementsMap}
+ elementsMap={renderableElementsMap}
>
<ElementCanvasButton
title={t("labels.convertToCode")}
@@ -2307,7 +2311,7 @@ class App extends React.Component<AppProps, AppState> {
?.status === "done" && (
<ElementCanvasButtons
element={firstSelectedElement}
- elementsMap={elementsMap}
+ elementsMap={renderableElementsMap}
>
<ElementCanvasButton
title={t("labels.copySource")}
@@ -2370,7 +2374,7 @@ class App extends React.Component<AppProps, AppState> {
<StaticCanvas
canvas={this.canvas}
rc={this.rc}
- elementsMap={elementsMap}
+ elementsMap={renderableElementsMap}
allElementsMap={allElementsMap}
visibleElements={visibleElements}
canvasNonce={canvasNonce}
@@ -2400,7 +2404,7 @@ class App extends React.Component<AppProps, AppState> {
newElement={newElementCanvasElement}
scale={window.devicePixelRatio}
rc={this.rc}
- elementsMap={elementsMap}
+ elementsMap={renderableElementsMap}
allElementsMap={allElementsMap}
renderConfig={{
imageCache: this.imageCache,
@@ -2421,7 +2425,7 @@ class App extends React.Component<AppProps, AppState> {
app={this}
containerRef={this.excalidrawContainerRef}
canvas={this.interactiveCanvas}
- elementsMap={elementsMap}
+ elementsMap={renderableElementsMap}
visibleElements={visibleElements}
allElementsMap={allElementsMap}
selectedElements={selectedElements}
@@ -3619,6 +3623,21 @@ class App extends React.Component<AppProps, AppState> {
this.setState({ editingTextElement: null });
}
+ // Forced false while a viewport animation runs — the scroll-back-to-content
+ // button must not render mid-animation (clicking it would fight the
+ // animation, which overwrites the viewport every frame). The animation's
+ // final commit lands after the animation is unregistered, settling this
+ // on the target viewport.
+ const scrolledOutside =
+ // hide when editing text
+ this.state.editingTextElement ||
+ AnimationController.running(SCROLL_TO_CONTENT_ANIMATION_KEY)
+ ? false
+ : !this.visibleElements.length && this.hasRenderableElements;
+ if (this.state.scrolledOutside !== scrolledOutside) {
+ this.setState({ scrolledOutside });
+ }
+
this.store.commit(elementsMap, this.state);
// Do not notify consumers if we're still loading the scene. Among other
@@ -3632,21 +3651,11 @@ class App extends React.Component<AppProps, AppState> {
}
private renderInteractiveSceneCallback = ({
- atLeastOneVisibleElement,
scrollBars,
- elementsMap,
}: RenderInteractiveSceneCallback) => {
if (scrollBars) {
currentScrollBars = scrollBars;
}
- const scrolledOutside =
- // hide when editing text
- this.state.editingTextElement
- ? false
- : !atLeastOneVisibleElement && elementsMap.size > 0;
- if (this.state.scrolledOutside !== scrolledOutside) {
- this.setState({ scrolledOutside });
- }
this.scheduleImageRefresh();
};
@@ -9713,7 +9722,6 @@ class App extends React.Component<AppProps, AppState> {
...prevState,
bindMode: "orbit",
newElement: element,
- startBoundElement: boundElement,
suggestedBinding:
boundElement && isBindingElement(element)
? {
diff --git a/packages/excalidraw/components/ColorPicker/ColorPicker.tsx b/packages/excalidraw/components/ColorPicker/ColorPicker.tsx
index f76c109280..f15d7eb38f 100644
--- a/packages/excalidraw/components/ColorPicker/ColorPicker.tsx
+++ b/packages/excalidraw/components/ColorPicker/ColorPicker.tsx
@@ -36,7 +36,7 @@ import "./ColorPicker.scss";
import type { ColorPickerType } from "./colorPickerUtils";
-import type { AppState } from "../../types";
+import type { AppState, UIAppState } from "../../types";
interface ColorPickerProps {
type: ColorPickerType;
@@ -48,7 +48,7 @@ interface ColorPickerProps {
onChange: (color: string) => void;
label: string;
elements: readonly ExcalidrawElement[];
- appState: AppState;
+ appState: UIAppState;
palette?: ColorPaletteCustom | null;
topPicks?: ColorTuple;
updateData: (formData?: any) => void;
diff --git a/packages/excalidraw/components/CommandPalette/CommandPalette.tsx b/packages/excalidraw/components/CommandPalette/CommandPalette.tsx
index d87d1d1b40..bfa336cf21 100644
--- a/packages/excalidraw/components/CommandPalette/CommandPalette.tsx
+++ b/packages/excalidraw/components/CommandPalette/CommandPalette.tsx
@@ -261,7 +261,7 @@ function CommandPaletteInner({
label = t(
action.label(
app.scene.getNonDeletedElements(),
- uiAppState as AppState,
+ uiAppState,
app,
) as unknown as TranslationKeys,
);
diff --git a/packages/excalidraw/components/LayerUI.tsx b/packages/excalidraw/components/LayerUI.tsx
index 355d39c088..e094140b92 100644
--- a/packages/excalidraw/components/LayerUI.tsx
+++ b/packages/excalidraw/components/LayerUI.tsx
@@ -675,7 +675,19 @@ const LayerUI = ({
};
const stripIrrelevantAppStateProps = (appState: AppState): UIAppState => {
- const { cursorButton, scrollX, scrollY, ...ret } = appState;
+ const {
+ cursorButton,
+ scrollX,
+ scrollY,
+ zoom,
+ shouldCacheIgnoreZoom,
+ snapLines,
+ originSnapOffset,
+ suggestedBinding,
+ frameToHighlight,
+ elementsToHighlight,
+ ...ret
+ } = appState;
return ret;
};
diff --git a/packages/excalidraw/components/footer/Footer.tsx b/packages/excalidraw/components/footer/Footer.tsx
index debbf332e6..e46253bce2 100644
--- a/packages/excalidraw/components/footer/Footer.tsx
+++ b/packages/excalidraw/components/footer/Footer.tsx
@@ -36,10 +36,7 @@ const Footer = ({
>
<Stack.Col gap={2}>
<Section heading="canvasActions">
- <ZoomActions
- renderAction={actionManager.renderAction}
- zoom={appState.zoom}
- />
+ <ZoomActions renderAction={actionManager.renderAction} />
{!appState.viewModeEnabled && (
<UndoRedoActions
diff --git a/packages/excalidraw/components/hyperlink/helpers.ts b/packages/excalidraw/components/hyperlink/helpers.ts
index 9f68734b54..f49c1a961d 100644
--- a/packages/excalidraw/components/hyperlink/helpers.ts
+++ b/packages/excalidraw/components/hyperlink/helpers.ts
@@ -12,7 +12,7 @@ import type {
NonDeletedExcalidrawElement,
} from "@excalidraw/element/types";
-import type { AppState, UIAppState } from "../../types";
+import type { AppState } from "../../types";
export const DEFAULT_LINK_SIZE = 12;
@@ -29,7 +29,7 @@ ELEMENT_LINK_IMG.src = `data:${MIME_TYPES.svg}, ${encodeURIComponent(
export const getLinkHandleFromCoords = (
[x1, y1, x2, y2]: Bounds,
angle: Radians,
- appState: Pick<UIAppState, "zoom">,
+ appState: Pick<AppState, "zoom">,
): Bounds => {
const size = DEFAULT_LINK_SIZE;
const zoom = appState.zoom.value > 1 ? appState.zoom.value : 1;
diff --git a/packages/excalidraw/renderer/interactiveScene.ts b/packages/excalidraw/renderer/interactiveScene.ts
index 30cadb0ef7..e19df683db 100644
--- a/packages/excalidraw/renderer/interactiveScene.ts
+++ b/packages/excalidraw/renderer/interactiveScene.ts
@@ -1564,12 +1564,10 @@ const _renderInteractiveScene = ({
deltaTime,
}: InteractiveSceneRenderConfig): {
scrollBars?: ReturnType<typeof getScrollBars>;
- atLeastOneVisibleElement: boolean;
- elementsMap: RenderableElementsMap;
animationState?: typeof animationState;
} => {
if (canvas === null) {
- return { atLeastOneVisibleElement: false, elementsMap };
+ return {};
}
const [normalizedWidth, normalizedHeight] = getNormalizedCanvasDimensions(
@@ -2069,8 +2067,6 @@ const _renderInteractiveScene = ({
return {
scrollBars,
- atLeastOneVisibleElement: visibleElements.length > 0,
- elementsMap,
animationState: nextAnimationState,
};
};
diff --git a/packages/excalidraw/scene/types.ts b/packages/excalidraw/scene/types.ts
index 59c421f8aa..db168ab225 100644
--- a/packages/excalidraw/scene/types.ts
+++ b/packages/excalidraw/scene/types.ts
@@ -74,8 +74,6 @@ export type InteractiveCanvasRenderConfig = {
};
export type RenderInteractiveSceneCallback = {
- atLeastOneVisibleElement: boolean;
- elementsMap: RenderableElementsMap;
scrollBars?: ScrollBars;
};
diff --git a/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap
index ba46b1e33b..fc3fa4b8ba 100644
--- a/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap
+++ b/packages/excalidraw/tests/__snapshots__/history.test.tsx.snap
@@ -100,7 +100,6 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"showHyperlinkPopup": false,
"showWelcomeScreen": true,
"snapLines": [],
- "startBoundElement": null,
"stats": {
"open": false,
"panels": 3,
@@ -736,7 +735,6 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"showHyperlinkPopup": false,
"showWelcomeScreen": true,
"snapLines": [],
- "startBoundElement": null,
"stats": {
"open": false,
"panels": 3,
@@ -2289,40 +2287,6 @@ exports[`history > multiplayer undo/redo > conflicts in arrows and their bindabl
"showHyperlinkPopup": false,
"showWelcomeScreen": true,
"snapLines": [],
- "startBoundElement": {
- "angle": 0,
- "backgroundColor": "transparent",
- "boundElements": [
- {
- "id": "id4",
- "type": "arrow",
- },
- ],
- "customData": undefined,
- "fillStyle": "solid",
- "frameId": null,
- "groupIds": [],
- "height": 100,
- "id": "id0",
- "index": "a0",
- "isDeleted": false,
- "link": null,
- "locked": false,
- "opacity": 100,
- "roughness": 1,
- "roundness": null,
- "seed": 1,
- "strokeColor": "#1e1e1e",
- "strokeStyle": "solid",
- "strokeWidth": 2,
- "type": "rectangle",
- "updated": 1,
- "version": 3,
- "versionNonce": 493213705,
- "width": 100,
- "x": -100,
- "y": -50,
- },
"stats": {
"open": false,
"panels": 3,
@@ -7434,7 +7398,6 @@ exports[`history > multiplayer undo/redo > should iterate through the history wh
"showHyperlinkPopup": false,
"showWelcomeScreen": true,
"snapLines": [],
- "startBoundElement": null,
"stats": {
"open": false,
"panels": 3,
@@ -10434,7 +10397,6 @@ exports[`history > multiplayer undo/redo > should override remotely added points
"showHyperlinkPopup": false,
"showWelcomeScreen": true,
"snapLines": [],
- "startBoundElement": null,
"stats": {
"open": false,
"panels": 3,
@@ -16721,7 +16683,6 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"showHyperlinkPopup": false,
"showWelcomeScreen": true,
"snapLines": [],
- "startBoundElement": null,
"stats": {
"open": false,
"panels": 3,
@@ -17472,7 +17433,6 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"showHyperlinkPopup": false,
"showWelcomeScreen": true,
"snapLines": [],
- "startBoundElement": null,
"stats": {
"open": false,
"panels": 3,
@@ -18121,7 +18081,6 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"showHyperlinkPopup": false,
"showWelcomeScreen": true,
"snapLines": [],
- "startBoundElement": null,
"stats": {
"open": false,
"panels": 3,
@@ -18768,7 +18727,6 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"showHyperlinkPopup": false,
"showWelcomeScreen": true,
"snapLines": [],
- "startBoundElement": null,
"stats": {
"open": false,
"panels": 3,
@@ -19523,7 +19481,6 @@ exports[`history > singleplayer undo/redo > should support bidirectional binding
"showHyperlinkPopup": false,
"showWelcomeScreen": true,
"snapLines": [],
- "startBoundElement": null,
"stats": {
"open": false,
"panels": 3,
@@ -21749,7 +21706,6 @@ exports[`history > singleplayer undo/redo > should support linear element creati
"showHyperlinkPopup": false,
"showWelcomeScreen": true,
"snapLines": [],
- "startBoundElement": null,
"stats": {
"open": false,
"panels": 3,
diff --git a/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap b/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap
index 557d3e636c..fe1a01329d 100644
--- a/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap
+++ b/packages/excalidraw/tests/__snapshots__/regressionTests.test.tsx.snap
@@ -6285,7 +6285,6 @@ exports[`regression tests > draw every type of shape > [end of test] appState 1`
"showHyperlinkPopup": false,
"showWelcomeScreen": true,
"snapLines": [],
- "startBoundElement": null,
"stats": {
"open": false,
"panels": 3,
@@ -8754,7 +8753,6 @@ exports[`regression tests > key 5 selects arrow tool > [end of test] appState 1`
"showHyperlinkPopup": false,
"showWelcomeScreen": true,
"snapLines": [],
- "startBoundElement": null,
"stats": {
"open": false,
"panels": 3,
@@ -8989,7 +8987,6 @@ exports[`regression tests > key 6 selects line tool > [end of test] appState 1`]
"showHyperlinkPopup": false,
"showWelcomeScreen": true,
"snapLines": [],
- "startBoundElement": null,
"stats": {
"open": false,
"panels": 3,
@@ -9420,7 +9417,6 @@ exports[`regression tests > key a selects arrow tool > [end of test] appState 1`
"showHyperlinkPopup": false,
"showWelcomeScreen": true,
"snapLines": [],
- "startBoundElement": null,
"stats": {
"open": false,
"panels": 3,
@@ -9837,7 +9833,6 @@ exports[`regression tests > key l selects line tool > [end of test] appState 1`]
"showHyperlinkPopup": false,
"showWelcomeScreen": true,
"snapLines": [],
- "startBoundElement": null,
"stats": {
"open": false,
"panels": 3,
@@ -14631,7 +14626,6 @@ exports[`regression tests > undo/redo drawing an element > [end of test] appStat
"showHyperlinkPopup": false,
"showWelcomeScreen": true,
"snapLines": [],
- "startBoundElement": null,
"stats": {
"open": false,
"panels": 3,
diff --git a/packages/excalidraw/types.ts b/packages/excalidraw/types.ts
index 5e91690dc2..3e3bf45225 100644
--- a/packages/excalidraw/types.ts
+++ b/packages/excalidraw/types.ts
@@ -537,7 +537,24 @@ export type SearchMatch = {
}[];
};
-export type UIAppState = Omit<AppState, "cursorButton" | "scrollX" | "scrollY">;
+export type UIAppState = Omit<
+ AppState,
+ // stripped from the UI-relevant app state so their (often per-frame)
+ // updates don't re-render the editor UI — canvas-only concerns.
+ // Subscribe via `useExcalidrawStateValue` if you need them in UI.
+ | "cursorButton"
+ | "scrollX"
+ | "scrollY"
+ | "zoom"
+ | "shouldCacheIgnoreZoom"
+ // canvas-interaction transients (snapping, binding & frame
+ // highlights) — identity churns per pointermove while interacting
+ | "snapLines"
+ | "originSnapOffset"
+ | "suggestedBinding"
+ | "frameToHighlight"
+ | "elementsToHighlight"
+>;
export type NormalizedZoomValue = number & { _brand: "normalizedZoom" };