Skip to content

Commit

Permalink
Fix running into m.redraw.sync() lock in MailViewer
Browse files Browse the repository at this point in the history
Stream.map() callback would be called immediately during setViewModel()
because of how streams are implemented, and we would try to do
m.redraw.sync() inside of another redraw.

Now we schedule a microtask after the current redraw.

fix #4570
  • Loading branch information
charlag committed Sep 16, 2022
1 parent 068ed1b commit 8c0ca6b
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions src/mail/view/MailViewer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,10 @@ export class MailViewer implements Component<MailViewerAttrs> {
if (this.viewModel !== oldViewModel) {
this.loadAllListener.end(true)
this.loadAllListener = this.viewModel.loadCompleteNotification.map(async () => {
// streams are pretty much synchronous, so we could be in the middle of a redraw here and mithril does not just schedule another redraw, it
// will error out so before calling m.redraw.sync() we want to make sure that we are not inside a redraw by just scheduling a microtask with
// this simple await.
await Promise.resolve()
// Wait for mail body to be redrawn before replacing images
m.redraw.sync()
await this.replaceInlineImages()
Expand Down Expand Up @@ -451,14 +455,14 @@ export class MailViewer implements Component<MailViewerAttrs> {

private renderLoadingIcon(): Children {
return m(".progress-panel.flex-v-center.items-center",
{
key: "loadingIcon",
style: {
height: "200px",
},
{
key: "loadingIcon",
style: {
height: "200px",
},
[progressIcon(), m("small", lang.get("loading_msg"))],
)
},
[progressIcon(), m("small", lang.get("loading_msg"))],
)
}

private renderBanners(mail: Mail): Children {
Expand Down Expand Up @@ -1002,7 +1006,7 @@ export class MailViewer implements Component<MailViewerAttrs> {
),
m(".flex",
m(ExpanderButton, {
style: { paddingTop: "0px" },
style: {paddingTop: "0px"},
label: "showAll_action",
expanded: this.filesExpanded(),
onExpandedChange: this.filesExpanded,
Expand Down

0 comments on commit 8c0ca6b

Please sign in to comment.