Prevent stale frames from being drawn / always ensure up-to-date contents in webview (#3668)

* Prevent stale frames being drawn.

At key points where external changes enter the webview, stale images might get rendered. This ensures that a frame showing current state is always shown.

* Only stage single redraw

* Remove potentially superfluous calls to `self.update()`

* Remove potentially superfluous calls to `self.update()`.

I lost this one during some git troubles.

* Revert unrelated change

The function is supposed to take a boolean telling it whether or not the loading succeeded, which it doesn't as is. However, this is unrelated and works either way so I also reverted it again.

* chore: code cleanup

* cleanup: Remove redundant check for presence of callback

A callback will be used either way for this call, so it can be simplified. The check happens inside the handler.

* Add comment explaining why this change is necessary, referencing the relevant PR.

* Clarify comment to answer the why, not the what.

One can see what is being done, why is probably more important.
This commit is contained in:
Luca Auer 2025-01-18 05:54:20 +01:00 committed by GitHub
parent 7ba143bad8
commit 899cb89990
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 10 additions and 9 deletions

View file

@ -203,6 +203,7 @@ hideo aoyama <https://github.com/boukendesho>
Ross Brown <rbrownwsws@googlemail.com>
🦙 <github.com/iamllama>
Lukas Sommer <sommerluk@gmail.com>
Luca Auer <lolle2000.la@gmail.com>
Lukas Sommer <sommerluk@users.noreply.github.com>
Niclas Heinz <nheinz@hpost.net>
Omar Kohl <omarkohl@posteo.net>

View file

@ -659,17 +659,17 @@ html {{ {font} }}
page = self.page()
assert page is not None
if cb:
def handler(val: Any) -> None:
if self._shouldIgnoreWebEvent():
print("ignored late js callback", cb)
return
if cb:
cb(val)
# Without the following, stale frames showing previous or corrupt content get occasionally displayed. (see #3668 for more details)
self.update()
page.runJavaScript(js, handler)
else:
page.runJavaScript(js)
def _queueAction(self, name: str, *args: Any) -> None:
self._pendingActions.append((name, args))