Turning it off just makes the flickering a blank screen.
I decided to look for code related to this prompt with `rg "loading"`.
Doing that, I found an interesting function in `zathura/page-widget.c` called `zathura_page_widget_draw`.
Skimming the code, it looks like it handles drawing pages to screen.
This was a promising new direction to look into.
Near the end, there is a section that takes care of drawing the loading screen.
Reading above, we see that the loading screen only renders if the page has no Cairo surface.
Essentially, if the page hasn't fully loaded, put up a loading screen.
Here, I had an idea: what if we replace the loading screen with the original page from before the reload?
That way, it would be a seamless transition from the original document to the new document.
To implement this, I added two extra pointers to the `zathura` struct:
the `predecessor_document`, and the `predecessor_pages`.
When Zathura closes the document for a reload, it preserves the current document and pages as "predecessors".
Zathura will not free the predecessor document and pages immediately.
Then, in `zathura_page_widget_draw`, instead of drawing a loading screen, it will draw the predecessor pages.
Since having an extra buffer also uses more memory, I added a toggle option `smooth-reload` that switches this feature on and off.
Of course, I'm skimming over many specific details here.
To see the exact code of my patch, you can look at the [commit](https://git.pwmt.org/pwmt/zathura/-/commit/257a2c968bcf67cf814aeab325800d4889d8df21) on Zathura's git repository.
Anyways, here is the end result of the bug-fix, where the bottom window is patched and the top one isn't:
[ ![Before and after the bugfix](/public/img/zathura/before-after-thumb.gif) ](/public/img/zathura/before-after.mp4)
I was really ecstatic when Zathura first smoothly reloaded a document.
It finally worked!
After this initial success, I collected all these changes into a [merge request](https://git.pwmt.org/pwmt/zathura/-/merge_requests/80) on GitLab.
Finally, after a month of waiting, I got the maintainer to merge my patch.
All in all, it took a weekend in total to get familiar with the codebase and create this patch.