fix: font not rendered correctly on init (#8002)

This commit is contained in:
David Luzar 2024-05-10 16:37:46 +02:00 committed by GitHub
parent 301e83805d
commit 273ba803d9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 53 additions and 64 deletions

View file

@ -714,10 +714,7 @@ class App extends React.Component<AppProps, AppState> {
id: this.id,
};
this.fonts = new Fonts({
scene: this.scene,
onSceneUpdated: this.onSceneUpdated,
});
this.fonts = new Fonts({ scene: this.scene });
this.history = new History();
this.actionManager.registerAll(actions);
@ -940,7 +937,7 @@ class App extends React.Component<AppProps, AppState> {
});
if (updated) {
this.scene.informMutation();
this.scene.triggerUpdate();
}
// GC
@ -1452,10 +1449,10 @@ class App extends React.Component<AppProps, AppState> {
const selectedElements = this.scene.getSelectedElements(this.state);
const { renderTopRightUI, renderCustomStats } = this.props;
const versionNonce = this.scene.getVersionNonce();
const sceneNonce = this.scene.getSceneNonce();
const { elementsMap, visibleElements } =
this.renderer.getRenderableElements({
versionNonce,
sceneNonce,
zoom: this.state.zoom,
offsetLeft: this.state.offsetLeft,
offsetTop: this.state.offsetTop,
@ -1673,7 +1670,7 @@ class App extends React.Component<AppProps, AppState> {
elementsMap={elementsMap}
allElementsMap={allElementsMap}
visibleElements={visibleElements}
versionNonce={versionNonce}
sceneNonce={sceneNonce}
selectionNonce={
this.state.selectionElement?.versionNonce
}
@ -1695,7 +1692,7 @@ class App extends React.Component<AppProps, AppState> {
elementsMap={elementsMap}
visibleElements={visibleElements}
selectedElements={selectedElements}
versionNonce={versionNonce}
sceneNonce={sceneNonce}
selectionNonce={
this.state.selectionElement?.versionNonce
}
@ -1819,7 +1816,7 @@ class App extends React.Component<AppProps, AppState> {
);
}
this.magicGenerations.set(frameElement.id, data);
this.onSceneUpdated();
this.triggerRender();
};
private getTextFromElements(elements: readonly ExcalidrawElement[]) {
@ -2444,7 +2441,7 @@ class App extends React.Component<AppProps, AppState> {
this.history.record(increment.elementsChange, increment.appStateChange);
});
this.scene.addCallback(this.onSceneUpdated);
this.scene.onUpdate(this.triggerRender);
this.addEventListeners();
if (this.props.autoFocus && this.excalidrawContainerRef.current) {
@ -2489,6 +2486,7 @@ class App extends React.Component<AppProps, AppState> {
public componentWillUnmount() {
this.renderer.destroy();
this.scene = new Scene();
this.fonts = new Fonts({ scene: this.scene });
this.renderer = new Renderer(this.scene);
this.files = {};
this.imageCache.clear();
@ -3670,7 +3668,7 @@ class App extends React.Component<AppProps, AppState> {
ShapeCache.delete(element);
}
});
this.scene.informMutation();
this.scene.triggerUpdate();
this.addNewImagesToImageCache();
},
@ -3730,7 +3728,7 @@ class App extends React.Component<AppProps, AppState> {
},
);
private onSceneUpdated = () => {
private triggerRender = () => {
this.setState({});
};
@ -5577,7 +5575,7 @@ class App extends React.Component<AppProps, AppState> {
}
this.elementsPendingErasure = new Set(this.elementsPendingErasure);
this.onSceneUpdated();
this.triggerRender();
}
};
@ -8069,7 +8067,7 @@ class App extends React.Component<AppProps, AppState> {
this.scene.getNonDeletedElementsMap(),
);
this.scene.informMutation();
this.scene.triggerUpdate();
}
}
}
@ -8564,7 +8562,7 @@ class App extends React.Component<AppProps, AppState> {
private restoreReadyToEraseElements = () => {
this.elementsPendingErasure = new Set();
this.onSceneUpdated();
this.triggerRender();
};
private eraseElements = () => {
@ -8978,7 +8976,7 @@ class App extends React.Component<AppProps, AppState> {
files,
);
if (updatedFiles.size) {
this.scene.informMutation();
this.scene.triggerUpdate();
}
}
};

View file

@ -444,7 +444,7 @@ const LayerUI = ({
);
ShapeCache.delete(element);
}
Scene.getScene(selectedElements[0])?.informMutation();
Scene.getScene(selectedElements[0])?.triggerUpdate();
} else if (colorPickerType === "elementBackground") {
setAppState({
currentItemBackgroundColor: color,

View file

@ -19,7 +19,7 @@ type InteractiveCanvasProps = {
elementsMap: RenderableElementsMap;
visibleElements: readonly NonDeletedExcalidrawElement[];
selectedElements: readonly NonDeletedExcalidrawElement[];
versionNonce: number | undefined;
sceneNonce: number | undefined;
selectionNonce: number | undefined;
scale: number;
appState: InteractiveCanvasAppState;
@ -206,10 +206,10 @@ const areEqual = (
// This could be further optimised if needed, as we don't have to render interactive canvas on each scene mutation
if (
prevProps.selectionNonce !== nextProps.selectionNonce ||
prevProps.versionNonce !== nextProps.versionNonce ||
prevProps.sceneNonce !== nextProps.sceneNonce ||
prevProps.scale !== nextProps.scale ||
// we need to memoize on elementsMap because they may have renewed
// even if versionNonce didn't change (e.g. we filter elements out based
// even if sceneNonce didn't change (e.g. we filter elements out based
// on appState)
prevProps.elementsMap !== nextProps.elementsMap ||
prevProps.visibleElements !== nextProps.visibleElements ||

View file

@ -19,7 +19,7 @@ type StaticCanvasProps = {
elementsMap: RenderableElementsMap;
allElementsMap: NonDeletedSceneElementsMap;
visibleElements: readonly NonDeletedExcalidrawElement[];
versionNonce: number | undefined;
sceneNonce: number | undefined;
selectionNonce: number | undefined;
scale: number;
appState: StaticCanvasAppState;
@ -112,10 +112,10 @@ const areEqual = (
nextProps: StaticCanvasProps,
) => {
if (
prevProps.versionNonce !== nextProps.versionNonce ||
prevProps.sceneNonce !== nextProps.sceneNonce ||
prevProps.scale !== nextProps.scale ||
// we need to memoize on elementsMap because they may have renewed
// even if versionNonce didn't change (e.g. we filter elements out based
// even if sceneNonce didn't change (e.g. we filter elements out based
// on appState)
prevProps.elementsMap !== nextProps.elementsMap ||
prevProps.visibleElements !== nextProps.visibleElements