Skip to content

Commit

Permalink
fix: images not initialized correctly (#4157)
Browse files Browse the repository at this point in the history
* fix: image not initialized correctly due to not renewing `state.pendingImageElement`

* ensure we replace elements on update

* set file as errored on >= 400 status respones
  • Loading branch information
dwelle committed Nov 1, 2021
1 parent 8df1a11 commit 790e6da
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 5 deletions.
20 changes: 16 additions & 4 deletions src/components/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4270,12 +4270,24 @@ class App extends React.Component<AppProps, AppState> {
if (updatedFiles.has(element.fileId)) {
invalidateShapeForElement(element);
}

if (erroredFiles.has(element.fileId)) {
newElementWith(element, { status: "error" });
}
}
}
if (erroredFiles.size) {
this.scene.replaceAllElements(
this.scene.getElementsIncludingDeleted().map((element) => {
if (
isInitializedImageElement(element) &&
erroredFiles.has(element.fileId)
) {
return newElementWith(element, {
status: "error",
});
}
return element;
}),
);
}

return { updatedFiles, erroredFiles };
};

Expand Down
2 changes: 2 additions & 0 deletions src/excalidraw-app/data/firebase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,8 @@ export const loadFilesFromFirebase = async (
dataURL,
created: metadata?.created || Date.now(),
});
} else {
erroredFiles.set(id, true);
}
} catch (error) {
erroredFiles.set(id, true);
Expand Down
10 changes: 9 additions & 1 deletion src/excalidraw-app/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -460,19 +460,27 @@ const ExcalidrawWrapper = () => {
if (excalidrawAPI) {
let didChange = false;

let pendingImageElement = appState.pendingImageElement;
const elements = excalidrawAPI
.getSceneElementsIncludingDeleted()
.map((element) => {
if (localFileStorage.shouldUpdateImageElementStatus(element)) {
didChange = true;
return newElementWith(element, { status: "saved" });
const newEl = newElementWith(element, { status: "saved" });
if (pendingImageElement === element) {
pendingImageElement = newEl;
}
return newEl;
}
return element;
});

if (didChange) {
excalidrawAPI.updateScene({
elements,
appState: {
pendingImageElement,
},
});
}
}
Expand Down

1 comment on commit 790e6da

@vercel
Copy link

@vercel vercel bot commented on 790e6da Nov 1, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.