From 609a72f7c738b69bf79c1595c438d6fa25a314a7 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Mon, 25 Mar 2024 19:08:27 +0100 Subject: [PATCH] LibWeb: Fix endless spinning in apply_the_history_step() While waiting for a task that populates a session history entry, we can't limit the processing of the event loop to the `NavigationAndTraversal` task source. This is because fetching uses the `Networking` task source, which also needs to be processed. Since making a fetch request might take some time, we want to process everything on the event loop while waiting, to avoid blocking user interactions. It is still possible to use `spin_processing_tasks_with_source_until()` on subsequent steps of `apply_the_history_step()`. Also modifies test that was flaky. --- .../remove-iframe-from-timeout-callback.txt | 2 +- .../remove-iframe-from-timeout-callback.html | 26 +++++++++++-------- .../LibWeb/HTML/TraversableNavigable.cpp | 2 +- 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Tests/LibWeb/Text/expected/navigation/remove-iframe-from-timeout-callback.txt b/Tests/LibWeb/Text/expected/navigation/remove-iframe-from-timeout-callback.txt index 136d06384a..73fdda35ba 100644 --- a/Tests/LibWeb/Text/expected/navigation/remove-iframe-from-timeout-callback.txt +++ b/Tests/LibWeb/Text/expected/navigation/remove-iframe-from-timeout-callback.txt @@ -1 +1 @@ - \ No newline at end of file +PASS: did not crash diff --git a/Tests/LibWeb/Text/input/navigation/remove-iframe-from-timeout-callback.html b/Tests/LibWeb/Text/input/navigation/remove-iframe-from-timeout-callback.html index e6de8c2e32..24bb8176ee 100644 --- a/Tests/LibWeb/Text/input/navigation/remove-iframe-from-timeout-callback.html +++ b/Tests/LibWeb/Text/input/navigation/remove-iframe-from-timeout-callback.html @@ -1,12 +1,16 @@ - -
- -
-
- + }); +PASS: did not crash diff --git a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp index 6f2cf6732b..73993fac8a 100644 --- a/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp +++ b/Userland/Libraries/LibWeb/HTML/TraversableNavigable.cpp @@ -572,7 +572,7 @@ TraversableNavigable::HistoryStepResult TraversableNavigable::apply_the_history_ // AD-HOC: Since currently populate_session_history_entry_document does not run in parallel // we call spin_until to interrupt execution of this function and let document population // to complete. - main_thread_event_loop().spin_processing_tasks_with_source_until(Task::Source::NavigationAndTraversal, [&] { + main_thread_event_loop().spin_until([&] { return !changing_navigable_continuations.is_empty() || completed_change_jobs == total_change_jobs; });