1
0
mirror of https://github.com/excalidraw/excalidraw.git synced 2025-02-18 13:29:36 +01:00

fix: image rendering issue when passed in initialData (#8471)

This commit is contained in:
Abhishek Mehandiratta 2024-09-09 03:26:00 +05:30 committed by GitHub
parent 6ff56c36e3
commit 5a11c70714
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -2295,6 +2295,9 @@ class App extends React.Component<AppProps, AppState> {
storeAction: StoreAction.UPDATE,
});
// clear the shape and image cache so that any images in initialData
// can be loaded fresh
this.clearImageShapeCache();
// FontFaceSet loadingdone event we listen on may not always
// fire (looking at you Safari), so on init we manually load all
// fonts and rerender scene text elements once done. This also
@ -2360,6 +2363,15 @@ class App extends React.Component<AppProps, AppState> {
return false;
};
private clearImageShapeCache() {
this.scene.getNonDeletedElements().forEach((element) => {
if (isInitializedImageElement(element) && this.files[element.fileId]) {
this.imageCache.delete(element.fileId);
ShapeCache.delete(element);
}
});
}
public async componentDidMount() {
this.unmounted = false;
this.excalidrawContainerValue.container =
@ -3674,15 +3686,7 @@ class App extends React.Component<AppProps, AppState> {
this.files = { ...this.files, ...Object.fromEntries(filesMap) };
this.scene.getNonDeletedElements().forEach((element) => {
if (
isInitializedImageElement(element) &&
filesMap.has(element.fileId)
) {
this.imageCache.delete(element.fileId);
ShapeCache.delete(element);
}
});
this.clearImageShapeCache();
this.scene.triggerUpdate();
this.addNewImagesToImageCache();