Skip to content

Commit

Permalink
Defer calculating picUrl to avoid accessing dependencies too early
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremywiebe committed Jul 14, 2023
1 parent 3d9e3f7 commit 6418245
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions packages/perseus-editor/src/widgets/plotter-editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,14 +84,11 @@ class PlotterEditor extends React.Component<Props, State> {
plotDimensions: [275, 200],
labelInterval: 1,

get picUrl() {
const staticUrl = Dependencies.getDependencies().staticUrl;
if (staticUrl) {
return staticUrl("/images/badges/earth-small.png");
}

return null;
},
// CAUTION(jeremy): picUrl used to be a getter here. Please do not
// restore this getter as it used getDependencies(). That is not
// reliable as sometimes that the dependencies are not provided by the
// host application at this point causing an error.
// get picUrl() {}
};

state: State = {
Expand All @@ -118,18 +115,19 @@ class PlotterEditor extends React.Component<Props, State> {
}
}

fetchPic: (arg1: string) => any = (url) => {
if (this.state.loadedUrl !== url) {
fetchPic(url: string) {
const staticUrl = Dependencies.getDependencies().staticUrl(url);
if (this.state.loadedUrl !== staticUrl) {
const pic = new Image();
pic.src = url;
pic.src = staticUrl;
pic.onload = () => {
this.setState({
pic: pic,
loadedUrl: url,
loadedUrl: staticUrl,
});
};
}
};
}

render(): React.ReactNode {
const setFromScale = _.contains(
Expand Down

0 comments on commit 6418245

Please sign in to comment.